Results 1 to 2 of 2
Threaded View
-
19th Nov 2011, 09:49 PM #1OP(╯?□?)╯︵ ┻━┻Website's:
Xenu.ws WarezLinkers.com SerialSurf.com CracksDirect.comGet a YouTube video URL in PHP
Quick piece of code that should, in theory, fetch the FLV/MP4/whatever URL of the video, given a youtube URL.
The example has a hard-coded url, turn it into a function to make it a parameter instead.
Also, it has absolutely no error checking, so you may wanna implement that (e.g. you should check if $r returns false and, if so, throw an error and die).
PHP Code:$c = curl_init();
curl_setopt($c, CURLOPT_URL, 'http://www.youtube.com/watch?v=sRLz4aDCAs0');
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_FAILONERROR, 1);
$r = curl_exec($c);
curl_close($c);
preg_match_all('#url_encoded_fmt_stream_map=([^&]+)#', $r, $fvars);
$fvars = explode('&', urldecode($fvars[1][0]));
$results = array();
$resultIndex = -1;
foreach($fvars as $item)
{
if(strpos($item, 'url=') !== false)
$resultIndex++;
if(!isset($results[$resultIndex]))
$results[$resultIndex] = array();
if(strpos($item, 'url=') === false)
{
$parse = explode('=', $item);
$results[$resultIndex][$parse[0]] = urldecode($parse[1]);
continue;
}
$parse = preg_match('#url=(.+)$#', $item, $url);
$results[$resultIndex]['url'] = urldecode($url[1]);
}
var_dump($results);
Code:array(5) { ["url"]=> string(419) "some_youtube_url" ["quality"]=> string(5) "small" ["fallback_host"]=> string(26) "tc.v4.cache5.c.youtube.com" ["type"]=> string(11) "video/x-flv" ["itag"]=> string(1) "5" }
JmZ Reviewed by JmZ on . Get a YouTube video URL in PHP Quick piece of code that should, in theory, fetch the FLV/MP4/whatever URL of the video, given a youtube URL. The example has a hard-coded url, turn it into a function to make it a parameter instead. Also, it has absolutely no error checking, so you may wanna implement that (e.g. you should check if $r returns false and, if so, throw an error and die). $c = curl_init(); curl_setopt($c, CURLOPT_URL, 'http://www.youtube.com/watch?v=sRLz4aDCAs0'); curl_setopt($c, Rating: 5Projects:
WCDDL - The Professional DDL Script
Top Secret Project: In Development - ZOMG
ImgTrack - Never Have Dead Images Again!
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
[Selling] Rank Your Video On No 1 Position Of Google & YouTube Now - [Video Ranking Domination]
By AcidH4X in forum ServicesReplies: 4Last Post: 17th Nov 2012, 04:54 AM -
How Do You Make a Video For YouTube?
By Ladybbird1 in forum Webmaster DiscussionReplies: 21Last Post: 10th Apr 2012, 02:04 PM -
youtube video download help
By Black Tiger in forum General DiscussionReplies: 1Last Post: 19th Jan 2012, 12:03 AM -
[Selling] YouTube Video Shoutout, On a "famous" YouTube Account [Great for Advertising Sites]
By Goob3r in forum Completed TransactionsReplies: 19Last Post: 29th Oct 2010, 06:38 AM -
[Selling] YouTube Video Views
By Goob3r in forum Completed TransactionsReplies: 53Last Post: 26th May 2010, 08:55 AM
themaPoster - post to forums and...
Version 5.23 released. Open older version (or...