Skip to content

Commit

Permalink
Language is now a String rather than enum. iTunes largely ignores lan…
Browse files Browse the repository at this point in the history
…guage; PodcastIndex uses it for trending.
  • Loading branch information
amugofjava committed Feb 1, 2024
1 parent eaa03cf commit 9fedfcc
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 43 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.8

- BREAKING CHANGE: Language is now a text parameter (2-3 letter code) rather than enum. This is because iTunes largely ignores language, but PodcastIndex can use it for trending podcasts.

## 0.6.7

- Update example to handle null feed.
Expand Down
1 change: 0 additions & 1 deletion lib/podcast_search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export 'src/model/genre.dart';
export 'src/model/value.dart';
export 'src/model/funding.dart';
export 'src/model/item.dart';
export 'src/model/language.dart';
export 'src/model/podcast.dart';
export 'src/model/search_result.dart';
export 'src/model/transcript.dart';
Expand Down
15 changes: 0 additions & 15 deletions lib/src/model/language.dart

This file was deleted.

2 changes: 1 addition & 1 deletion lib/src/search/base_search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ abstract class BaseSearch {
required String term,
Country country = Country.none,
Attribute attribute = Attribute.none,
Language language = Language.none,
String language = '',
int limit = 0,
int version = 0,
bool explicit = false,
Expand Down
6 changes: 3 additions & 3 deletions lib/src/search/itunes_search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ final class ITunesSearch extends BaseSearch {
int? _limit;

/// If non-null, the results will be limited to the language specified.
late Language _language;
late String _language;

/// Set to true to disable the explicit filter.
bool? _explicit;
Expand Down Expand Up @@ -93,7 +93,7 @@ final class ITunesSearch extends BaseSearch {
{String? term,
Country country = Country.none,
Attribute attribute = Attribute.none,
Language language = Language.none,
String language = '',
int limit = 0,
int version = 0,
bool explicit = false,
Expand Down Expand Up @@ -269,7 +269,7 @@ final class ITunesSearch extends BaseSearch {
}

String _languageParam() {
return _language != Language.none ? '&language=${_language.code}' : '';
return _language.isNotEmpty && _language == 'ja' ? '&language=ja_jp' : '';
}

String _versionParam() {
Expand Down
51 changes: 31 additions & 20 deletions lib/src/search/podcast_index_search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,16 @@ final class PodcastIndexSearch extends BaseSearch {
/// By default, searches will be based on keywords. Supply an [Attribute]
/// value to search by a different attribute such as Author, genre etc.
@override
Future<SearchResult> search(
{String? term,
Country country = Country.none,
Attribute attribute = Attribute.none,
Language language = Language.none,
int limit = 0,
int version = 0,
bool explicit = false,
Map<String, dynamic>? queryParams = const {}}) async {
Future<SearchResult> search({
String? term,
Country country = Country.none,
Attribute attribute = Attribute.none,
String language = '',
int limit = 0,
int version = 0,
bool explicit = false,
Map<String, dynamic>? queryParams = const {},
}) async {
_term = term;
_limit = limit;
_explicit = explicit;
Expand Down Expand Up @@ -238,19 +239,29 @@ final class PodcastIndexSearch extends BaseSearch {
/// the infrequent update of the chart feed it is recommended that clients
/// cache the results.
@override
Future<SearchResult> charts(
{Country country = Country.none,
int limit = 20,
bool explicit = false,
String genre = '',
Map<String, dynamic> queryParams = const {}}) async {
Future<SearchResult> charts({
Country country = Country.none,
String language = '',
int limit = 20,
bool explicit = false,
String genre = '',
Map<String, dynamic> queryParams = const {},
}) async {
try {
var queryParameters = <String, dynamic>{
'since': -1 * 3600 * 24 * 7,
'cat': genre,
'max': limit,
};

if (language.isNotEmpty) {
queryParameters.addAll({'lang': language});
}

queryParameters.addAll(queryParams);

var response = await _client.get(trendingApiEndpoint,
queryParameters: {
'since': -1 * 3600 * 24 * 7,
'cat': genre,
'max': limit,
}..addAll(queryParams));
queryParameters: queryParameters);

return SearchResult.fromJson(
json: response.data, type: ResultType.podcastIndex);
Expand Down
7 changes: 5 additions & 2 deletions lib/src/search/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Search {
int _limit = 0;

/// If non-null, the results will be limited to the language specified.
Language _language = Language.none;
String _language = '';

/// Set to true to disable the explicit filter.
bool _explicit = false;
Expand Down Expand Up @@ -54,7 +54,7 @@ class Search {
String term, {
Country country = Country.none,
Attribute attribute = Attribute.none,
Language language = Language.none,
String language = '',
int limit = 0,
int version = 0,
bool explicit = false,
Expand Down Expand Up @@ -101,12 +101,14 @@ class Search {
/// cache the results.
Future<SearchResult> charts({
Country country = Country.none,
String language = '',
int limit = 20,
bool explicit = false,
String genre = '',
Map<String, dynamic> queryParams = const {},
}) async {
_country = country;
_language = language;
_limit = limit;
_explicit = explicit;
_genre = genre;
Expand All @@ -118,6 +120,7 @@ class Search {
podcastIndexProvider: searchProvider as PodcastIndexProvider,
).charts(
country: _country,
language: _language,
limit: _limit,
explicit: _explicit,
genre: _genre,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: podcast_search
description: A library for searching for podcasts and parsing podcast RSS feeds. Supports iTunes and PodcastIndex directories, and newer features such as chapters and transcripts.

version: 0.6.7
version: 0.6.8
homepage: https://github.com/amugofjava/podcast_search

environment:
Expand Down

0 comments on commit 9fedfcc

Please sign in to comment.