Thank you, I am new to this forum and if I could apologize in advance if this post is not in the correct location.
I have having trouble reading an external m3u file (playlist) into my php code, thought someone has done this before and could give me an idea or lined solution example of what my incomplete line should look like.
I do know that, M3U files are just plain text, with each line being either a comment (starts with a #) or a path to a file (doesn't start with a #). I still dont know how to load each line of the M3U file into an array, then loop over it and of course only use the lines that don't start with a "#".
The way things work like this...
You start a stream. This reads an M3U file with a list of songs.
The steam plays the songs in the order they are listed in the M3U file.
The question which i have somewhat resolved is I need to know what time every song will play during the next week assuming the stream is not restarted. If it is restarted then the entire week prediction needs to be recalculated.
The first problem was that the songs are not likely to have lengths which are perfect seconds, and the streamer may drop a bit of time between songs, so the longer the stream is up, the less accurate the prediction will be. This could be corrected by observing the current song and the current time and fixing up the calculation periodically. I am skipping this problem for now.
The main thing I need to do is, given a time T, show what song will be playing at time T + X. I believe this should be as simple as counting the number of seconds in a week and working my way through the playlist over and over for the week.
I have attached a sample script that you might be able to assist on. Right now It contains one function that generates a schedule given a time, a length and a playlist. There are also an example playlist with some made up song titles and lengths.
I will need to figure out how to convert the m3u playlist into an array like this
$playlist = array();
$playlist[] = array('title' => 'Junk Monster - MPG', 'length' => 180);
$playlist[] = array('title' => 'A Bell Tolls - MR', 'length' => 625);
$playlist[] = array('title' => 'Enter The Wagon - Soulless', 'length' => 76);
$playlist[] = array('title' => 'Conjoined - Twister', 'length' => 523);
$playlist[] = array('title' => 'Poutine - The Canucks', 'length' => 23);
$playlist[] = array('title' => 'Autobus - Exploradoras', 'length' => 758);
$playlist[] = array('title' => 'Rusty Shovel Medley - Ramshackle', 'length' => 254);
$playlist[] = array('title' => 'Purple Lung - Twin Mountain Match', 'length' => 876);
$playlist[] = array('title' => 'Cold Pizza, Hot Cola - Pacifica', 'length' => 234);
$playlist[] = array('title' => 'Nothing Works - MTL', 'length' => 68);
Thanking for you assistance in advance....
Full code below
<?php
function calculate_schedule($start_timestamp, $length_in_seconds, $playlist) {
$schedule = array();
$i = 0;
$song = 0;
while($i < $length_in_seconds) {
$schedule[] = array('timestamp' => $start_timestamp + $i, 'title' => $playlist[$song]['title'], 'length' => $playlist[$song]['length']);
$i += $playlist[$song]['length'];
$song = ($song + 1) % count($playlist);
}
return $schedule;
}
// I will need to figure out how to convert the m3u playlist into an array like this
$playlist = array();
$playlist[] = array('title' => 'Junk Monster - MPG', 'length' => 180);
$playlist[] = array('title' => 'A Bell Tolls - MR', 'length' => 625);
$playlist[] = array('title' => 'Enter The Wagon - Soulless', 'length' => 76);
$playlist[] = array('title' => 'Conjoined - Twister', 'length' => 523);
$playlist[] = array('title' => 'Poutine - The Canucks', 'length' => 23);
$playlist[] = array('title' => 'Autobus - Exploradoras', 'length' => 758);
$playlist[] = array('title' => 'Rusty Shovel Medley - Ramshackle', 'length' => 254);
$playlist[] = array('title' => 'Purple Lung - Twin Mountain Match', 'length' => 876);
$playlist[] = array('title' => 'Cold Pizza, Hot Cola - Pacifica', 'length' => 234);
$playlist[] = array('title' => 'Nothing Works - MTL', 'length' => 68);
// next we get the assume the start time of the stream is the current time
date_default_timezone_set('America/New_York');
$start = time();
// ask the function to calculate one week of programming
$seconds_per_week = 86400 * 7;
// get the schedule
$schedule = calculate_schedule($start, $seconds_per_week, $playlist);
// see http://php.net/date for formatting details
$display_format = 'Y-m-d H:i:s';
// display the schedule
foreach($schedule as $item) {
printf("%s %s (%d)<br />\n", date($display_format, $item['timestamp']), $item['title'], $item['length']);
}
?>