eyecatchup / php-yt_downloader

PHP Class to download videos from YouTube.
http://eyecatchup.github.com/php-yt_downloader/
293 stars 166 forks source link

Don't save file on server #1

Closed nathanp closed 12 years ago

nathanp commented 12 years ago

Any way to just offer a download link to the user instead of saving the video on my server first? Seems like an unnecessary step, plus can get pretty bandwidth-heavy. This is a great script! just think this suggestion will make it better :)

eyecatchup commented 12 years ago

For Audio downloads this is a necessary step. For video downloads you can easily modify the download_video() function to return an array of download links by returning the $vids variable here: https://github.com/eyecatchup/php-yt_downloader/blob/master/youtube-dl.class.php#L235

nathanp commented 12 years ago

thanks for the help! I'm having some issues with it though. right now I'm getting the keys/values of the $vids array by using:

foreach($vids as $array){    
                    foreach($array as $key=>$value){
                        echo 'Key: '.$key.'<br />';
                        echo 'Value: '.$value.'<br />';
                        echo '<br />';
                    }
                }

but the URL keys are returning values like this:

http://o-o---preferred---ord12s18---v11---lscache2.c.youtube.com/videoplayback?upn=KsAfUH2A0xs&sparams=cp%2Cid%2Cip%2Cipbits%2Citag%2Cratebypass%2Csource%2Cupn%2Cexpire&fexp=909710%2C911304%2C915507%2C907217%2C907335%2C921602%2C922600%2C919804%2C920704%2C924500%2C906831%2C924700%2C913547%2C920706%2C924402%2C907344%2C912706%2C902518&ms=au&itag=22&ipbits=8&signature=4E6FF53012632B5708D160950213F8A117D5812D.47CA4D9C1561F298E895B96CA2C98DF453682AC6&mv=m&sver=3&mt=1343108776&ratebypass=yes&source=youtube&expire=1343130794&key=yt1&ip=74.208.16.154&cp=U0hTSFFOTl9OTkNOM19JSFJIOjhzY19ZOGh3M2tB&id=d1b8c17f80716841&newshard=yes

any tips?

eyecatchup commented 12 years ago

These are the correct URLs - they just look like this. So you probably didn't tried them, he? ;-) Anyway, just use these links to download the files. Note: they are serverd without a content-type header! Thus, you have to add that manually when downloading via browser. To know which mime type the vid is, see ext and type key values. Also, your code doesn't make sense to me.. Why would you want to iterate through the vids array? Do you want to download a video in each quality it's available? Here's a simplified example

file_put_contents('nameOfVideo.' . $vids[0]['ext'], $vids[0]['url']); That's all you need..

PS: Please note this is not a user support forum, but rather an issue tracker!

Update: Just forgot you don't want to save them on the server.. So I guess you try to provide a "user service", correct? 1) Don't do it. 2) if this is what you want to do (providing alink to any user) you must, as I said, add the content type. You might find it useful to take a look at my forced download script here: https://github.com/eyecatchup/php-yt_downloader/blob/gh-pages/download.php