Skip to content

Commit

Permalink
EXT-X-MEDIA tag should be multiple
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisyue committed Mar 8, 2019
1 parent eb92b89 commit 02ac68f
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 111 deletions.
124 changes: 121 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,125 @@ PHP M3u8

An M3u8 parser / dumper.

By default, it fully supports for [RFC 8216](docs/supported-tags.md), however
it can support for non standard M3U(8) too, with little effort.
Now it fully supports for [RFC 8216](docs/supported-tags.md), and
it can support for non standard M3U(8) with little effort.

Please read the [docs](docs/index.md) for a quickstart and documentations.
Installation
------------

Use composer to require it, version 3 above is recommended.

```bash
composer require 'chrisyue/php-m3u8:^3'
```

Quickstart
----------

Setup the demo project and install PHP M3U8 with it:

```bash
mkdir demo
cd demo
composer require 'chrisyue/php-m3u8:^3'
```

Create a PHP script `demo.php` in project root

```bash
touch demo.php
```

Copy the code below to `demo.php`:

```php
<?php

use Chrisyue\PhpM3u8\Facade\DumperFacade;
use Chrisyue\PhpM3u8\Facade\ParserFacade;
use Chrisyue\PhpM3u8\Stream\TextStream;

require 'vendor/autoload.php';

$parser = new ParserFacade();
$dumper = new DumperFacade();

echo '*** Parsing media playlist... ***', PHP_EOL;

$m3u8Content = <<<'M3U8'
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:7794
#EXT-X-TARGETDURATION:15

#EXT-X-KEY:METHOD=AES-128,URI="https://priv.example.com/key.php?r=52"

#EXTINF:2.833,
http://media.example.com/fileSequence52-A.ts
#EXTINF:15.0,
http://media.example.com/fileSequence52-B.ts
#EXTINF:13.333,
http://media.example.com/fileSequence52-C.ts

#EXT-X-KEY:METHOD=AES-128,URI="https://priv.example.com/key.php?r=53"

#EXTINF:15.0,
http://media.example.com/fileSequence53-A.ts
M3U8;

$mediaPlaylist = $parser->parse(new TextStream($m3u8Content));

var_export($mediaPlaylist);
echo PHP_EOL;

// PARSING MEDIA PLAYLIST DEMO END

echo '*** Dumping media playlist... ***', PHP_EOL;
$text = new TextStream();
$dumper->dump($mediaPlaylist, $text);

echo $text, PHP_EOL;

echo '*** Parsing master playlist... ***', PHP_EOL;
$m3u8Content = <<<'M3U8'
#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=1280000,AVERAGE-BANDWIDTH=1000000
http://example.com/low.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=2560000,AVERAGE-BANDWIDTH=2000000
http://example.com/mid.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=7680000,AVERAGE-BANDWIDTH=6000000
http://example.com/hi.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=65000,CODECS="mp4a.40.5"
http://example.com/audio-only.m3u8
M3U8;

$masterPlaylist = $parser->parse(new TextStream($m3u8Content));

var_export($masterPlaylist);
echo PHP_EOL;

// PARSING MASTER PLAYLIST DEMO END

// DUMPING DEMO START

echo '*** Dumping media playlist... ***', PHP_EOL;
$text = new TextStream();
$dumper->dump($masterPlaylist, $text);

echo $text, PHP_EOL;
```

And run:

```bash
php demo.php
```

As a "Facade" hides too much details, if you take a look of those facade
classes, you'll notice that the real parser/dumper will take a "tag definitions"
and a "parsing/dumping rules" as it's dependencies. "definitions" and "rules" are
actually "configuration". All these "configuration"s are written in PHP. You may
want to modify those configuration files to meet your needs. For more
information, see
- [How to Define A Tag](docs/how-to-define-a-tag.md)
- [How to Make A Parsing/Dumping Rule](docs/how-to-make-a-parsing-dumping-rule.md)
108 changes: 0 additions & 108 deletions docs/index.md

This file was deleted.

1 change: 1 addition & 0 deletions resources/tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
'CHANNELS' => 'quoted-string',
],
'position' => -1900,
'multiple' => true,
],
'EXT-X-STREAM-INF' => [
'category' => 'master-playlist',
Expand Down

0 comments on commit 02ac68f

Please sign in to comment.