Advertisement
TonyAR

mpd track listing

Sep 6th, 2022 (edited)
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.48 KB | None | 0 0
  1. /*
  2. I wanted the output to look like this:
  3.  
  4. 38 Special - The Very Best of the A&M Years (1977-1988) - Rockin' Into the Night
  5. 38 Special - The Very Best of the A&M Years (1977-1988) - Hold on Loosely
  6. 38 Special - The Very Best of the A&M Years (1977-1988) - Wild-Eyed Southern Boys
  7. 38 Special - The Very Best of the A&M Years (1977-1988) - Fantasy Girl
  8. etc...
  9. */
  10.  
  11. // Solution - probably a bit crude but it works.
  12. // the foreach loop can go into a function
  13. // Input array is $playlistid (see below)
  14.  
  15. unset($playlistid[0]);
  16. array_pop($playlistid);
  17.  
  18. $album = preg_grep('/\bAlbum:\s/', $playlistid);
  19. $artist = preg_grep('/\bArtist:\s/', $playlistid);
  20. $title = preg_grep('/\bTitle:\s/', $playlistid);
  21.  
  22. $album = array_values($album);
  23. $artist = array_values($artist);
  24. $title = array_values($title);
  25. $arr_count=count($album);
  26. $range = range(0,$arr_count -1);
  27.  
  28. foreach($range as $list) {
  29.         $artist_title = trim(str_replace("Artist:", "", $artist[$list]));
  30.         $song_title = trim(str_replace("Title:", "", $title[$list]));
  31.         $album_title = trim(str_replace("Album:", "", $album[$list]));
  32.         echo "{$artist_title} - {$album_title} - {$song_title}\n";
  33. }
  34.  
  35. /*
  36. Input array ($playlistid)
  37.  
  38. Array
  39. (
  40.     [1] => file: 38_Special/The_Very_Best_of_the_A_and_M_Years-1977-1988/01_Rockin_Into_the_Night.flac
  41.     [2] => Last-Modified: 2020-06-03T12:24:50Z
  42.     [3] => Format: 44100:16:2
  43.     [4] => Album: The Very Best of the A&M Years (1977-1988)
  44.     [5] => Artist: 38 Special
  45.     [6] => Composer: Frank Sullivan; Gary Smith; Jim Peterik
  46.     [7] => Date: 2003
  47.     [8] => Genre: Southern Rock
  48.     [9] => Title: Rockin' Into the Night
  49.     [10] => Track: 1
  50.     [11] => AlbumArtist: 38 Special
  51.     [12] => Time: 240
  52.     [13] => duration: 239.600
  53.     [14] => Pos: 0
  54.     [15] => Id: 878
  55.     [16] => file: 38_Special/The_Very_Best_of_the_A_and_M_Years-1977-1988/02_Hold_on_Loosely.flac
  56.     [17] => Last-Modified: 2020-06-03T12:24:50Z
  57.     [18] => Format: 44100:16:2
  58.     [19] => Album: The Very Best of the A&M Years (1977-1988)
  59.     [20] => Artist: 38 Special
  60.     [21] => Composer: Don Barnes; Jeff Carlisi; Jim Peterik
  61.     [22] => Date: 2003
  62.     [23] => Genre: Southern Rock
  63.     [24] => Title: Hold on Loosely
  64.     [25] => Track: 2
  65.     [26] => AlbumArtist: 38 Special
  66.     [27] => Time: 280
  67.     [28] => duration: 279.800
  68.     [29] => Pos: 1
  69.     [30] => Id: 879
  70.     [31] => file: 38_Special/The_Very_Best_of_the_A_and_M_Years-1977-1988/03_Wild-Eyed_Southern_Boys.flac
  71.     [32] => Last-Modified: 2020-06-03T12:24:50Z
  72.     [33] => Format: 44100:16:2
  73.     [34] => Album: The Very Best of the A&M Years (1977-1988)
  74.     [35] => Artist: 38 Special
  75.     [36] => Composer: Jim Peterik
  76.     [37] => Date: 2003
  77.     [38] => Genre: Southern Rock
  78.     [39] => Title: Wild-Eyed Southern Boys
  79.     [40] => Track: 3
  80.     [41] => AlbumArtist: 38 Special
  81.     [42] => Time: 257
  82.     [43] => duration: 257.399
  83.     [44] => Pos: 2
  84.     [45] => Id: 880
  85.     [46] => file: 38_Special/The_Very_Best_of_the_A_and_M_Years-1977-1988/04_Fantasy_Girl.flac
  86.     [47] => Last-Modified: 2020-06-03T12:24:50Z
  87.     [48] => Format: 44100:16:2
  88.     [49] => Album: The Very Best of the A&M Years (1977-1988)
  89.     [50] => Artist: 38 Special
  90.     [51] => Composer: Jeff Carlisi; Jim Peterik
  91.     [52] => Date: 2003
  92.     [53] => Genre: Southern Rock
  93.     [54] => Title: Fantasy Girl
  94.     [55] => Track: 4
  95.     [56] => AlbumArtist: 38 Special
  96.     [57] => Time: 245
  97.     [58] => duration: 244.866
  98.     [59] => Pos: 3
  99.     [60] => Id: 881
  100. )
  101.  
  102. <snip>
  103. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement