Skip to content

Commit d3827b3

Browse files
committed
Add missing length and type enclosure fields.
1 parent 06f57cd commit d3827b3

File tree

6 files changed

+69
-28
lines changed

6 files changed

+69
-28
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.7.11
2+
3+
- Add missing enclosure length and type fields.
4+
15
## 0.7.10
26

37
- Update intl and rss_dart dependencies to support Flutter v3.32.x.

lib/src/feed/feed.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,12 @@ class Feed {
270270

271271
if (response.statusCode == 200) {
272272
if (response.statusCode == 200) {
273-
274273
final lastModified = response.headers.value('last-modified');
275274
if (lastModified != null) {
276275
lastUpdated = lastModifiedFormat.tryParse(
277276
lastModified.replaceAll('GMT', ''),
278277
);
279278
}
280-
281279
}
282280
}
283281

@@ -666,6 +664,8 @@ class Feed {
666664
duration: item.itunes?.duration,
667665
contentUrl: item.enclosure?.url,
668666
imageUrl: item.itunes?.image?.href,
667+
length: item.enclosure?.length ?? 0,
668+
mimeType: item.enclosure?.type,
669669
season: item.itunes?.season,
670670
episode: item.itunes?.episode,
671671
content: item.content?.value,

lib/src/model/episode.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ class Episode {
3434
/// Episode author.
3535
String? author;
3636

37+
/// File length in bytes
38+
int length;
39+
40+
String? mimeType;
41+
3742
/// Season
3843
int? season;
3944

@@ -64,12 +69,14 @@ class Episode {
6469
required this.guid,
6570
required this.title,
6671
required this.description,
72+
required this.length,
6773
this.link = '',
6874
this.publicationDate,
6975
this.author = '',
7076
this.duration,
7177
this.contentUrl,
7278
this.imageUrl,
79+
this.mimeType,
7380
this.season,
7481
this.episode,
7582
this.content,

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.7.10
4+
version: 0.7.11
55
homepage: https://github.com/amugofjava/podcast_search
66

77
environment:

test/podcast_load_test.dart

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,39 @@
22
// code is governed by a MIT license that can be found in the LICENSE file.
33

44
import 'package:podcast_search/podcast_search.dart';
5-
import 'package:podcast_search/src/feed/feed.dart';
65
import 'package:podcast_search/src/model/medium.dart';
76
import 'package:test/test.dart';
87

98
void main() {
109
group('Podcast load test', () {
1110
test('Load podcast', () async {
1211
var podcast = await Feed.loadFeed(
13-
url: 'https://podcasts.files.bbci.co.uk/p06tqsg3.rss');
12+
url: 'https://podcasts.files.bbci.co.uk/p06tqsg3.rss',
13+
);
1414

1515
expect(podcast.title, 'Forest 404');
1616
});
1717

1818
test('Load invalid podcast - unknown host', () async {
1919
await expectLater(
20-
() =>
21-
Feed.loadFeed(url: 'https://pc.files.bbci.co.uk/p06tqsg3.rss'),
22-
throwsA(const TypeMatcher<PodcastFailedException>()));
20+
() => Feed.loadFeed(url: 'https://pc.files.bbci.co.uk/p06tqsg3.rss'),
21+
throwsA(const TypeMatcher<PodcastFailedException>()),
22+
);
2323
});
2424

2525
test('Load invalid podcast - invalid RSS call 404', () async {
2626
await expectLater(
27-
() => Feed.loadFeed(url: 'https://bbc.co.uk/abcdp06tqsg3.rss'),
28-
throwsA(const TypeMatcher<PodcastFailedException>()));
27+
() => Feed.loadFeed(url: 'https://bbc.co.uk/abcdp06tqsg3.rss'),
28+
throwsA(const TypeMatcher<PodcastFailedException>()),
29+
);
2930
});
3031
});
3132

3233
group('Podcast local file load test', () {
3334
test('Load podcast', () async {
34-
var podcast =
35-
await Feed.loadFeedFile(file: 'test_resources/podcast1.rss');
35+
var podcast = await Feed.loadFeedFile(
36+
file: 'test_resources/podcast1.rss',
37+
);
3638

3739
expect(podcast.title, 'Podcast Load Test 1');
3840
expect(podcast.description, 'Unit test podcast test 1');
@@ -56,8 +58,9 @@ void main() {
5658

5759
group('Block tag test', () {
5860
test('Load podcast with block tags', () async {
59-
var podcast =
60-
await Feed.loadFeedFile(file: 'test_resources/podcast1.rss');
61+
var podcast = await Feed.loadFeedFile(
62+
file: 'test_resources/podcast1.rss',
63+
);
6164

6265
expect(podcast.block.length, 3);
6366
expect(podcast.block[0].block, true);
@@ -72,23 +75,41 @@ void main() {
7275

7376
test('Load podcast with no block tags', () async {
7477
var podcast = await Feed.loadFeedFile(
75-
file: 'test_resources/podcast-no-block.rss');
78+
file: 'test_resources/podcast-no-block.rss',
79+
);
7680

7781
expect(podcast.block.length, 0);
7882
});
7983
});
8084

85+
group('Basic item test', () {
86+
test('Load podcast item', () async {
87+
var podcast = await Feed.loadFeedFile(
88+
file: 'test_resources/podcast1.rss',
89+
);
90+
91+
expect(podcast.episodes[0].length, 1024000);
92+
expect(podcast.episodes[0].mimeType, 'audio/mpeg');
93+
expect(
94+
podcast.episodes[0].contentUrl,
95+
'https://nowhere.com/podcastsearchtest1/podcast1/episode001.mp3',
96+
);
97+
});
98+
});
99+
81100
group('Remote item test', () {
82101
test('No remote items', () async {
83102
var podcast = await Feed.loadFeedFile(
84-
file: 'test_resources/podcast-no-block.rss');
103+
file: 'test_resources/podcast-no-block.rss',
104+
);
85105

86106
expect(podcast.remoteItems.length, 0);
87107
});
88108

89109
test('Load podcast 3 remote items', () async {
90110
var podcast = await Feed.loadFeedFile(
91-
file: 'test_resources/podcast-remote-item.rss');
111+
file: 'test_resources/podcast-remote-item.rss',
112+
);
92113

93114
expect(podcast.remoteItems.length, 3);
94115

@@ -108,30 +129,35 @@ void main() {
108129

109130
expect(item3.feedGuid, '917393e3-1b1e-5cef-ace4-edaa54e1f812');
110131
expect(item3.itemGuid, 'asdf089j0-ep240-20230511');
111-
expect(item3.feedUrl,
112-
'https://feeds.example.org/917393e3-1b1e-5cef-ace4-edaa54e1f811/rss.xml');
132+
expect(
133+
item3.feedUrl,
134+
'https://feeds.example.org/917393e3-1b1e-5cef-ace4-edaa54e1f811/rss.xml',
135+
);
113136
expect(item3.medium, 'music');
114137
});
115138
});
116139

117140
group('Medium test', () {
118141
test('No medium', () async {
119-
var podcast =
120-
await Feed.loadFeedFile(file: 'test_resources/podcast1.rss');
142+
var podcast = await Feed.loadFeedFile(
143+
file: 'test_resources/podcast1.rss',
144+
);
121145

122146
expect(podcast.medium, Medium.podcast);
123147
});
124148

125149
test('Audiobook medium', () async {
126150
var podcast = await Feed.loadFeedFile(
127-
file: 'test_resources/podcast-medium-audiobook.rss');
151+
file: 'test_resources/podcast-medium-audiobook.rss',
152+
);
128153

129154
expect(podcast.medium, Medium.audiobook);
130155
});
131156

132157
test('Music list medium', () async {
133158
var podcast = await Feed.loadFeedFile(
134-
file: 'test_resources/podcast-medium-music-list.rss');
159+
file: 'test_resources/podcast-medium-music-list.rss',
160+
);
135161

136162
expect(podcast.medium, Medium.musicL);
137163
expect(podcast.remoteItems.length, 2);
@@ -141,14 +167,16 @@ void main() {
141167
group('Alternate enclosures', () {
142168
test('No alternate enclosures', () async {
143169
var podcast = await Feed.loadFeedFile(
144-
file: 'test_resources/podcast-alternate-enclosure.rss');
170+
file: 'test_resources/podcast-alternate-enclosure.rss',
171+
);
145172

146173
expect(podcast.episodes[0].alternateEnclosures.length, 0);
147174
});
148175

149176
test('Load episode 2 alternate enclosures', () async {
150177
var podcast = await Feed.loadFeedFile(
151-
file: 'test_resources/podcast-alternate-enclosure.rss');
178+
file: 'test_resources/podcast-alternate-enclosure.rss',
179+
);
152180

153181
var episode2 = podcast.episodes[1];
154182

@@ -187,8 +215,10 @@ void main() {
187215
expect(source2.contentType, 'audio/opus');
188216

189217
expect(integrity?.type, 'sri');
190-
expect(integrity?.value, 'sha384-ExVqijgYHm15PqQqdXfW95x+Rs6C+d6E/ICxyQOeFevnxNLR/wtJNrNYTjIysUBo');
218+
expect(
219+
integrity?.value,
220+
'sha384-ExVqijgYHm15PqQqdXfW95x+Rs6C+d6E/ICxyQOeFevnxNLR/wtJNrNYTjIysUBo',
221+
);
191222
});
192223
});
193-
194224
}

test_resources/podcast1.rss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<item>
3636
<title>Episode 001</title>
3737
<link>https://nowhere.com/podcastsearchtest1/podcast1</link>
38-
<enclosure url="https://nowhere.com/podcastsearchtest1/podcast1/episode001.mp3" length="0" type="audio/mpeg" />
38+
<enclosure url="https://nowhere.com/podcastsearchtest1/podcast1/episode001.mp3" length="1024000" type="audio/mpeg" />
3939
<itunes:duration>1200</itunes:duration>
4040
<itunes:explicit>yes</itunes:explicit>
4141
<itunes:episodeType>full</itunes:episodeType>

0 commit comments

Comments
 (0)