Reputation: 313
I get youtube video download link from youtube-dl.
When I download it from any browser it downloads in 5 seconds but when I try to download it from python, the link downloads in 1 minute. I tried same size in different networks but I got same result.
For Python I use this:
import urllib
urllib.urlretrieve(url,"file.m4a")
I don't know google expects me any header or something else to make download faster.
Upvotes: 3
Views: 21451
Reputation: 12798
I suspect your browser has the file cached, or is using a proxy which caches the file. I tried downloading a file from youtube and got a similar duration in three different ways.
# Note this is how to get the youtube url: `youtube-dl -f 22 -g https://www.youtube.com/watch?v=qxlVTsFbyKs`
url = 'https://r3---sn-tt1e7n7e.googlevideo.com/videoplayback?id=o-APMpsV_ubZwYnre71FtKIY7rTKTd1HmAGqjFS7D_W9vO&itag=22&source=youtube&requiressl=yes&mm=31%2C29&mn=sn-tt1e7n7e%2Csn-tt1eln7s&ms=au%2Crdu&mv=m&pl=25&ei=g-LdXNT1H-ODir4P0Jeb0Ag&initcwndbps=2695000&mime=video%2Fmp4&ratebypass=yes&dur=91.649&lmt=1556128078557211&mt=1558045252&fvip=3&c=WEB&txp=2216222&ip=184.75.215.122&ipbits=0&expire=1558066915&sparams=ip%2Cipbits%2Cexpire%2Cid%2Citag%2Csource%2Crequiressl%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Cei%2Cinitcwndbps%2Cmime%2Cratebypass%2Cdur%2Clmt&signature=481807C3CAD81BC6CFA6E4131D5E734BC2CB63FC.2EBF166C597725BC02E9EE28227B9A9C815E224C&key=yt8'
# 60 seconds
import urllib.request
urllib.request.urlretrieve(url,"file.mp4")
# 50 seconds
import urllib.request
data = urllib.request.urlopen(url).read()
open('out.mp4', 'wb').write(data)
# 50 seconds
import subprocess
subprocess.check_call(["curl", "-L", url, "--output", "out4.mp4"])
To disable your caches on the browser, e.g. chrome, you can try Disabling Chrome cache for website development
Upvotes: 1