-
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
7 changed files
with
156 additions
and
6 deletions.
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
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,73 @@ | ||
<?php | ||
|
||
namespace M3uParser\Tag; | ||
|
||
/** | ||
* @see https://github.com/Gemorroj/M3uParser/issues/27 | ||
*/ | ||
class ExtVlcOpt implements ExtTagInterface | ||
{ | ||
private string $key; | ||
private string $value; | ||
|
||
/** | ||
* #EXTVLCOPT:http-user-agent=Mozilla/5.0 (Windows NT 6.1; rv:61.0) Gecko/20100101 Firefox/61.0. | ||
*/ | ||
public function __construct(string $lineStr = null) | ||
{ | ||
if (null !== $lineStr) { | ||
$this->make($lineStr); | ||
} | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return '#EXTVLCOPT:'.$this->getKey().'='.$this->getValue(); | ||
} | ||
|
||
public function setKey(string $key): self | ||
{ | ||
$this->key = $key; | ||
|
||
return $this; | ||
} | ||
|
||
public function getKey(): string | ||
{ | ||
return $this->key; | ||
} | ||
|
||
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, '#EXTVLCOPT:'); | ||
} | ||
|
||
protected function make(string $lineStr): void | ||
{ | ||
/* | ||
EXTVLCOPT format: | ||
#EXTVLCOPT:<key> = <value> | ||
example: | ||
#EXTVLCOPT:http-user-agent=Mozilla/5.0 (Windows NT 6.1; rv:61.0) Gecko/20100101 Firefox/61.0 | ||
*/ | ||
$dataLineStr = \substr($lineStr, \strlen('#EXTVLCOPT:')); | ||
$dataLineStr = \trim($dataLineStr); | ||
|
||
[$key, $value] = \explode('=', $dataLineStr, 2); | ||
|
||
$this->setKey($key); | ||
$this->setValue($value); | ||
} | ||
} |
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
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,61 @@ | ||
<?php | ||
|
||
namespace M3uParser\Tests\Tag; | ||
|
||
use M3uParser\M3uData; | ||
use M3uParser\M3uEntry; | ||
use M3uParser\M3uParser; | ||
use M3uParser\Tag\ExtTagInterface; | ||
use M3uParser\Tag\ExtVlcOpt; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @coversNothing | ||
*/ | ||
class ExtVlcOptTest extends TestCase | ||
{ | ||
public function testParseExtVlcOpt(): void | ||
{ | ||
$m3uParser = new M3uParser(); | ||
$m3uParser->addDefaultTags(); | ||
$data = $m3uParser->parseFile(__DIR__.'/../fixtures/extvlcopt.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 ExtVlcOpt $extVlcOpt */ | ||
$extVlcOpt = $extTags[0]; | ||
self::assertInstanceOf(ExtVlcOpt::class, $extVlcOpt); | ||
|
||
self::assertEquals('http-user-agent', $extVlcOpt->getKey()); | ||
self::assertEquals('Lavf53.32.100', $extVlcOpt->getValue()); | ||
} | ||
|
||
public function testGenerateExtVlcOpt(): void | ||
{ | ||
$expectedString = '#EXTM3U'."\n"; | ||
$expectedString .= '#EXTVLCOPT:some-key=some-value'."\n"; | ||
$expectedString .= 'test-path'; | ||
|
||
$entry = new M3uEntry(); | ||
$entry->setPath('test-path'); | ||
$entry->addExtTag( | ||
(new ExtVlcOpt()) | ||
->setKey('some-key') | ||
->setValue('some-value') | ||
); | ||
|
||
$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 | ||
|
||
#EXTVLCOPT:http-user-agent=Lavf53.32.100 | ||
rtp://@127.0.0.1:5003 |