-
PHP help needed!
I'm kind of in a pickle at the moment! I have a PHP script here which converts an inputted YouTube URL into an MP4, although after it's converted it into the MP4, I would like it to finally convert into a tinyurl. I've tried but I really don't understand how I could do so, so if anyone could lend a hand, then I'd definitely be grateful!
+rep to any help!
PHP Code:
<?php
$youtube = $_GET['web'];
function getstring($string)
{
$pos = strrpos($string, "swfArgs")+11;
$texto = substr($string,$pos,strrpos(substr($string,$pos,strlen($string)), "additionalStatsHonorsUrl")-10);
$replace = array(" ",'"',"_");
$adata = split(",",str_replace($replace,"",$texto));
$vid_id = split(":",$adata[2]);
$lang = split(":",$adata[7]);
$code = split(":",$adata[6]);
$vidn1 = strrpos($string, "<title>")+7;
$vidn2 = strrpos(substr($string,$vidn1,-1), "</title>");
$vidname = substr($string,$vidn1,$vidn2);
$web = 'http://www.youtube.com/get_video?video_id='.$vid_id[1].'&hl='.$lang[1].'&t='.$code[1].'&fmt=18';
echo $web.'|'.$vidname;
}
function getPage($opts) {
$ch = curl_init($opts);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.12) Gecko/20070508 Firefox/1.5.0.12");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$html = curl_exec($ch);
if(curl_errno($ch)) {
$html = "";
}
curl_close ($ch);
return getstring($html);
}
getPage($youtube);
?>
PHP Code:
$web = 'http://www.youtube.com/get_video?video_id='.$vid_id[1].'&hl='.$lang[1].'&t='.$code[1].'&fmt=18';
echo $web.'|'.$vidname;
is the conversion that takes place, after this has happened, the tinyurl conversion needs to take place.
-
Google made this easy:
PHP Code:
<?php
function createTinyUrl($strURL) {
$tinyurl = file_get_contents("http://tinyurl.com/api-create.php?url=".$strURL);
return $tinyurl;
}
?>
PHP Code:
<?php
echo(createTinyUrl('http://www.richardcastera.com/2009/05/09/creating-a-tinyurl-with-tinyurl-api/'));
?>
-
Quote:
Originally Posted by
Chippiewill
Google made this easy:
PHP Code:
<?php
function createTinyUrl($strURL) {
$tinyurl = file_get_contents("http://tinyurl.com/api-create.php?url=".$strURL);
return $tinyurl;
}
?>
PHP Code:
<?php
echo(createTinyUrl('http://www.richardcastera.com/2009/05/09/creating-a-tinyurl-with-tinyurl-api/'));
?>
I've tried this already but if I honestly don't know how to make the URL convert to a tinyURL AFTER converting to the MP4.
-
Code:
<?php
echo createTinyUrl(getPage($youtube));
?>
-
Can I ask what you're using to convert the video once you've downloaded it? FFMPEG? Looked into making one of these scripts a while ago.
-
I really don't think he is converting it... I think he is just converting a standard URL / HTML into the MP4 download link for the given video... that's what I see in the code..
-
Ah yeah, for some reason I read MP4 as MP3. My mistake :P
-
Haha, no problem. I thought you were thinking converting from what.. FLV isn't it? to MP4?
-
You input a standard YouTube link and it gives you the MP4 link (FLV without &fmt=18).
Thanks for the help btw, +rep given! :)