Skip to content

Commit 9fedfcc

Browse files
committed
Language is now a String rather than enum. iTunes largely ignores language; PodcastIndex uses it for trending.
1 parent eaa03cf commit 9fedfcc

File tree

8 files changed

+45
-43
lines changed

8 files changed

+45
-43
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.6.8
2+
3+
- 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.
4+
15
## 0.6.7
26

37
- Update example to handle null feed.

lib/podcast_search.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export 'src/model/genre.dart';
1111
export 'src/model/value.dart';
1212
export 'src/model/funding.dart';
1313
export 'src/model/item.dart';
14-
export 'src/model/language.dart';
1514
export 'src/model/podcast.dart';
1615
export 'src/model/search_result.dart';
1716
export 'src/model/transcript.dart';

lib/src/model/language.dart

Lines changed: 0 additions & 15 deletions
This file was deleted.

lib/src/search/base_search.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ abstract class BaseSearch {
1919
required String term,
2020
Country country = Country.none,
2121
Attribute attribute = Attribute.none,
22-
Language language = Language.none,
22+
String language = '',
2323
int limit = 0,
2424
int version = 0,
2525
bool explicit = false,

lib/src/search/itunes_search.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ final class ITunesSearch extends BaseSearch {
5555
int? _limit;
5656

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

6060
/// Set to true to disable the explicit filter.
6161
bool? _explicit;
@@ -93,7 +93,7 @@ final class ITunesSearch extends BaseSearch {
9393
{String? term,
9494
Country country = Country.none,
9595
Attribute attribute = Attribute.none,
96-
Language language = Language.none,
96+
String language = '',
9797
int limit = 0,
9898
int version = 0,
9999
bool explicit = false,
@@ -269,7 +269,7 @@ final class ITunesSearch extends BaseSearch {
269269
}
270270

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

275275
String _versionParam() {

lib/src/search/podcast_index_search.dart

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,16 @@ final class PodcastIndexSearch extends BaseSearch {
202202
/// By default, searches will be based on keywords. Supply an [Attribute]
203203
/// value to search by a different attribute such as Author, genre etc.
204204
@override
205-
Future<SearchResult> search(
206-
{String? term,
207-
Country country = Country.none,
208-
Attribute attribute = Attribute.none,
209-
Language language = Language.none,
210-
int limit = 0,
211-
int version = 0,
212-
bool explicit = false,
213-
Map<String, dynamic>? queryParams = const {}}) async {
205+
Future<SearchResult> search({
206+
String? term,
207+
Country country = Country.none,
208+
Attribute attribute = Attribute.none,
209+
String language = '',
210+
int limit = 0,
211+
int version = 0,
212+
bool explicit = false,
213+
Map<String, dynamic>? queryParams = const {},
214+
}) async {
214215
_term = term;
215216
_limit = limit;
216217
_explicit = explicit;
@@ -238,19 +239,29 @@ final class PodcastIndexSearch extends BaseSearch {
238239
/// the infrequent update of the chart feed it is recommended that clients
239240
/// cache the results.
240241
@override
241-
Future<SearchResult> charts(
242-
{Country country = Country.none,
243-
int limit = 20,
244-
bool explicit = false,
245-
String genre = '',
246-
Map<String, dynamic> queryParams = const {}}) async {
242+
Future<SearchResult> charts({
243+
Country country = Country.none,
244+
String language = '',
245+
int limit = 20,
246+
bool explicit = false,
247+
String genre = '',
248+
Map<String, dynamic> queryParams = const {},
249+
}) async {
247250
try {
251+
var queryParameters = <String, dynamic>{
252+
'since': -1 * 3600 * 24 * 7,
253+
'cat': genre,
254+
'max': limit,
255+
};
256+
257+
if (language.isNotEmpty) {
258+
queryParameters.addAll({'lang': language});
259+
}
260+
261+
queryParameters.addAll(queryParams);
262+
248263
var response = await _client.get(trendingApiEndpoint,
249-
queryParameters: {
250-
'since': -1 * 3600 * 24 * 7,
251-
'cat': genre,
252-
'max': limit,
253-
}..addAll(queryParams));
264+
queryParameters: queryParameters);
254265

255266
return SearchResult.fromJson(
256267
json: response.data, type: ResultType.podcastIndex);

lib/src/search/search.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Search {
2626
int _limit = 0;
2727

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

3131
/// Set to true to disable the explicit filter.
3232
bool _explicit = false;
@@ -54,7 +54,7 @@ class Search {
5454
String term, {
5555
Country country = Country.none,
5656
Attribute attribute = Attribute.none,
57-
Language language = Language.none,
57+
String language = '',
5858
int limit = 0,
5959
int version = 0,
6060
bool explicit = false,
@@ -101,12 +101,14 @@ class Search {
101101
/// cache the results.
102102
Future<SearchResult> charts({
103103
Country country = Country.none,
104+
String language = '',
104105
int limit = 20,
105106
bool explicit = false,
106107
String genre = '',
107108
Map<String, dynamic> queryParams = const {},
108109
}) async {
109110
_country = country;
111+
_language = language;
110112
_limit = limit;
111113
_explicit = explicit;
112114
_genre = genre;
@@ -118,6 +120,7 @@ class Search {
118120
podcastIndexProvider: searchProvider as PodcastIndexProvider,
119121
).charts(
120122
country: _country,
123+
language: _language,
121124
limit: _limit,
122125
explicit: _explicit,
123126
genre: _genre,

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: podcast_search
22
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.
33

4-
version: 0.6.7
4+
version: 0.6.8
55
homepage: https://github.com/amugofjava/podcast_search
66

77
environment:

0 commit comments

Comments
 (0)