Skip to content

Commit

Permalink
Fix the name and implement the PartOfASet -> Season mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-xo committed Dec 23, 2022
1 parent 4030286 commit 74efd9a
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
15 changes: 14 additions & 1 deletion dir2cast.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function appendToItem(DOMElement $d, DOMDocument $doc, RSS_Item $item)
}

unset($this->getid3);

if(!empty($info['comments']))
{
if(!empty($info['comments']['title'][0]))
Expand All @@ -184,6 +184,8 @@ public function appendToItem(DOMElement $d, DOMDocument $doc, RSS_Item $item)
$item->setID3Album( $info['comments']['album'][0] );
if(!empty($info['comments']['comment'][0]))
$item->setID3Comment( $info['comments']['comment'][0] );
if(!empty($info['part_of_a_set'][0]))
$item->setID3PartOfASet( $info['part_of_a_set'][0] );

if(self::$AUTO_SAVE_COVER_ART)
{
Expand Down Expand Up @@ -929,6 +931,17 @@ public function getSubtitle()
return $subtitle;
}

public function getSeason()
{
$season = parent::getSeason();
if(!$season)
{
// use part_of_a_set tag as season if there's no override
$season = $this->getID3PartOfASet();
}
return $season;
}

/**
* Version number used in the saved cache files. If the used fields change, increment this number.
* @var integer
Expand Down
11 changes: 11 additions & 0 deletions test/Media_RSS_ItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public function getID3Comment()
return '';
}

public function getID3PartOfASet()
{
return '';
}

protected $media_rss_item_class = 'Media_RSS_Item';

public function newRSSItem()
Expand All @@ -67,6 +72,7 @@ public function newRSSItem()
$item->setID3Title($this->getID3Title());
$item->setID3Artist($this->getID3Artist());
$item->setID3Comment($this->getID3Comment());
$item->setID3PartOfASet($this->getID3PartOfASet());
return $item;
}

Expand Down Expand Up @@ -136,6 +142,11 @@ public function test_summary_from_description_when_summary_not_set_and_descripti
$this->assertEquals('', $item->getSummary());
}

public function test_season_from_part_of_set_tag_by_default() {
$item = $this->newRSSItem();
$this->assertEquals($this->getID3PartOfASet(), $item->getSeason());
}

public function tearDown(): void
{
file_exists($this->filename) && unlink($this->filename);
Expand Down
41 changes: 41 additions & 0 deletions test/Media_RSS_Item_id3v2_artist_title_partofsetTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php declare(strict_types=1);

use PHPUnit\Framework\TestCase;

class Media_RSS_Item_id3v2_artist_title_partofsetTest extends Media_RSS_ItemTest
{
public function getMediaFileContent()
{
return file_get_contents('fixtures/id3v2_artist_title_partofaset.mp3');
}

public function getMediaFileLength()
{
return filesize('fixtures/id3v2_artist_title_partofaset.mp3');
}

public function getID3Artist()
{
return 'ARTIST#65';
}

public function getID3Title()
{
return 'EXAMPLE#65';
}

public function getID3PartOfASet()
{
return 'Season 1';
}

public function getDefaultTitle()
{
return 'EXAMPLE#65';
}

public function getDefaultSubtitle()
{
return 'ARTIST#65';
}
}

0 comments on commit 74efd9a

Please sign in to comment.