Youtube video uploaded successfully on local, but on server (online) only 0 byte flv is uploaded

I am using php tube class to download youtube videos. The video is automatically uploaded to the folder by submitting the YouTube URL.

everything works fine on local (XAMPP) but when I upload it to the server (online) ONLY ONLY 0 byte flv file is saved.

I am also debugging code both sides (local and global).

I am getting url like this (on local )

http://www.youtube.com/get_video?video_id=1jNWCFwqPvM&=vjVQa1PpcFMyYCECyfmYENWklpwXGyhVgJpSFPgNAEc%3D

whereas on the server I got a link like this

http://www.youtube.com/ get_video?video_id=1jNWCFwqPvM&t=vjVQa1PpcFNS3SPxIXi8hy-NF4qZFFrScDXCjGLLrLc%3D

when I copy the link from local and paste it into the browser then the download window appears in the browser, while when I copy the link from the server and paste in the browser only a blank page appears.

  • please solve my problem, where is the error?
  • How to know if a pear is installed or not on the server?
  • on the server side sometimes I get a link like

    http://www.youtube.com/get_video?video_id=1jNWCFwqPvM&t=vjVQa1PpcFNS3SPxIXi8hy-NF4qZFFrScDXCjGLLrLc%3D

but sometimes i only get

http://www.youtube.com/get_video?video_id=&t=

How to solve them?

UPDATE:

I am debugging all the code and found that it file_get_contents()

returns string (0) on the server, whereas on local it returns some integer value. allow_url_fopen

- onmy server

this is index.php

include_once('functions.php');  
$url =  $_POST['url']; // here is url of youtube video
$pattern = getPatternFromUrl($url); 
$flv_path = GrabFlvFromYoutube($pattern );
echo "File Successfully Downloaded at:".$flv_path."<br/>";

      


these functions are in functions.php

function getPatternFromUrl($url)
{
$url = $url.'&';
$pattern = '/v=(.+?)&+/';
preg_match($pattern, $url, $matches);
//echo $matches[1]; die;
return ($matches[1]);
}

      

and

function GrabFlvFromYoutube( $pattern )
{
require_once ("phptube.php");
$tube = new PHPTube ();
$flv_http_path = $tube->download($pattern) ;
    echo "<br/>Complete URL:".$flv_http_path;
set_time_limit(0);

$data = file_get_contents($flv_http_path);  
//var_dump(file_get_contents($flv_http_path));  
$new_flv_path = dirname(_FILE_).'/flvs/'.$pattern.'-'.time().'.flv' ;

echo "<br />File uploaed:";
    file_put_contents($new_flv_path, $data);    

return $new_flv_path ;
}

      


below function in phptube.php

class PHPTube {

var $cookies;
var $mgr;
var $req; 
var $debug = true;
var $auth = false;

function PHPTube () {}
    function download ($video_id) {

    $url = "http://www.youtube.com/watch?v=".$video_id;     
$this->req =& new HTTP_Request($url);
$response = $this->req->sendRequest();
if (PEAR::isError($response)) {
    $response->getMessage()."\n";
} else {    
        $page = $this->req->getResponseBody();  
    $vpattern = '/v=(.*?)&/';
    //$vpattern ='/video_id:(.*?)/';
    preg_match($vpattern,$page,$mv);
    //preg_match('&"video_id": "(.*?)"&', $page, $mv); 
    echo "<br />Video ID:".$v_id = $mv[1]; 
    //$tpattern='/"t": "(.*?)"/';
    $tpattern = '/&t=(.*?)&/';
    preg_match($tpattern,$page,$tickets);
    echo "<br />Token ID:".$token = $tickets[1];
    $curl = "video_id=";
    $curl .= $v_id;
    $curl .= "&t=";         
    $curl.= $token;
    //echo "<br />Query String:".$curl; die;
    $url = "http://www.youtube.com/get_video?".$curl;  
    if ($this->debug)
     return $url;
     }
   }
 }  

      

+2


source to share


3 answers


To download / copy youtube video to your server, you can do it via SSH.

1) Download the latest youtube-dl script (here: http://rg3.github.io/youtube-dl/ Save it as youtube-dl.py

and download this wherever you want on your server.

2) To download the video, login to your server via ssh (using putty or whatever), go to the directory where you saved the youtube-dl script file, and download the video by entering a command like:

code:



python youtube-dl.py -o youroutputfile.mp4 http://www.youtubevideourl.com/

      

where the filename you give after the part -o

is the filename you want to save the video as and the youtubevideourl part will look like http://www.youtube.com/watch?v=_DHEK9xJXvs i.e. the actual URL of the Youtube video page. The script will display the youtube page, extract the video location and save the video. If it stops working, it means that Youtube has changed the formatting of its page and you need to download a new version of youtube-dl from the site.

This is a great script because since it is run from the command line it is very easy to include it in your own batch upload scripts.

+2


source


Have you even tried the user agent idea I mentioned in your last question? I'll paste it here again if you haven't.

ini_set('user_agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9');

      

And you are going to embed this at the beginning of your script file. You can also change this in the php.ini file in the settings user_agent

.



The only thing I can imagine that your server and local machine will be different from each other is that the server identifies itself differently.

Another thing is that YouTube can block your server / web host from requesting videos. If you are on a shared host and someone has tried this before, Google could hack it and blacken your host's IP address. Downloading FLV from YouTube is against the terms of service, so they may well do it.

Hope it helps (again).

+1


source


I think it has something to do with the ip of the machine that is trying to parse the source code or grab a link. On the local machine, since you are pulling the page, the link will have your ip in ip param, if it is executed on the remote server, then the server ip will be in the ip parameter, and you will try to load from your computer where the ips do not match.

I also run into a similar situation where this is fine on my dev machine, but as soon as I put it live it all went to the bank. I am trying to figure out how to make it work, atm is the easiest / only thing I can think of doing on the client with javascript.

EDIT:

My idea of ​​requesting a youtube page with ajax on the client won't work like you can't request from another domain.

The only way I can get it to work is to let the server get the download link which will be valid for the server ip, then the proxy download the file using readfile()

and some header()

for the client. The big problem is that you will be completely splitting streaming streaming downloads to users.

I would like to know if anyone has any better ideas?

0


source







All Articles