PHP Classes

PHP Video Downloader Script: Discover and download a video using its page URL

Recommend this page to a friend!
  Info   View files Example   View files View files (22)   DownloadInstall with Composer Download .zip   Reputation   Support forum (2)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 279 This week: 1All time: 7,616 This week: 560Up
Version License PHP version Categories
the-downloader 1.0.0The PHP License5PHP 5, Files and Folders, Video
Description 

Author

This package can discover and download a video using its page URL.

It can take the URL of a video page on different well known sites that host videos and returns a class for parsing the given page and extract several details about the video like whether it is a page of a video, a playlist, a channel, video length, title, etc..

Currently the package supports videos sites like Ajanshaber, Dailymotion, Facebook, Haberay, Izlesene, Mynet, Translate, Webtv and YouTube.

Picture of Kemal GENIS
  Performance   Level  
Name: Kemal GENIS <contact>
Classes: 7 packages by
Country: Turkey Turkey
Age: 40
All time rank: 234140 in Turkey Turkey
Week rank: 411 Up9 in Turkey Turkey Up

Example

<?php
include_once "init.php";
include_once
"templates/form.html";

if(!isset(
$url) and isset($argv[1])){
   
$url = $argv[1];
}

if(!isset(
$url) and isset($_REQUEST['url'])){
   
$url = $_REQUEST['url'];
}

if(!isset(
$url) and isset($_REQUEST['video_url'])){
   
$url = $_REQUEST['video_url'];
}

if(isset(
$_REQUEST['video_cat'])){
   
$videoCategory = $_REQUEST['video_cat'];
}
else{
   
$videoCategory = '';
}

if(
$url != '' and $db->numRowsCount("SELECT * FROM orjinal_videos WHERE orjinal_url='" . $url . "'") == 0){
   
//writeFile('./downloadFileList.txt', $url);
   
$parser = detectDownloader($url);

    echo
"<h2>".strtoupper($parser)."</h2>\n";

    if(
file_exists("classes/$parser.class.php")){
        include_once
"classes/$parser.class.php";
    }

   
$video = new video($url);
    if(
$parser == 'youtube' and $video->isPlaylist()){
       
$playlist = $video->getPlaylistVideoId(true);
        foreach(
$playlist as $vidId){
           
$videox = new video("https://www.youtube.com/watch?v=".$vidId);
           
$vidData = $videox->getVideoInfo();
            echo
"<div style='margin-bottom: 20px;'>
                        <a href='https://www.youtube.com/watch?v="
.$vidId."' target='_blank' style='float:left;'>
                            <img src='http://i1.ytimg.com/vi/"
. $vidId . "/hqdefault.jpg' style='height:120px; width:160px;' border:1px solid #333; />
                        </a>
                        <div style='height:120px; float:left;'>
                            <span style='padding:10px;'>"
.$vidData['title']."</span><br>
                            <a href='?exit&video_cat="
.$videoCategory."&video_url=https://www.youtube.com/watch?v=".$vidId."' target='_blank' style='padding:10px; line-height:50px;'>Yükle</a>
                        </div>
                        <div style='clear:both;'></div>
                    </div>\n"
;
            unset(
$videox);
        }
        exit;
    }
    else if(
$parser == 'youtube' and $video->isChannel()){
       
$channellist = $video->getChannelVideoId(true);
        foreach(
$channellist as $vidId){
           
$videox = new video("https://www.youtube.com/watch?v=".$vidId);
           
$vidData = $videox->getVideoInfo();
            echo
"<div style='margin-bottom: 20px;'>
                        <a href='https://www.youtube.com/watch?v="
.$vidId."' target='_blank' style='float:left;'>
                            <img src='http://i1.ytimg.com/vi/"
. $vidId . "/hqdefault.jpg' style='height:120px; width:160px;' border:1px solid #333; />
                        </a>
                        <div style='height:120px; float:left;'>
                            <span style='padding:10px;'>"
.$vidData['title']."</span><br>
                            <a href='?exit&video_cat="
.$videoCategory."&video_url=https://www.youtube.com/watch?v=".$vidId."' target='_blank' style='padding:10px; line-height:50px;'>Yükle</a>
                        </div>
                        <div style='clear:both;'></div>
                    </div>\n"
;
            unset(
$videox);
        }
        exit;
    }
   
$data = $video->getResult();

    if(
$db->numRowsCount("SELECT * FROM videos WHERE title='".$db->clean($data['title'])."'") > 0){
        die(
'Bu isimde bir video zaten yüklenmi?.');
    }

    if(
$parser == 'youtube' and $data['length'] > 1000){
       
$data['video_url'] = '';
    }

    if(
urlExists($data['video_url'])){
       
$downloadCounter = DOWNLOAD_COUNTER;
       
$downloadStatus = false;
        while(
$downloadCounter){
            if(
$video->download()){
                echo
"Dosya indirildi. OK <br>\n";
                echo
"Dosya : " . DOWNLOAD_DIR . $data['video_file_name'] . " (" . byteCalc(filesize(DOWNLOAD_DIR . $data['video_file_name'])) . ")<br>\n";
               
$downloadCounter = 0;
               
$downloadStatus = true;
            }
            else{
               
$downloadCounter--;
               
sleep(1);
            }
        }
    }

    if(
$downloadStatus){
        try{
            require
"includes/sdk/Dailymotion.php";

           
$api = new Dailymotion();

           
$api->setGrantType(
               
Dailymotion::GRANT_TYPE_PASSWORD,
               
DAILY_KEY,
               
DAILY_SECRET,
                array(
'read', 'write', 'manage_videos'),
                array(
'username' => DAILY_USERNAME, 'password' => DAILY_PASSWORD)
            );


           
/*
            //-> Generate tags
            $convertToLang = array('tr', 'en', 'fr');
            $currentLangDesc = langDetect($data['description']);
            $convText = array();
            foreach($convertToLang as $lngx){
                if($currentLangTitle != $lngx){
                    $convText['title'][] = yandexCeviri($data['title'], $currentLangTitle, $lngx);
                }
            }
            foreach($convertToLang as $lngx){
                if($currentLangDesc != $lngx){
                    $convText['desc'][] = yandexCeviri($data['title'], $currentLangDesc, $lngx);
                }
            }
*/
           
$currentLangTitle = langDetect($data['title']);

           
$vvii = realpath(DOWNLOAD_DIR . $data['video_file_name']);
           
$urlx = $api->uploadFile($vvii);

           
$videoPostData = array(
               
'url' => $urlx,
               
'title' => $data['title'],
               
'tags' => genVideoTag(genTranslateContent($data['title'], " ")),
               
'description'=> genTranslateContent($data['description']),
               
'channel' => ($videoCategory!=''?$videoCategory:'webcam'),
               
'language' => $currentLangTitle==false?'tr':$currentLangTitle,
               
'published' => true,
            );
           
$resultx = $api->post('/me/videos', $videoPostData);

            if(!
$resultx){
                throw new
Exception("<pre>".var_export($resultx, true)."</pre>");
            }

            if(isset(
$resultx['id']) and $resultx['id'] != ''){
                echo
"<h5>".$resultx['title']."</h5>";
                echo
"<pre>".var_export($videoPostData, true)."</pre>\n";
                echo
'<h4 style="color:green;">YÜKLEME BA?ARILI! :)</h4>';

               
$db->query("INSERT INTO orjinal_videos (orjinal_url, video_file, image_url, title, content, status, dailymotion_id, indate) VALUES ('".$url."', '".$data['video_file_name']."', '".$data['picture_url']."', '".$db->clean($data['title'])."', '".$db->clean($data['description'])."', '1', '".$resultx['id']."', '".time()."')");
               
$lastInsertId = $db->insertId();

               
$insertVideosSql = "INSERT INTO videos (dailymotion_id, title, descr, tags, lang, orj_id, indate, dailymotion_channel, duration) VALUES ('".$resultx['id']."', '".$db->clean($videoPostData['title'])."', '".$db->clean($videoPostData['description'])."', '".$db->clean($videoPostData['tags'])."', '".$videoPostData['language']."', '".$lastInsertId."','".time()."', '".DAILY_USERNAME."', '".(isset($data['length'])?$data['length']:'0')."')";
               
//echo $insertVideosSql;
               
$db->query($insertVideosSql);
            }
            else{
                echo
'<h4 style="color:red;">V?DEO YÜKLENEMED?. :(</h4>';
            }

            if(
file_exists(DOWNLOAD_DIR . $data['video_file_name'])){
               
sleep(3);
               
unlink(DOWNLOAD_DIR . $data['video_file_name']);
            }
        }catch(
Exception $e) {
            echo
$e->getMessage();
        }
    }
    else{
        echo
"<h4 style=\"color:red;\">Dosya indirilemedi. ERROR</h4> <br>\n";
    }

    if(isset(
$_REQUEST['exit'])){
        echo
"<script>setTimeout(function(){ window.close(); }, 15000);</script>";
    }
}



  Files folder image Files  
