Jump to content

Please help solve "Playlist Parse Create" script error.


Recommended Posts

I am a DJ and I am currently re-doing my website. I am a beginner at PHP; as a matter of fact, I hardly know PHP but I love digging into the code and trying to figure out what I need to tweak in order to get the results that I want; though, I have been stumped with this one. I came across a script that allows my prospect clients to create tracklists from my own playlists. They will then either print these or email them to me for whenever they have me play at their events. Anyway, this script is supposed to create a txt file, but oddly, it does not. Then, since it can't find it, it goes into an endless loop, causing my browser to crash! Here is the code so you can check it out and let me know what it is that I need to fix. I've also included the .zip file with all the files necessary. Thank you all in advance for assisting me on this one!

 

AUTHOR'S ABOUT FILE:

~~~~~~
Setup:
~~~~~~
Open config.php and add the name of your playlist (playlists must be in .m3u format and you must include this) to the variable $playlist
Example:

$playlist = "all.m3u";

Now just upload the playlist with this script, and that's it, your done.

~~~~~~~~~~~~
How It Works:
~~~~~~~~~~~~
We filter out all the information in the .m3u file that we don't need such as song path and tags
Then we load this into a text file, so we have a text version of your playlist including html select tags, this is called playlist.txt

Playlist.txt is then loaded inbetween form and listbox tags, creating the form full of songs you should see on the page.
Selected songs are then submitted to another text file named chosen.txt that is then displayed on the screen.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
What you may want in the future:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Intergtation into shoutcast stats to delete songs from the list once they have been played 

 

 

INDEX FILE:

<strong>Please Select A Song Request</strong><br>
<br>
<?php
// Read Original PLaylist
include ("config.php");
$handle = fopen($playlist,  "rb");
$contents = '';
while (!feof($handle)) {
  $contents .= fread($handle,  8192);
}
fclose($handle);

// Begin parsing and writing
$filename = 'playlist.txt';
$newline = "\n";
$text1 = str_replace ("#EXTINF:0, ",  "<option>" ,  $contents); // removes rubbish
$text1 = str_replace (".mp3",  "</option>" ,  $text1); // removes rubbish
$text1 = str_replace ("#EXTM3U",  "" ,  $text1); // removes more rubbish
$f=fopen($filename,  "wb");
fputs($f,  $text1);
fclose($f); // and writes file
$file = file($filename); // re opens file
$fp = fopen($filename,  'w');
foreach($file as $line){
  $line = trim($line);
  if(!empty($line)){ // removes blank lines
    fwrite($fp,  $line.$newline);
  }
}
fclose($fp);
$key = "\\"; // search for backslash,  this will remove file path in the playlist,  leaving us only with song names
$fc=file($filename);
$f=fopen($filename, "w");
foreach($fc as $line)
{
     if (!strstr($line, $key)) //look for $key in each line
           fputs($f, $line); //place $line back in file
}
fclose($f);
// Read new Text file
$handle1 = fopen("playlist.txt",  "rb");
$contents1 = '';
while (!feof($handle1)) {
  $contents1 .= fread($handle1,  8192);
}
fclose($handle1);
print "<form name=\"form1\" method=\"post\" action=\"index.php\">
</select>
     
<select name=\"select[]\" size=\"15\" multiple>";
echo $contents1;
print "</select><input type=\"submit\" name=\"Submit\" value=\"Submit\">
<input type=\"hidden\" name=\"good\" value=\"yes\"></form>";

// Create request list

if($_POST['good']=='yes') //if the hidden field was submitted (then we know our form has been)
{
// Create The m3u file with a random name
$filename = "chosen.txt"; // put the random number and the .m3u together.
$fp = fopen($filename,  'a'); // this will create the the m3u file since it doesn't exist
chmod($filename,  0777); // chmod our m3u to 777 so we can write data to it (and later delete the file)
fwrite($fp,  ""); // Again not 100% neccesary,  but just shows it can be written too
fclose($fp);  // close our m3u file.
// end creation
if (is_writable($filename)) { // if we can write to the file

   if (!$handle = fopen($filename,  'a')) { // but can't open it
         echo "Cannot open file ($filename)"; // print out an error message.
         exit; // and exit.
   } // and close the if statement.

$topicArray = $_POST['select']; // Get The Array of mp3's and wma's from our selectbox.
foreach ($topicArray as $select) // and for everyone
{
// Write The data from the selectbox to our opened file.
   if (fwrite($handle,  $select) === FALSE) { // more error checking for if file cannot be written to,  if it can do it.
       echo "Cannot write to file ($filename)"; // and error message if it can't.
       exit; // and exit
   } // and close the if statement
   fwrite($handle,  "<br>"); // and write a new line character so that each link to the mp3 / wma goes on a new line so media player
   // can read the file.
   }}}
   // Read Original PLaylist
$handle5 = fopen("chosen.txt",  "rb");
$contents5 = '';
while (!feof($handle5)) {
  $contents5 .= fread($handle5,  8192);
}
fclose($handle5);
echo "<strong>Songs To Be Played</strong><br><br>";
echo $contents5;
?>

 

 

CONFIG FILE:

<?PHP
// Upload a playlist in .m3u format in the same folder as the script files and add its name to the variable below

$playlist = "all.m3u";
?> 

 

And here is a screenshot of the errors:

 

error.jpg

 

[attachment deleted by admin]

Thanks for replying so quick. I went ahead and uploaded a text file named "chosen.txt" and chmoded to 777 just in case. The end is met but I do not get the list of songs in the Playlist I have uploaded named "all.m3u"; thus, I can't select any of the songs to test this script. Here is a screenshot...

 

nothing.jpg

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.