php -How to download video from download url - php

I've a download youtube scrip, after many changes I get to a point where I get a direct link to video, something like this :
http://r12---sn-4g57km7s.googlevideo.com/videoplayback?dur=265.868&pl=21&sver=3&mt=1444909527&ms=pm&source=youtube&sparams=dur,id,ip,ipbits,itag,lmt,mime,mm,mn,ms,mv,nh,pl,ratebypass,source,upn,expire&mv=s&itag=22&signature=A1D19A4DB1134E4ADF3CCBE8DDD7F5B01AB995B4.C0790F1AB331B4C290E83C292F064F67B811C17E&mm=35&mn=sn-4g57km7s&upn=qNbx8hdMDaU&nh=EAY&id=o-AAR67WMXg6mE9K6QpXf981YZf0B51_Jz_kEGYVHT9hdz&mime=video/mp4&expire=1444936669&ipbits=0&fexp=9408710,9414764,9414929,9416126,9417259,9417707,9418162,9418203,9418400,9418802,9418907,9418997,9421584,9421945,9422338,9422428,9422587,9422900&ratebypass=yes&ip=144.76.168.167&lmt=1444877662206720&key=yt6&signature=
when I enter the url in browser , it opens the video a plays it .
I tried this code but I get a file with the size of 0 as the result :
$download_video_file = file_put_contents("file", fopen($url, 'x'));
How can I download and save video from youtube and save it in my webhost ?
thanks

Download Videos from youtube is a complex issue...
Basically, youtube will generate a key when you access the video page, that key is only valid for the ip of the device accessing the page.
Check the url you've posted for a variable called ip , it has the value 144.76.168.167, this means that you'll only be able to download the video from that ip.
As I said, it's complex and you may want to take a look at https://rg3.github.io/youtube-dl/ . It's opensource video downloader that supports 700+ sites including youtube and it's updated frequently by a huge community.
youtube-dl
youtube-dl is a small command-line program to download videos from
YouTube.com and a few more sites. It requires the Python interpreter
(2.6, 2.7, or 3.2+), and it is not platform specific. We also provide
a Windows executable that includes Python. youtube-dl should work in
your Unix box, in Windows or in Mac OS X. It is released to the public
domain, which means you can modify it, redistribute it or use it
however you like.

Related

How to stream remote mp4 videos using apache and php

I have a laravel website on shared hosting and some videos on a cloud storage.
What do I need to hide direct links and stream videos on my website?
The videos are for sell and somebody might download them without paying. so every time that a user wants to see a video, I generate a random link and use it in video src. I generate random string and pass it to a function. The function finds video link and uses curl to get and play video (PHP stream remote video file) but it's not good enough. If it is possible to stream videos from another source, what do I need to do it right?
Do I need a streaming server? is apache good enough? what should I learn?

YouTube video upload through storage server url of the video

I need to upload a video to YouTube but without the video being on my web server. I have videos on a separate storage server, and the PHP is on a web server, I understand and got it working to upload a video to YouTube which is in my public web server folder.
It's simply as you only need to provide the location of the file, like $videoPath=sfConfig::get('sf_root_dir').'/web/tmp.mp4', however, going on with this code my web server would have to download the file from my storage server and then set the path of the video, but that would lead to too much bandwidth usage of my web server. What I'd like to do is something like $videoPath="http://storageserverurl.com/tmp.mp4" but that isn't possible.
Here is the piece of code that downloads the file to the web server and sends it to YouTube, it's working without problems.
file_put_contents("tmp.mp4", file_get_contents("http://storageserver.com/tmp.mp4"));
$videoPath=sfConfig::get('sf_root_dir').'/web/tmp.mp4';
I'd like it to be something like $videoPath="http://storageserver.com/tmp.mp4";
The rest of the code is the sample code given by Google. I'm using PHP 5.6.3 with symfony 1.4.

Can't detect 1080p and higher video url from Youtube

I am trying to make a Youtube video downloader by using this php script. I have got it from here.
https://github.com/jeckman/YouTube-Downloader
It works fine and shows direct link up to 720p resolution to download. But unable to detect URL over 720p even though 4k quality is available.
So if I want to make 1080p, 1440p, 2160p quality available what will I do.
Current script demo
http://loader.neq3.com/
You could utilize a command-line based youtube downloader, like youtube-dl. By default it will download 720p videos, but it seems that there is a new feature that allows for 1080p downloads as well! More information on downloading 1080p video with youtube-dl here.
To run commands from within PHP take a look at this stack post: Running shell commands in .php file from command-line
Let me know if you need any help!

Generate actual Youtube download link in PHP or Javascript

I have develop a media website to play video from Youtube by using jPlayer in PHP.
I have a problem with getting actual Youtube download link to make it play in my jPlayer.
Suppose that I have a Youtube link: https://www.youtube.com/watch?v=zpfNeFWA2vE and my actual download link is: http://o-o---preferred---hkg05s03---v12---nonxt5.c.youtube.com/videoplayback?upn=PnVtBEZ_KJw&sparams=cp%2Cgcr%2Cid%2Cip%2Cipbits%2Citag%2Cratebypass%2Csource%2Cupn%2Cexpire&fexp=919109%2C911646%2C920917%2C922401%2C920704%2C912806%2C913419%2C913558%2C913556%2C925109%2C912706&ms=nxu&expire=1348071130&itag=18&ipbits=8&gcr=kh&sver=3&ratebypass=yes&mt=1348046463&ip=119.15.90.10&mv=m&source=youtube&key=yt1&cp=U0hTTVBST19ISkNOM19ITFNCOmNBYVpWN2FtYXpn&id=ce97cd785580daf1&signature=74DF90D5D04F4DA2A2D588BDAFE777594673D2EE.64E845538B00C1FAA2E0AC043DAB5C512A49E45D&redirect_counter=1&cms_redirect=yes.
This actual url will expired on the next day.
Is there any method which I can paste only https://www.youtube.com/watch?v=zpfNeFWA2vE onto jPlayer or a script in either PHP or Javascript which can generate that actual link?
Note
I have download phptube from http://www.masnun.me/2011/05/17/phptube-a-php-class-to-get-download-links-from-youtube-watch-videos.html. It's working but when I download video from this generate link it said that "I don't have permission to download this file. 403 Forbidden"
Thank for helping!
Are you making sure that when you generate the youtube download links with phptube you are also accessing them from the server (and not from the client machine)? You are allowed to access these download links only from the same machine that was used to generate them (the author of phptube states that right at the beginning of the article).
A solution would be to generate these links from your server. Then use the server to download the contents to it. Then use the downloaded file to display it to the user. The problem is that your server will have to use double the bandwidth and the process will need time. YouTube just won't let you share the download links directly.
I had the exact same problem! Than I found this:
http://navarr.me/ytaudio/?q=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DtvS5MLzJfAw&s=on&psize=s&theme=dark
the source: https://github.com/navarr/ytaudio/
This script is also creating a download link like phptube. But I can acces the video from my local pc!

Embed Windows Media Player in PHP

Hi how do I go about embeding Windows Media Player in PHP ? what I want is when the user clicks the link a new window pops up to play the video in it's original size & when the user checks the page source he wont find the direct link to the video file, without using activex if possible.
PHP has nothing to do with Windows Media Player. At most it can generate the appropriate HTML to invoke a media player on the client's machine (via <object> and/or <embed> and/or <video>, but there's no guarantee it would be media player. You cannot force a particular player. What if they're on a Mac? Or a Unix machine? No WMP there...
At best you can obscure the address, but when push comes to shove, the address of the media file HAS to be sent to the client so their player can retrieve the data for playing.

Categories