-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm3u2strm.php
executable file
·56 lines (47 loc) · 1.33 KB
/
m3u2strm.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
require __DIR__ . '/vendor/autoload.php';
use M3uParser\M3uParser;
if(!isset($argv[1]))
{
die("Usage : php m3u2strm <m3u url or m3u filename>\n");
}
error_reporting(E_ALL & ~E_NOTICE);
$m3uParser = new M3uParser();
$m3uParser->addDefaultTags();
try
{
$raw_m3u = file_get_contents($argv[1]);
//$data = $m3uParser->parseFile('data.m3u');
if($data = $m3uParser->parse($raw_m3u))
{
/** @var \M3uParser\M3uEntry $entry */
$index=[];
foreach ($data as $entry) {
$meta=[];
foreach ($entry->getExtTags() as $extTag) {
switch ($extTag) {
case $extTag instanceof \M3uParser\Tag\ExtInf: // If EXTINF tag
$meta['group']=str_replace(["/",".","'","`"],"_",trim($extTag->getAttribute("group-title")));
$meta['title']=str_replace(["/",".","'","`"],"_",trim($extTag->getAttribute("tvg-name")));
$meta['title']=str_replace("#EXTINF:0,","",$meta['title']);
}
}
$meta['path']=$entry->getPath();
$index[$meta['group']][]=$meta;
}
foreach($index as $group=>$entries)
{
mkdir("output/".$group,0777,true);
foreach($entries as $entry)
{
echo "Group : $group | Title : {$entry['title']}\n";
file_put_contents("output/".$group."/".$entry['title'].".strm",$entry['path']);
}
}
}else{
die("Failed to parse m3u file\n");
}
}catch(Exception $e){
echo $e;
die("Error: ".$e->getMessage()."\n");
}