File Role Description
Files folder imageclasses (11 files)
Files folder imagefiles (1 file)
Files folder imageincludes (3 files, 1 directory)
Files folder imagetemplates (1 file)
Accessible without login Plain text file index.php Example Example script
Accessible without login Plain text file init.php Aux. Auxiliary script
Accessible without login Plain text file trend_cron.php Example Example script
Accessible without login Plain text file updater.php Example Example script

  Files folder image Files  /  classes  
File Role Description
  Plain text file ajanshaber.class.php Class Class source
  Plain text file dailymotion.class.php Class Class source
  Plain text file dbMysql.class.php Class Class source
  Plain text file dbSqlite.class.php Class Class source
  Plain text file facebook.class.php Class Class source
  Plain text file haberay.class.php Class Class source
  Plain text file izlesene.class.php Class Class source
  Plain text file mynet.class.php Class Class source
  Plain text file translate.class.php Class Class source
  Plain text file webtv.class.php Class Class source
  Plain text file youtube.class.php Class Class source

  Files folder image Files  /  files  
File Role Description
  Accessible without login HTML file index.html Doc. Documentation

  Files folder image Files  /  includes  
File Role Description
Files folder imagesdk (2 files)
  Accessible without login Plain text file api_conf.inc Data Auxiliary data
  Accessible without login Plain text file conf.inc Data Auxiliary data
  Accessible without login Plain text file func.inc Example Example script

  Files folder image Files  /  includes  /  sdk  
File Role Description
  Plain text file Dailymotion.php Class Class source
  Accessible without login Plain text file dm_ca_chain_bundle.crt Data Auxiliary data

  Files folder image Files  /  templates  
File Role Description
  Accessible without login HTML file form.html Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
 100%
Total:279
This week:1
All time:7,616
This week:560Up
User Comments (1)
Nothing telling how the script works.
5 years ago (Terry Woody)
35%StarStar