From dc163e3d6d7d14d94b06f3f6b0c1a77acf919b68 Mon Sep 17 00:00:00 2001 From: Draconis Date: Tue, 13 Feb 2024 09:53:18 +0100 Subject: [PATCH] =?UTF-8?q?g=C3=A9n=C3=A9ration=20du=20m3U?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- playlist_gen.php | 102 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 playlist_gen.php diff --git a/playlist_gen.php b/playlist_gen.php new file mode 100644 index 0000000..9eb84b2 --- /dev/null +++ b/playlist_gen.php @@ -0,0 +1,102 @@ +analyze($filename); + getid3_lib::CopyTagsToComments($fileinfo); // To get id3v1 and id3v2 tags at the same place. + $duration = (string)floor($fileinfo['playtime_seconds']); + $GLOBALS['TOTALTIME'] += $fileinfo['playtime_seconds']; + $artist = $fileinfo['comments']['artist'][0]; + $title = $fileinfo['comments']['title'][0]; + return '#EXTINF:'.$duration.','.$artist.' - '.$title; +} +/** + * Builds a m3u playlist from all mp3 files located in a directory. + * Returns a properly formatted m3u file. + * Input: $dir : directory to scan. + * $baseurl : Base URL where this directory is served. + * Output: (string) the resulting m3u file. + */ +function buildM3u($dir,$baseurl) +{ + $lines = Array(); + foreach(getFilesFromDir($dir) as $filename) + { + if (pathinfo($filename, PATHINFO_EXTENSION)=='mp3') + { + echo "Processing $filename\n"; + $lines[] = makeEXTInfLine($filename); + $lines[] = $baseurl.substr($filename, strlen($dir)); + } + } + return implode("\n",$lines); +} + +$data = buildM3u('.','https://sebsauvage.net/ambient'); +file_put_contents('playlist.m3u',$data); +echo 'Playlist regénérée. Durée totale (en secondes): ',$GLOBALS['TOTALTIME']; +?> \ No newline at end of file