Skip to content

Commit d953f64

Browse files
committed
Merge branch 'bugfix/item-tag-duplication-with-auto-cover-art-enabled-62'
2 parents a4a39d5 + 600ce83 commit d953f64

8 files changed

+74
-8
lines changed

CHANGELOG.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Changelog
22
=========
33

4+
1.36 2022-08-25 * Fix bug where podcasts with autosaved cover art would end up
5+
with duplicated iTunes metadata tags. Thanks once again to
6+
@EdwarDDay for the bug report.
7+
48
1.35 2022-08-24 * Image files extracted from podcast cover art are now placed
59
in the correct sub folder, if you organise your podcasts by
610
sub folder. Thanks to @EdwarDDay for the bug report!

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[![Testing dir2cast](https://github.com/ben-xo/dir2cast/actions/workflows/testing.yml/badge.svg)](https://github.com/ben-xo/dir2cast/actions/workflows/testing.yml)
22

33

4-
dir2cast by Ben XO v1.35 (2022-08-24)
4+
dir2cast by Ben XO v1.36 (2022-08-25)
55
================================================================================
66

77
https://github.com/ben-xo/dir2cast/

dir2cast.php

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
/* DEFAULTS *********************************************/
5757

5858
// error handler needs these, so let's set them now.
59-
define('VERSION', '1.35');
59+
define('VERSION', '1.36');
6060
define('DIR2CAST_HOMEPAGE', 'https://github.com/ben-xo/dir2cast/');
6161
define('GENERATOR', 'dir2cast ' . VERSION . ' by Ben XO (' . DIR2CAST_HOMEPAGE . ')');
6262

@@ -125,6 +125,7 @@ public function __call($method, $params)
125125
}
126126

127127
interface Podcast_Helper {
128+
public function id();
128129
public function appendToChannel(DOMElement $d, DOMDocument $doc);
129130
public function appendToItem(DOMElement $d, DOMDocument $doc, RSS_Item $item);
130131
public function addNamespaceTo(DOMElement $d, DOMDocument $doc);
@@ -135,7 +136,10 @@ public function addNamespaceTo(DOMElement $d, DOMDocument $doc);
135136
*
136137
*/
137138
class getID3_Podcast_Helper implements Podcast_Helper {
138-
139+
public function id()
140+
{
141+
return get_class($this);
142+
}
139143
static $AUTO_SAVE_COVER_ART = false;
140144

141145
public function appendToChannel(DOMElement $d, DOMDocument $doc) { /* nothing */ }
@@ -206,6 +210,10 @@ public function appendToItem(DOMElement $d, DOMDocument $doc, RSS_Item $item)
206210
*
207211
*/
208212
class Caching_getID3_Podcast_Helper implements Podcast_Helper {
213+
public function id()
214+
{
215+
return get_class($this);
216+
}
209217

210218
protected $wrapped_helper;
211219
protected $cache_dir;
@@ -267,6 +275,10 @@ protected function saveToCache($filename, Serializable $item) {
267275
}
268276

269277
class Atom_Podcast_Helper extends GetterSetter implements Podcast_Helper {
278+
public function id()
279+
{
280+
return get_class($this);
281+
}
270282

271283
protected $self_link;
272284

@@ -312,7 +324,13 @@ public function setSelfLink($link)
312324
}
313325

314326
class iTunes_Podcast_Helper extends GetterSetter implements Podcast_Helper {
327+
public function id()
328+
{
329+
return get_class($this);
330+
}
315331

332+
static $ITUNES_SUBTITLE_SUFFIX = '';
333+
316334
protected $owner_name, $owner_email, $image_href, $explicit;
317335
protected $categories = array();
318336

@@ -404,7 +422,7 @@ public function appendToItem(DOMElement $item_element, DOMDocument $doc, RSS_Ite
404422
$itunes_subtitle = $item->getSubtitle();
405423
if($itunes_subtitle !== '')
406424
{
407-
$elements['subtitle'] = $itunes_subtitle . ITUNES_SUBTITLE_SUFFIX;
425+
$elements['subtitle'] = $itunes_subtitle . iTunes_Podcast_Helper::$ITUNES_SUBTITLE_SUFFIX;
408426
}
409427

410428
foreach($elements as $key => $val)
@@ -552,7 +570,7 @@ public function appendToChannel(DOMElement $channel, DOMDocument $doc)
552570

553571
public function addHelper(Podcast_Helper $helper)
554572
{
555-
$this->helpers[] = $helper;
573+
$this->helpers[$helper->id()] = $helper;
556574
return $helper;
557575
}
558576
}
@@ -976,7 +994,7 @@ abstract class Podcast extends GetterSetter
976994

977995
public function addHelper(Podcast_Helper $helper)
978996
{
979-
$this->helpers[] = $helper;
997+
$this->helpers[$helper->id()] = $helper;
980998

981999
// attach helper to items already added.
9821000
// new items will have the helper attached when they are added.
@@ -1413,7 +1431,7 @@ protected function cache_is_stale($cache_date, $most_recent_modification)
14131431
*/
14141432
public function renew()
14151433
{
1416-
touch($this->temp_file); // renew cache file life expectancy
1434+
touch($this->temp_file); // renew cache file life expectancy
14171435
}
14181436

14191437
public function uncache()
@@ -1915,6 +1933,7 @@ public static function defaults(array $SERVER)
19151933
Dir_Podcast::$DEBUG = DEBUG;
19161934
Cached_Dir_Podcast::$MIN_CACHE_TIME = MIN_CACHE_TIME;
19171935
getID3_Podcast_Helper::$AUTO_SAVE_COVER_ART = AUTO_SAVE_COVER_ART;
1936+
iTunes_Podcast_Helper::$ITUNES_SUBTITLE_SUFFIX = ITUNES_SUBTITLE_SUFFIX;
19181937

19191938
// Set up up factory settings for RSS Items
19201939
RSS_File_Item::$FILES_URL = MP3_URL; // TODO: rename this to MEDIA_URL

test/Dir_PodcastTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,11 @@ public function test_helpers_added_to_found_items()
165165
$mp = $this->newPodcast();
166166

167167
$helper = $this->createMock(Podcast_Helper::class);
168+
$helper->expects($this->atLeastOnce())->method('id')->willReturn('Mock1');
168169
$helper->expects($this->exactly(4))->method('appendToItem');
169170

170171
$helper2 = $this->createMock(Podcast_Helper::class);
172+
$helper2->expects($this->atLeastOnce())->method('id')->willReturn('Mock2');
171173
$helper2->expects($this->exactly(4))->method('appendToItem');
172174

173175
$mp->addHelper($helper);
@@ -185,9 +187,11 @@ public function test_files_added_to_podcast_obeys_ITEM_COUNT()
185187
$mp = $this->newPodcast();
186188

187189
$helper = $this->createMock(Podcast_Helper::class);
190+
$helper->expects($this->atLeastOnce())->method('id')->willReturn('Mock1');
188191
$helper->expects($this->exactly(2))->method('appendToItem');
189192

190193
$helper2 = $this->createMock(Podcast_Helper::class);
194+
$helper2->expects($this->atLeastOnce())->method('id')->willReturn('Mock2');
191195
$helper2->expects($this->exactly(2))->method('appendToItem');
192196

193197
$mp->addHelper($helper);

test/PodcastHelperTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ public static function setUpBeforeClass(): void
1313
public function test_helpers_applied_to_newly_added_items()
1414
{
1515
$helper = $this->createMock(Podcast_Helper::class);
16+
$helper->expects($this->atLeastOnce())->method('id')->willReturn('Mock1');
1617
$helper->expects($this->exactly(2))->method('appendToItem');
1718

1819
$helper2 = $this->createMock(Podcast_Helper::class);
20+
$helper2->expects($this->atLeastOnce())->method('id')->willReturn('Mock2');
1921
$helper2->expects($this->exactly(2))->method('appendToItem');
2022

2123
$mp = new MyPodcast();
@@ -34,9 +36,11 @@ public function test_helpers_applied_to_newly_added_items()
3436
public function test_helpers_applied_to_already_added_items()
3537
{
3638
$helper = $this->createMock(Podcast_Helper::class);
39+
$helper->expects($this->atLeastOnce())->method('id')->willReturn('Mock1');
3740
$helper->expects($this->exactly(2))->method('appendToItem');
3841

3942
$helper2 = $this->createMock(Podcast_Helper::class);
43+
$helper2->expects($this->atLeastOnce())->method('id')->willReturn('Mock2');
4044
$helper2->expects($this->exactly(2))->method('appendToItem');
4145

4246
$mp = new MyPodcast();
@@ -57,9 +61,11 @@ public function test_helpers_applied_to_already_added_items()
5761
public function test_helpers_given_opportunity_to_add_namespace()
5862
{
5963
$helper = $this->createMock(Podcast_Helper::class);
64+
$helper->expects($this->atLeastOnce())->method('id')->willReturn('Mock1');
6065
$helper->expects($this->once())->method('addNamespaceTo');
6166

6267
$helper2 = $this->createMock(Podcast_Helper::class);
68+
$helper2->expects($this->atLeastOnce())->method('id')->willReturn('Mock2');
6369
$helper2->expects($this->once())->method('addNamespaceTo');
6470

6571
$mp = new MyPodcast();

test/RSS_Item_getID3_Podcast_Helper_AUTO_SAVE_COVERTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,37 @@ public function test_id3v2_artist_album_title_with_cover()
6363
$this->assertEquals(file_get_contents('another.subdir/id3v2_artist_album_title_cover.jpg'), file_get_contents('../fixtures/empty.jpg'));
6464
}
6565

66+
public function test_auto_save_doesnt_create_spurious_helper_duplication()
67+
{
68+
define('CLI_ONLY', true);
69+
70+
copy('../fixtures/id3v2_artist_album_title_cover.mp3', './id3v2_artist_album_title_cover.mp3');
71+
72+
mkdir('temp');
73+
$mp = new Cached_Dir_Podcast('.', 'temp');
74+
$mp->init();
75+
$getid3 = $mp->addHelper(new Caching_getID3_Podcast_Helper('temp', new getID3_Podcast_Helper()));
76+
$atom = $mp->addHelper(new Atom_Podcast_Helper());
77+
$itunes = $mp->addHelper(new iTunes_Podcast_Helper());
78+
$content = $mp->generate();
79+
80+
# checking for duplication
81+
$this->assertEquals(1, preg_match_all("/<\/itunes:duration>/", $content));
82+
83+
age_dir_by('.', 60);
84+
85+
$mp = new Cached_Dir_Podcast('.', 'temp');
86+
$mp->init();
87+
$getid3 = $mp->addHelper(new Caching_getID3_Podcast_Helper('temp', new getID3_Podcast_Helper()));
88+
$atom = $mp->addHelper(new Atom_Podcast_Helper());
89+
$itunes = $mp->addHelper(new iTunes_Podcast_Helper());
90+
$content = $mp->generate();
91+
92+
# checking for duplication
93+
$this->assertEquals(1, preg_match_all("/<\/itunes:duration>/", $content));
94+
95+
}
96+
6697
public static function tearDownAfterClass(): void
6798
{
6899
chdir('..');

test/RSS_Item_iTunes_Podcast_HelperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function test_rss_item_added_to_podcast_channel_has_itunes_properties()
4242
*/
4343
public function test_rss_item_itunes_subtitle_suffix()
4444
{
45-
define('ITUNES_SUBTITLE_SUFFIX', ' Click here for more…');
45+
iTunes_Podcast_Helper::$ITUNES_SUBTITLE_SUFFIX = ' Click here for more…';
4646

4747
$mp = new MyPodcast();
4848
$helper = new iTunes_Podcast_Helper();

test/SettingsHandlerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public function test_default_defines_set()
5757
$this->assertFalse(getID3_Podcast_Helper::$AUTO_SAVE_COVER_ART);
5858
$this->assertEmpty(RSS_File_Item::$FILES_URL);
5959
$this->assertEmpty(RSS_File_Item::$FILES_DIR);
60+
$this->assertEmpty(iTunes_Podcast_Helper::$ITUNES_SUBTITLE_SUFFIX);
6061
$this->assertFalse(Media_RSS_Item::$LONG_TITLES);
6162
$this->assertEquals('comment', Media_RSS_Item::$DESCRIPTION_SOURCE);
6263

@@ -191,6 +192,7 @@ public function test_sensible_defaults($argv0)
191192
$this->assertSame(Dir_Podcast::$MIN_FILE_AGE, MIN_FILE_AGE);
192193
$this->assertSame(Cached_Dir_Podcast::$MIN_CACHE_TIME, MIN_CACHE_TIME);
193194
$this->assertSame(getID3_Podcast_Helper::$AUTO_SAVE_COVER_ART, AUTO_SAVE_COVER_ART);
195+
$this->assertSame(iTunes_Podcast_Helper::$ITUNES_SUBTITLE_SUFFIX, ITUNES_SUBTITLE_SUFFIX);
194196
$this->assertSame(RSS_File_Item::$FILES_URL, MP3_URL);
195197
$this->assertSame(RSS_File_Item::$FILES_DIR, MP3_DIR);
196198
$this->assertSame(Media_RSS_Item::$LONG_TITLES, LONG_TITLES);

0 commit comments

Comments
 (0)