Skip to content

Commit

Permalink
Merge branch 'bugfix/item-tag-duplication-with-auto-cover-art-enabled…
Browse files Browse the repository at this point in the history
…-62'
  • Loading branch information
ben-xo committed Aug 24, 2022
2 parents a4a39d5 + 600ce83 commit d953f64
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

1.36 2022-08-25 * Fix bug where podcasts with autosaved cover art would end up
with duplicated iTunes metadata tags. Thanks once again to
@EdwarDDay for the bug report.

1.35 2022-08-24 * Image files extracted from podcast cover art are now placed
in the correct sub folder, if you organise your podcasts by
sub folder. Thanks to @EdwarDDay for the bug report!
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![Testing dir2cast](https://github.com/ben-xo/dir2cast/actions/workflows/testing.yml/badge.svg)](https://github.com/ben-xo/dir2cast/actions/workflows/testing.yml)


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

https://github.com/ben-xo/dir2cast/
Expand Down
31 changes: 25 additions & 6 deletions dir2cast.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
/* DEFAULTS *********************************************/

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

Expand Down Expand Up @@ -125,6 +125,7 @@ public function __call($method, $params)
}

interface Podcast_Helper {
public function id();
public function appendToChannel(DOMElement $d, DOMDocument $doc);
public function appendToItem(DOMElement $d, DOMDocument $doc, RSS_Item $item);
public function addNamespaceTo(DOMElement $d, DOMDocument $doc);
Expand All @@ -135,7 +136,10 @@ public function addNamespaceTo(DOMElement $d, DOMDocument $doc);
*
*/
class getID3_Podcast_Helper implements Podcast_Helper {

public function id()
{
return get_class($this);
}
static $AUTO_SAVE_COVER_ART = false;

public function appendToChannel(DOMElement $d, DOMDocument $doc) { /* nothing */ }
Expand Down Expand Up @@ -206,6 +210,10 @@ public function appendToItem(DOMElement $d, DOMDocument $doc, RSS_Item $item)
*
*/
class Caching_getID3_Podcast_Helper implements Podcast_Helper {
public function id()
{
return get_class($this);
}

protected $wrapped_helper;
protected $cache_dir;
Expand Down Expand Up @@ -267,6 +275,10 @@ protected function saveToCache($filename, Serializable $item) {
}

class Atom_Podcast_Helper extends GetterSetter implements Podcast_Helper {
public function id()
{
return get_class($this);
}

protected $self_link;

Expand Down Expand Up @@ -312,7 +324,13 @@ public function setSelfLink($link)
}

class iTunes_Podcast_Helper extends GetterSetter implements Podcast_Helper {
public function id()
{
return get_class($this);
}

static $ITUNES_SUBTITLE_SUFFIX = '';

protected $owner_name, $owner_email, $image_href, $explicit;
protected $categories = array();

Expand Down Expand Up @@ -404,7 +422,7 @@ public function appendToItem(DOMElement $item_element, DOMDocument $doc, RSS_Ite
$itunes_subtitle = $item->getSubtitle();
if($itunes_subtitle !== '')
{
$elements['subtitle'] = $itunes_subtitle . ITUNES_SUBTITLE_SUFFIX;
$elements['subtitle'] = $itunes_subtitle . iTunes_Podcast_Helper::$ITUNES_SUBTITLE_SUFFIX;
}

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

public function addHelper(Podcast_Helper $helper)
{
$this->helpers[] = $helper;
$this->helpers[$helper->id()] = $helper;
return $helper;
}
}
Expand Down Expand Up @@ -976,7 +994,7 @@ abstract class Podcast extends GetterSetter

public function addHelper(Podcast_Helper $helper)
{
$this->helpers[] = $helper;
$this->helpers[$helper->id()] = $helper;

// attach helper to items already added.
// new items will have the helper attached when they are added.
Expand Down Expand Up @@ -1413,7 +1431,7 @@ protected function cache_is_stale($cache_date, $most_recent_modification)
*/
public function renew()
{
touch($this->temp_file); // renew cache file life expectancy
touch($this->temp_file); // renew cache file life expectancy
}

public function uncache()
Expand Down Expand Up @@ -1915,6 +1933,7 @@ public static function defaults(array $SERVER)
Dir_Podcast::$DEBUG = DEBUG;
Cached_Dir_Podcast::$MIN_CACHE_TIME = MIN_CACHE_TIME;
getID3_Podcast_Helper::$AUTO_SAVE_COVER_ART = AUTO_SAVE_COVER_ART;
iTunes_Podcast_Helper::$ITUNES_SUBTITLE_SUFFIX = ITUNES_SUBTITLE_SUFFIX;

// Set up up factory settings for RSS Items
RSS_File_Item::$FILES_URL = MP3_URL; // TODO: rename this to MEDIA_URL
Expand Down
4 changes: 4 additions & 0 deletions test/Dir_PodcastTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,11 @@ public function test_helpers_added_to_found_items()
$mp = $this->newPodcast();

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

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

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

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

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

$mp->addHelper($helper);
Expand Down
6 changes: 6 additions & 0 deletions test/PodcastHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ public static function setUpBeforeClass(): void
public function test_helpers_applied_to_newly_added_items()
{
$helper = $this->createMock(Podcast_Helper::class);
$helper->expects($this->atLeastOnce())->method('id')->willReturn('Mock1');
$helper->expects($this->exactly(2))->method('appendToItem');

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

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

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

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

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

$mp = new MyPodcast();
Expand Down
31 changes: 31 additions & 0 deletions test/RSS_Item_getID3_Podcast_Helper_AUTO_SAVE_COVERTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,37 @@ public function test_id3v2_artist_album_title_with_cover()
$this->assertEquals(file_get_contents('another.subdir/id3v2_artist_album_title_cover.jpg'), file_get_contents('../fixtures/empty.jpg'));
}

public function test_auto_save_doesnt_create_spurious_helper_duplication()
{
define('CLI_ONLY', true);

copy('../fixtures/id3v2_artist_album_title_cover.mp3', './id3v2_artist_album_title_cover.mp3');

mkdir('temp');
$mp = new Cached_Dir_Podcast('.', 'temp');
$mp->init();
$getid3 = $mp->addHelper(new Caching_getID3_Podcast_Helper('temp', new getID3_Podcast_Helper()));
$atom = $mp->addHelper(new Atom_Podcast_Helper());
$itunes = $mp->addHelper(new iTunes_Podcast_Helper());
$content = $mp->generate();

# checking for duplication
$this->assertEquals(1, preg_match_all("/<\/itunes:duration>/", $content));

age_dir_by('.', 60);

$mp = new Cached_Dir_Podcast('.', 'temp');
$mp->init();
$getid3 = $mp->addHelper(new Caching_getID3_Podcast_Helper('temp', new getID3_Podcast_Helper()));
$atom = $mp->addHelper(new Atom_Podcast_Helper());
$itunes = $mp->addHelper(new iTunes_Podcast_Helper());
$content = $mp->generate();

# checking for duplication
$this->assertEquals(1, preg_match_all("/<\/itunes:duration>/", $content));

}

public static function tearDownAfterClass(): void
{
chdir('..');
Expand Down
2 changes: 1 addition & 1 deletion test/RSS_Item_iTunes_Podcast_HelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function test_rss_item_added_to_podcast_channel_has_itunes_properties()
*/
public function test_rss_item_itunes_subtitle_suffix()
{
define('ITUNES_SUBTITLE_SUFFIX', ' Click here for more…');
iTunes_Podcast_Helper::$ITUNES_SUBTITLE_SUFFIX = ' Click here for more…';

$mp = new MyPodcast();
$helper = new iTunes_Podcast_Helper();
Expand Down
2 changes: 2 additions & 0 deletions test/SettingsHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function test_default_defines_set()
$this->assertFalse(getID3_Podcast_Helper::$AUTO_SAVE_COVER_ART);
$this->assertEmpty(RSS_File_Item::$FILES_URL);
$this->assertEmpty(RSS_File_Item::$FILES_DIR);
$this->assertEmpty(iTunes_Podcast_Helper::$ITUNES_SUBTITLE_SUFFIX);
$this->assertFalse(Media_RSS_Item::$LONG_TITLES);
$this->assertEquals('comment', Media_RSS_Item::$DESCRIPTION_SOURCE);

Expand Down Expand Up @@ -191,6 +192,7 @@ public function test_sensible_defaults($argv0)
$this->assertSame(Dir_Podcast::$MIN_FILE_AGE, MIN_FILE_AGE);
$this->assertSame(Cached_Dir_Podcast::$MIN_CACHE_TIME, MIN_CACHE_TIME);
$this->assertSame(getID3_Podcast_Helper::$AUTO_SAVE_COVER_ART, AUTO_SAVE_COVER_ART);
$this->assertSame(iTunes_Podcast_Helper::$ITUNES_SUBTITLE_SUFFIX, ITUNES_SUBTITLE_SUFFIX);
$this->assertSame(RSS_File_Item::$FILES_URL, MP3_URL);
$this->assertSame(RSS_File_Item::$FILES_DIR, MP3_DIR);
$this->assertSame(Media_RSS_Item::$LONG_TITLES, LONG_TITLES);
Expand Down

0 comments on commit d953f64

Please sign in to comment.