veryroundbird revised this gist 1 month ago. Go to revision
1 file changed, 3 insertions, 4 deletions
playlist-exporter.php
| @@ -27,15 +27,14 @@ $items = array_map(function ($l) use ($argv) { | |||
| 27 | 27 | print_r($l); | |
| 28 | 28 | return array_combine($header, $l); | |
| 29 | 29 | }, array_slice($items, 1))); | |
| 30 | - | print_r($items); | |
| 31 | 30 | ||
| 32 | - | foreach ($items as $item) { | |
| 31 | + | foreach ($items as $k => $item) { | |
| 33 | 32 | $out = $argv[2].'/'.normalize_string($item['artist']).'-'.normalize_string($item['title']).'.mp3'; | |
| 34 | 33 | if (!file_exists($out) && file_exists($item['file'])) { | |
| 35 | 34 | $audio = $ffmpeg->open($item['file']); | |
| 36 | 35 | $audio->save(new FFMpeg\Format\Audio\MP3(), $out); | |
| 37 | 36 | } | |
| 38 | - | $item['file'] = $out; | |
| 37 | + | $items[$k]['file'] = $out; | |
| 39 | 38 | } | |
| 40 | 39 | ||
| 41 | 40 | $json = [ | |
| @@ -47,4 +46,4 @@ $json = [ | |||
| 47 | 46 | 'tracklist' => $items | |
| 48 | 47 | ]; | |
| 49 | 48 | ||
| 50 | - | file_put_contents(preg_replace('/\.[a-zA-Z0-9]$/', '', $argv[1]).'.json', json_encode($json)); | |
| 49 | + | file_put_contents(preg_replace('/\.[a-zA-Z0-9]$/', '', $argv[1]).'.json', json_encode($json, JSON_PRETTY_PRINT)); | |
veryroundbird revised this gist 1 month ago. Go to revision
1 file changed, 50 insertions
playlist-exporter.php(file created)
| @@ -0,0 +1,50 @@ | |||
| 1 | + | <?php | |
| 2 | + | ||
| 3 | + | require 'vendor/autoload.php'; | |
| 4 | + | $ffmpeg = FFMpeg\FFMpeg::create(); | |
| 5 | + | ||
| 6 | + | function normalize_string($str) { | |
| 7 | + | $out = str_replace(' ', '_', preg_replace('/[\'\"\(\)\.,\[\]]+/', '', strtolower(str_replace('Ke$ha', 'kesha', $str)))); | |
| 8 | + | return $out; | |
| 9 | + | } | |
| 10 | + | ||
| 11 | + | $file = trim(file_get_contents($argv[1])); | |
| 12 | + | $items = array_map(function ($l) { | |
| 13 | + | return explode("\t", $l); | |
| 14 | + | }, explode("\n", $file)); | |
| 15 | + | $header = array_slice($items, 0, 1)[0]; | |
| 16 | + | $items = array_map(function ($l) use ($argv) { | |
| 17 | + | return [ | |
| 18 | + | 'title' => $l['Name'], | |
| 19 | + | 'artist' => $l['Artist'], | |
| 20 | + | 'album' => $l['Album'], | |
| 21 | + | 'mime' => 'audio/mp3', | |
| 22 | + | 'file' => str_replace("Macintosh HD", "", $l['Location']), | |
| 23 | + | 'note' => '' | |
| 24 | + | ]; | |
| 25 | + | }, array_map(function ($l) use ($header) { | |
| 26 | + | print_r($header); | |
| 27 | + | print_r($l); | |
| 28 | + | return array_combine($header, $l); | |
| 29 | + | }, array_slice($items, 1))); | |
| 30 | + | print_r($items); | |
| 31 | + | ||
| 32 | + | foreach ($items as $item) { | |
| 33 | + | $out = $argv[2].'/'.normalize_string($item['artist']).'-'.normalize_string($item['title']).'.mp3'; | |
| 34 | + | if (!file_exists($out) && file_exists($item['file'])) { | |
| 35 | + | $audio = $ffmpeg->open($item['file']); | |
| 36 | + | $audio->save(new FFMpeg\Format\Audio\MP3(), $out); | |
| 37 | + | } | |
| 38 | + | $item['file'] = $out; | |
| 39 | + | } | |
| 40 | + | ||
| 41 | + | $json = [ | |
| 42 | + | 'title' => '', | |
| 43 | + | 'description' => '', | |
| 44 | + | 'cover' => '', | |
| 45 | + | 'tags' => [], | |
| 46 | + | 'pubDate' => '', | |
| 47 | + | 'tracklist' => $items | |
| 48 | + | ]; | |
| 49 | + | ||
| 50 | + | file_put_contents(preg_replace('/\.[a-zA-Z0-9]$/', '', $argv[1]).'.json', json_encode($json)); | |