I am not sure exactly what you would call such a task but hopefully the title may be onto some of it!
Lets get started..
I have a folder that contains .m3us. The m3us are actually Genre related to music. So you would have 00s.m3u, 50s.m3u etc. Inside these files there is just plain URLs followed by newline to the exact path to a MP3. This was used for a search mech but we have now moved onto SQLITE.
Example of inside m3us:
http://streamlink.com/rihanna%20-%20work.mp3
http://streamlink.com/taylor%20swift-%20love%20story.mp3
My aim here is to loop through each m3u (Genre), create an array of those tracks with information relating to that track. So you would have artistname, trackname, genre1, genre2, genre3. If it comes out of 00s Genre. It would make an array that includes 00s for genre1-3. Seeing as there is no other record of it! BUT, if lets say http://streamlink.com/rihanna%20-%20work.mp3
shows up in 00s & 50s. I then want it to make a final array with all the tracks as is! Fully ready for me to then create my sqlite file and go on with my business. Going back to the 00s & 50s issue, if i have that EXACT same rihanna track in multiple genres. I want it to then create a final item in a final array of items that fills my genres 1 - 3. So i would be left with: Rihanna, work, 00s, 50s, "genre3 can be blank here or you can fill with 00s or 50s if there is no other genre to fill in". Now there cant be no more than 3 genres! So if we have rihanna in 00s, 50s, 60s, dance. It will only put in the first 3 it finds! So it will be left with: Rihanna, work, 00s, 50s, 60s and dance will not go anywhere! So no matter what, i want a final array that consists of all my tracks fully tagged with information with genre 1 - 3 of course filled with either genres it came across in. Or just the first genre filled into 1 - 3 so if it only finds rihanna once and only in 00s. Then it should show 00s,00s,00s. Or just 00s,"","" it doesnt exactly matter!
The part i am stuck at is i am not sure how to create final array that can include 00s,50s,60s if rihanna shows up in those. I currently loop through each file, create the data and push to an array. I am not sure where to go from there!
My code:
<?PHP
$Genres = scandir("/var/lib/mpd/playlists");
$testArray = [];
foreach($Genres as $genre)
{
if($genre !== "." && $genre !== "..")
{
$StrippedGenreName = str_replace("Genres - ", "", str_replace(".m3u","",$genre));
$GenreArray = explode("\n", file_get_contents("/var/lib/mpd/playlists/".$genre));
foreach($GenreArray as $genredata)
{
$TrackPath = $genredata;
$RawForm = str_replace(".mp3", "", str_replace("%20", " ", str_replace("http://streamlink.com/", "", $genredata)));
$TrackDecide = explode(" - ", $RawForm);
$ArtistName = $TrackDecide[0];
$TrackName = $TrackDecide[1];
$GenreData = array("",$TrackPath,$ArtistName,$TrackName,"","",$StrippedGenreName,$StrippedGenreName,$StrippedGenreName,"","Audio");
array_push($testArray, $GenreData);
}
}
}
print("<pre>".print_r($testArray,true)."</pre>");
//Code here to do final array task
?>
My output:
Array
(
[0] => Array
(
[0] =>
[1] => http://streamlink.com/2Pac%20Feat.%20Elton%20John%20-%20Ghetto%20Gospel.mp3
[2] => 2Pac Feat. Elton John
[3] => Ghetto Gospel
[4] =>
[5] =>
[6] => 00s
[7] => 00s
[8] => 00s
[9] =>
[10] => Audio
)
[1] => Array
(
[0] =>
[1] => http://streamlink.com/Aaliyah%20-%20Try%20Again.mp3
[2] => Aaliyah
[3] => Try Again
[4] =>
[5] =>
[6] => 00s
[7] => 00s
[8] => 00s
[9] =>
[10] => Audio
)
[2] => Array
(
[0] =>
[1] => http://streamlink.com/Adele%20-%20Chasing%20Pavements.mp3
[2] => Adele
[3] => Chasing Pavements
[4] =>
[5] =>
[6] => 00s
[7] => 00s
[8] => 00s
[9] =>
[10] => Audio
)
[3] => Array
(
[0] =>
[1] => http://streamlink.com/Al%20Hibbler%20-%20Unchained%20Melody.mp3
[2] => Al Hibbler
[3] => Unchained Melody
[4] =>
[5] =>
[6] => 50s
[7] => 50s
[8] => 50s
[9] =>
[10] => Audio
)
[4] => Array
(
[0] =>
[1] => http://streamlink.com/Al%20Martino%20-%20Here%20In%20My%20Heart.mp3
[2] => Al Martino
[3] => Here In My Heart
[4] =>
[5] =>
[6] => 50s
[7] => 50s
[8] => 50s
[9] =>
[10] => Audio
)
[5] => Array
(
[0] =>
[1] => http://streamlink.com/Alma%20Cogan%20-%20Dreamboat.mp3
[2] => Alma Cogan
[3] => Dreamboat
[4] =>
[5] =>
[6] => 50s
[7] => 50s
[8] => 50s
[9] =>
[10] => Audio
)
[6] => Array
(
[0] =>
[1] => http://streamlink.com/2Pac%20Feat.%20Elton%20John%20-%20Ghetto%20Gospel.mp3
[2] => 2Pac Feat. Elton John
[3] => Ghetto Gospel
[4] =>
[5] =>
[6] => 50s
[7] => 50s
[8] => 50s
[9] =>
[10] => Audio
)
[7] => Array
(
[0] =>
[1] => http://streamlink.com/Acker%20Bilk%20-%20Stranger%20On%20The%20Shore.mp3
[2] => Acker Bilk
[3] => Stranger On The Shore
[4] =>
[5] =>
[6] => 60s
[7] => 60s
[8] => 60s
[9] =>
[10] => Audio
)
[8] => Array
(
[0] =>
[1] => http://streamlink.com/Adam%20Faith%20-%20Poor%20Me.mp3
[2] => Adam Faith
[3] => Poor Me
[4] =>
[5] =>
[6] => 60s
[7] => 60s
[8] => 60s
[9] =>
[10] => Audio
)
[9] => Array
(
[0] =>
[1] => http://streamlink.com/Allisons%20-%20Are%20You%20Sure.mp3
[2] => Allisons
[3] => Are You Sure
[4] =>
[5] =>
[6] => 60s
[7] => 60s
[8] => 60s
[9] =>
[10] => Audio
)
)
So in this example, we can see that http://streamlink.com/2Pac%20Feat.%20Elton%20John%20-%20Ghetto%20Gospel.mp3
shows up under 00s & 50s. It should then be able to create a new array of all the items in its full state of information.
So i should be left with:
Array
(
[0] => Array
(
[0] =>
[1] => http://streamlink.com/2Pac%20Feat.%20Elton%20John%20-%20Ghetto%20Gospel.mp3
[2] => 2Pac Feat. Elton John
[3] => Ghetto Gospel
[4] =>
[5] =>
[6] => 00s
[7] => 50s
[8] => 50s
[9] =>
[10] => Audio
)
[1] => Array
(
[0] =>
[1] => http://streamlink.com/Aaliyah%20-%20Try%20Again.mp3
[2] => Aaliyah
[3] => Try Again
[4] =>
[5] =>
[6] => 00s
[7] => 00s
[8] => 00s
[9] =>
[10] => Audio
)
[2] => Array
(
[0] =>
[1] => http://streamlink.com/Adele%20-%20Chasing%20Pavements.mp3
[2] => Adele
[3] => Chasing Pavements
[4] =>
[5] =>
[6] => 00s
[7] => 00s
[8] => 00s
[9] =>
[10] => Audio
)
[3] => Array
(
[0] =>
[1] => http://streamlink.com/Al%20Hibbler%20-%20Unchained%20Melody.mp3
[2] => Al Hibbler
[3] => Unchained Melody
[4] =>
[5] =>
[6] => 50s
[7] => 50s
[8] => 50s
[9] =>
[10] => Audio
)
[4] => Array
(
[0] =>
[1] => http://streamlink.com/Al%20Martino%20-%20Here%20In%20My%20Heart.mp3
[2] => Al Martino
[3] => Here In My Heart
[4] =>
[5] =>
[6] => 50s
[7] => 50s
[8] => 50s
[9] =>
[10] => Audio
)
[5] => Array
(
[0] =>
[1] => http://streamlink.com/Alma%20Cogan%20-%20Dreamboat.mp3
[2] => Alma Cogan
[3] => Dreamboat
[4] =>
[5] =>
[6] => 50s
[7] => 50s
[8] => 50s
[9] =>
[10] => Audio
)
[6] => Array
(
[0] =>
[1] => http://streamlink.com/Acker%20Bilk%20-%20Stranger%20On%20The%20Shore.mp3
[2] => Acker Bilk
[3] => Stranger On The Shore
[4] =>
[5] =>
[6] => 60s
[7] => 60s
[8] => 60s
[9] =>
[10] => Audio
)
[7] => Array
(
[0] =>
[1] => http://streamlink.com/Adam%20Faith%20-%20Poor%20Me.mp3
[2] => Adam Faith
[3] => Poor Me
[4] =>
[5] =>
[6] => 60s
[7] => 60s
[8] => 60s
[9] =>
[10] => Audio
)
[8] => Array
(
[0] =>
[1] => http://streamlink.com/Allisons%20-%20Are%20You%20Sure.mp3
[2] => Allisons
[3] => Are You Sure
[4] =>
[5] =>
[6] => 60s
[7] => 60s
[8] => 60s
[9] =>
[10] => Audio
)
)
Please note the array[0] that shows http://streamlink.com/2Pac%20Feat.%20Elton%20John%20-%20Ghetto%20Gospel.mp3
having merged is info to now include Genre1: 00s, Genre2: 50s & Genre3 to be 50s also. This is how i would want the final array to contain.
I hope i explained myself and someone may be able to shed some light or point me in the right direction! Thanks!!
It looks to me as if the streamlink is kind of a unique identifier for a specific track across m3u files. So I would base my array on that and use it as first level key in the result:
[
'http://streamlink.com/2Pac%20Feat.%20Elton%20John%20-%20Ghetto%20Gospel.mp3' => [
[0] =>
[1] => http://streamlink.com/2Pac%20Feat.%20Elton%20John%20-%20Ghetto%20Gospel.mp3
[2] => 2Pac Feat. Elton John
[3] => Ghetto Gospel
[4] =>
[5] =>
[6] => 00s
[7] => 00s
[8] => 00s
[9] =>
[10] => Audio
]
etc. That way you can easily match the same file and add the tags. And if you need to get rid of the keys at the end to have a normal array you can just run array_values
on it.