1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[GET] Dailymotion Video Downloader (PHP)

Discussion in 'Social Networking Sites' started by HisInfernal, Aug 23, 2013.

  1. HisInfernal

    HisInfernal Registered Member

    Joined:
    Dec 4, 2012
    Messages:
    65
    Likes Received:
    10
    Occupation:
    System Administrator
    Location:
    Where red roses grow.
    I decide to share one script with BHW community.
    Its very simple Dailymotion video downloader.
    Save this code in .php file (ex. getDailymotion.php) and execute it by: php getDailymotion.php "VIDEOURL"

    Script will create directory called videos/ and place downloaded videos into it with random names.

    PHP:
    <?php
    if(empty($argv[1])){
        print 
    "======\nSyntax: ".$argv[0]." \"DAILYMOTIONURL\" \n======\n";die();
    }else{
    $tubePage=$argv[1];}


    $videosFolder="videos/";
    if (!
    file_exists($videosFolder)){mkdir($videosFolder0777true);}


    function 
    randomName($length=10) {
        return 
    substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0$length);
    }


    function 
    downloadFile($url$path) {  
        
    $newfname $path;
      
    $file fopen ($url"rb");
      if (
    $file) {
        
    $newf fopen ($newfname"wb");
            print 
    "\nDownloading video";
        if (
    $newf)
        while(!
    feof($file)) {
          
    fwrite($newffread($file1024 ), 1024 );
          print 
    ".";
        }
      }
      if (
    $file) {fclose($file);}
      if (
    $newf) {fclose($newf);}
    }


    function 
    getVideoUrl($url){
        global 
    $cookiejar;


        
    $userAgent "Mozilla/5.0 (X11; Linux i686; rv:18.0) Gecko/20100101 Firefox/18.0";
        
    $headers = array("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
                                                                                                                                        
    "Accept-Language: en-us,en;q=0.5");
        
    $ch curl_init();
        
    curl_setopt($chCURLOPT_FOLLOWLOCATIONTRUE);
        
    curl_setopt($chCURLOPT_URL$url);
        
    curl_setopt($chCURLOPT_USERAGENT$userAgent);
        
    curl_setopt($chCURLOPT_PORT 80);
        
    curl_setopt($chCURLOPT_HTTPHEADER$headers);
        
    curl_setopt($chCURLOPT_COOKIEFILE$cookiejar);
        
    curl_setopt($chCURLOPT_COOKIEJAR$cookiejar);
        
    curl_setopt($chCURLOPT_COOKIE'family_filter=off;');
        
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
        
    $output curl_exec($ch);
        
    curl_close($ch);
        
    preg_match("/name=\"flashvars\"\svalue=\"(.*?)\"/i",$output,$flashvars);
        if(isset(
    $flashvars[1])){
            
    $flashvars=urldecode($flashvars[1]);
            
    preg_match("/\"video_url\":\"(.*?)\"/i",$flashvars,$flvUrl);
            if(empty(
    $flvUrl[1])){
                
    preg_match("/\"sdURL\":\"(.*?)\"/i",$flashvars,$flvUrl);
            }
        }
        if(isset(
    $flvUrl[1])){
            return 
    urldecode($flvUrl[1]);
        }else{
            return 
    false;
        }
    }


    if(
    $flvUrl=getVideoUrl($tubePage)){
      
    $flvUrl=str_replace("\/","/",$flvUrl);
      
    $flvFilename=randomName();
      
    downloadFile($flvUrl,$videosFolder.$flvFilename.".mp4");
    }else{echo 
    "Unable to get video from Dailymotion.";}
    ?>
     
    • Thanks Thanks x 1
  2. x007x

    x007x Newbie

    Joined:
    Sep 6, 2013
    Messages:
    3
    Likes Received:
    0
    Can you give my help on how to use it on my remote server ?
    I upload the php file by ftp and ???

    Thanks
     
  3. x007x

    x007x Newbie

    Joined:
    Sep 6, 2013
    Messages:
    3
    Likes Received:
    0
    I found a way to add a parameter via HTTP_GET_VARS.


    Thanks anyway :eek:)
     
  4. x007x

    x007x Newbie

    Joined:
    Sep 6, 2013
    Messages:
    3
    Likes Received:
    0
    Do you have a method to get the best quality possible of the video ?
    Because your script only download the lowest quality.....

    Thanks for helping me in advance.
     
  5. inposphp

    inposphp Newbie

    Joined:
    Nov 27, 2013
    Messages:
    1
    Likes Received:
    0
    Hi the below code is not working for me, I dont know where should we pass dailymotion url. Can anyone please help me with the below code

    PHP:
    <?php
    if(empty($argv[1])){
        print 
    "======\nSyntax: ".$argv[0]." \"DAILYMOTIONURL\" \n======\n";die();
    }else{
    $tubePage=$argv[1];}


    $videosFolder="videos/";
    if (!
    file_exists($videosFolder)){mkdir($videosFolder0777true);}


    function 
    randomName($length=10) {
        return 
    substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0$length);
    }


    function 
    downloadFile($url$path) {  
        
    $newfname $path;
      
    $file fopen ($url"rb");
      if (
    $file) {
        
    $newf fopen ($newfname"wb");
            print 
    "\nDownloading video";
        if (
    $newf)
        while(!
    feof($file)) {
          
    fwrite($newffread($file1024 ), 1024 );
          print 
    ".";
        }
      }
      if (
    $file) {fclose($file);}
      if (
    $newf) {fclose($newf);}
    }


    function 
    getVideoUrl($url){
        global 
    $cookiejar;


        
    $userAgent "Mozilla/5.0 (X11; Linux i686; rv:18.0) Gecko/20100101 Firefox/18.0";
        
    $headers = array("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
                                                                                                                                        
    "Accept-Language: en-us,en;q=0.5");
        
    $ch curl_init();
        
    curl_setopt($chCURLOPT_FOLLOWLOCATIONTRUE);
        
    curl_setopt($chCURLOPT_URL$url);
        
    curl_setopt($chCURLOPT_USERAGENT$userAgent);
        
    curl_setopt($chCURLOPT_PORT 80);
        
    curl_setopt($chCURLOPT_HTTPHEADER$headers);
        
    curl_setopt($chCURLOPT_COOKIEFILE$cookiejar);
        
    curl_setopt($chCURLOPT_COOKIEJAR$cookiejar);
        
    curl_setopt($chCURLOPT_COOKIE'family_filter=off;');
        
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
        
    $output curl_exec($ch);
        
    curl_close($ch);
        
    preg_match("/name=\"flashvars\"\svalue=\"(.*?)\"/i",$output,$flashvars);
        if(isset(
    $flashvars[1])){
            
    $flashvars=urldecode($flashvars[1]);
            
    preg_match("/\"video_url\":\"(.*?)\"/i",$flashvars,$flvUrl);
            if(empty(
    $flvUrl[1])){
                
    preg_match("/\"sdURL\":\"(.*?)\"/i",$flashvars,$flvUrl);
            }
        }
        if(isset(
    $flvUrl[1])){
            return 
    urldecode($flvUrl[1]);
        }else{
            return 
    false;
        }
    }


    if(
    $flvUrl=getVideoUrl($tubePage)){
      
    $flvUrl=str_replace("\/","/",$flvUrl);
      
    $flvFilename=randomName();
      
    downloadFile($flvUrl,$videosFolder.$flvFilename.".mp4");
    }else{echo 
    "Unable to get video from Dailymotion.";}
    ?>
    [/QUOTE]