-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace M3uParser\Tag; | ||
|
||
/** | ||
* @see https://github.com/Gemorroj/M3uParser/issues/34 | ||
*/ | ||
class ExtAlbumArtUrl implements ExtTagInterface | ||
{ | ||
private string $value; | ||
|
||
/** | ||
* #EXTALBUMARTURL:https://store.example.com/download/A32X5yz-1.jpg. | ||
*/ | ||
public function __construct(string $lineStr = null) | ||
{ | ||
if (null !== $lineStr) { | ||
$this->make($lineStr); | ||
} | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return '#EXTALBUMARTURL:'.$this->getValue(); | ||
} | ||
|
||
public function setValue(string $value): self | ||
{ | ||
$this->value = $value; | ||
|
||
return $this; | ||
} | ||
|
||
public function getValue(): string | ||
{ | ||
return $this->value; | ||
} | ||
|
||
public static function isMatch(string $lineStr): bool | ||
{ | ||
return 0 === \stripos($lineStr, '#EXTALBUMARTURL:'); | ||
} | ||
|
||
protected function make(string $lineStr): void | ||
{ | ||
/* | ||
EXTALBUMARTURL format: | ||
#EXTALBUMARTURL:<url> | ||
example: | ||
#EXTALBUMARTURL:https://store.example.com/download/A32X5yz-1.jpg | ||
*/ | ||
$dataLineStr = \substr($lineStr, \strlen('#EXTALBUMARTURL:')); | ||
$dataLineStr = \trim($dataLineStr); | ||
|
||
$this->setValue($dataLineStr); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace M3uParser\Tests\Tag; | ||
|
||
use M3uParser\M3uData; | ||
use M3uParser\M3uEntry; | ||
use M3uParser\M3uParser; | ||
use M3uParser\Tag\ExtAlbumArtUrl; | ||
use M3uParser\Tag\ExtTagInterface; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @coversNothing | ||
*/ | ||
class ExtAlbumArtUrlTest extends TestCase | ||
{ | ||
public function testParseExtAlbumArtUrl(): void | ||
{ | ||
$m3uParser = new M3uParser(); | ||
$m3uParser->addDefaultTags(); | ||
$data = $m3uParser->parseFile(__DIR__.'/../fixtures/extalbumarturl.m3u'); | ||
|
||
/** @var M3uEntry $entry */ | ||
$entry = $data[0]; | ||
|
||
self::assertEquals('rtp://@127.0.0.1:5003', $entry->getPath()); | ||
|
||
/** @var ExtTagInterface[] $extTags */ | ||
$extTags = $entry->getExtTags(); | ||
self::assertCount(1, $extTags); | ||
|
||
/** @var ExtAlbumArtUrl $extAlbumArtUrl */ | ||
$extAlbumArtUrl = $extTags[0]; | ||
self::assertInstanceOf(ExtAlbumArtUrl::class, $extAlbumArtUrl); | ||
|
||
self::assertEquals('https://store.example.com/download/A32X5yz-1.jpg', $extAlbumArtUrl->getValue()); | ||
} | ||
|
||
public function testGenerateExtAlbumArtUrl(): void | ||
{ | ||
$expectedString = '#EXTM3U'."\n"; | ||
$expectedString .= '#EXTALBUMARTURL:https://store.example.com/download/A32X5yz-1.jpg'."\n"; | ||
$expectedString .= 'test-path'; | ||
|
||
$entry = new M3uEntry(); | ||
$entry->setPath('test-path'); | ||
$entry->addExtTag( | ||
(new ExtAlbumArtUrl()) | ||
->setValue('https://store.example.com/download/A32X5yz-1.jpg') | ||
); | ||
|
||
$data = new M3uData(); | ||
$data->append($entry); | ||
|
||
self::assertEquals($expectedString, (string) $data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#EXTM3U | ||
|
||
#EXTALBUMARTURL:https://store.example.com/download/A32X5yz-1.jpg | ||
rtp://@127.0.0.1:5003 |