Activity Stream
48,167 MEMBERS
6793 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 2 of 2
  1.     
    #1
    (╯?□?)╯︵ ┻━┻
    Website's:
    Xenu.ws WarezLinkers.com SerialSurf.com CracksDirect.com

    Default 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).

    PHP Code: 
    $c curl_init();
    curl_setopt($cCURLOPT_URL'http://www.youtube.com/watch?v=sRLz4aDCAs0');
    curl_setopt($cCURLOPT_RETURNTRANSFER1);
    curl_setopt($cCURLOPT_FAILONERROR1);
    $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); 
    This results in an array containing arrays like so:

    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"
      }
    Just an example anyway, there may be an easier way to do it but this seemed logical at the time.
    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: 5
    Projects:
    WCDDL - The Professional DDL Script
    Top Secret Project: In Development - ZOMG
    ImgTrack - Never Have Dead Images Again!

  2.   Sponsored Links

  3.     
    #2
    Member
    Website's:
    tehMoviez.com 0Senes.com GeekFaceGames.com
    i like it, pretty simple yet very useful

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 4
    Last Post: 17th Nov 2012, 04:54 AM
  2. How Do You Make a Video For YouTube?
    By Ladybbird1 in forum Webmaster Discussion
    Replies: 21
    Last Post: 10th Apr 2012, 02:04 PM
  3. youtube video download help
    By Black Tiger in forum General Discussion
    Replies: 1
    Last Post: 19th Jan 2012, 12:03 AM
  4. Replies: 19
    Last Post: 29th Oct 2010, 06:38 AM
  5. [Selling] YouTube Video Views
    By Goob3r in forum Completed Transactions
    Replies: 53
    Last Post: 26th May 2010, 08:55 AM

Tags for this Thread

BE SOCIAL