Jump to content

Recommended Posts

First I would like to thank the users here who have helped me to get this far. The script I am about to show you works fine with small videos (tested with like 30 seconds fine) but larger videos cause the browser to freezeup and then eventually it will go back to normal but the video wasnt uploaded or added to the playlist. The script reads a url from a form, gets a video from youtube, saves it to the server, adds the filename to a playlist and exits. Please dont be offended by the code you are about to see, I'm roughly new at this (2 1/2 years of on and mostly off)

 

<?
/* machination.no-ip.info */
/* include the standard headers */
include('header.php');
include('headers/connect.php');


/* checks to see if the video should be grabbed - should probly check for submit instead of variable  */
if (isset($_POST['url'])) {

/* The posted variables from the form */
$url = $_POST['url'];
$track = $_POST['track'];
$desc = $_POST['desc'];
$handle = @fopen ($url, "r");

/* Find the download ticket so we can actually request the video special thanks to Pascal from mediapirate.org for this part */
if($handle){
    while(!feof($handle)){
         $code .= fread($handle, 1024);
    }
    fclose($handle);

    $expression = '/v=([A-Za-z0-9_-]+)/';
    preg_match_all($expression,$url,$video);
    $expression = '/t\=([A-Za-z0-9_-]{5,})/';
    preg_match_all($expression,$code,$ticket);



/* Remove the spaces so that we can create a table cuz ive had problems with spaces also get a filename and stuff ready for the grab and save */
$badtags = array("v=");

$urlp1 = str_replace($badtags, "", $video[0][0]);
$random = (rand()%50000);
$fullurl="http://www.youtube.com/get_video?video_id=".$urlp1."&".$ticket[0][0];
$filename="videos/".$random.".flv";




/* Get the file from the url and save it */
ob_start();
readfile($fullurl);
$file = ob_get_contents();
ob_end_clean();


$fp = fopen($filename, 'wb');
fwrite($fp, $file);
fclose($fp);

print "<tr class=\"content\"><td colspan=\"2\">Thank You. Your Video has been added";
}

/* this first part seems firmiliar - I think i did it up there, oh well, make a name for the playlist that the media player will use */
$badtags = array(" ");

$playlist = str_replace($badtags, "_", "$track");

$playlistname="playlists/".$playlist.".xml";

$somecontent = "<video url=\"$filename\" desc=\"$desc\" />";

/* Write the new entry to the playlist for the specified song */
if (is_writable($playlistname)) {

   if (!$handle2 = fopen($playlistname, 'a')) {
         echo "Cannot open file ($playlistname)";
         exit;
   }

   // Write $somecontent to our opened file.
   if (fwrite($handle2, $somecontent) === FALSE) {
       echo "Cannot write to file ($playlistname)";
       exit;
   }

   echo "Success, wrote ($somecontent) to file ($playlistname)";

   fclose($handle2);

} else {
   echo "The file $playlistname is not writable";
}







}

/* If the form hasnt been submited yet print it */
else{

print "
<tr class=\"content\"><td colspan=\"2\">
<h2>Submit Video</h2><br><br>

<form name=uploadvideo action=grab_video.php method=post>
<b>This may take several minutes depending on the video size and length. Only YouTube URLs are currently supported. Be sure to select the correct song from the drop down list.</b><br><br>
Video URL:<br>
<input type=text size=60 name=url class=input>
<SELECT NAME=\"track\" class=input>
";


$query = "SELECT * FROM media ORDER BY 'id' DESC";
$result=mysql_query($query);
$i=0;
$num=mysql_numrows($result);


while ($i < $num) {


$track=mysql_result($result,$i,"track");

print "<OPTION VALUE=\"$track\">$track";

$i++;
}

print "
</SELECT>
<br>Enter a brief description. E.G <i>Bumblefoot Solo</i><br><input type=text size=60 name=desc class=input>
<input type=submit class=input value='Submit Video' class=input><br><br>
</form>
Get the url from:<br>
<img src=images/youtube.jpg>
";
}

That means your host disabled that feature for you. You may be SOL unless you talk to your host.

 

You may want to review this, maybe there is an answer.

 

http://us2.php.net/manual/en/ref.info.php#ini.max-execution-time

 

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.