Skip to content

Instantly share code, notes, and snippets.

@1d10t
Created February 15, 2018 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1d10t/2dbb3bea938a130bd27771e0d0730387 to your computer and use it in GitHub Desktop.
Save 1d10t/2dbb3bea938a130bd27771e0d0730387 to your computer and use it in GitHub Desktop.
<?php
$f = fopen('ttv.all.iproxy.m3u', 'r');
$i = 0;
$name = $folder = null;
while(($s = fgets($f)) !== false){
$s = trim($s);
if($s === ''){
continue;
}
if($s[0] != '#'){
$i++;
if(is_null($name)) $name = $i;
if(is_null($folder)) $folder = 'unsorted';
$nf = "m3u/".preg_replace('#[^A-Za-zА-Яа-яЁё\(\)\[\]\+\-\d ]#u', '_', $folder)
."/".preg_replace('#[^A-Za-zА-Яа-яЁё\(\)\[\]\+\-\d ]#u', '_', $name).".m3u";
$nf = iconv('utf-8', 'windows-1251', $nf);
$df = dirname($nf);
if(!file_exists($df))
mkdir(dirname($nf), 0777, true);
file_put_contents($nf, "#EXTM3U\r\n\r\n#EXTINF:-1,{$name}\r\n{$s}\r\n");
$name = $folder = null;
}else{
// #EXTINF:-1,Ani (Детские)
if(preg_match('~^#EXTINF\:\-?\d+,(.*)$~ui', $s, $t)){
$name = $t[1];
if(preg_match('#^(.*)\s+\(([^\)]+)\)$#', $name, $t)){
$name = $t[1];
$folder = $t[2];
}
}
}
}
fclose($f);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment