Unique files / songs in M3U playlists
A PHP script to sort out double entries while maintaining #EXTINF meta info.
Just hand over the file name like m3u-unique.php?fn=c:/mp3/testfile.m3u
Directory is optional. The new playlist will be named 'testfile-unique.m3u' in this example. File extension should always be m3u.
$fn=$_GET['fn'];
if (!file_exists($fn)) {print"file not found.";exit;}
$f=file($fn);
$m='';
foreach ($f as $k=>$s) {
if ($s[0]=='#'&&$k) {$m=$s;unset($f[$k]);}
else {
if ($m) {$f[$k]=$m.$s;}
$m='';}}
$f=array_unique($f);
file_put_contents(substr($fn,0,-4).'-unique.m3u',$f);
print"done.";