Last active
June 1, 2019 04:07
-
-
Save dasl-/870034616f805485580f71476bb7e324 to your computer and use it in GitHub Desktop.
youtube-dl downloads videos way faster than pafy.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# results of a typical test: | |
# ytdl downloaded in 5.32s at 3.77 MB/s | |
# pafy downloaded in 786.6s at 0.03 MB/s | |
import pafy | |
import time | |
import youtube_dl | |
import sys | |
import glob | |
import os | |
def test_ytdl(url): | |
ydl_opts = { | |
'format': 'worstvideo[ext=webm]/worst[ext=webm]/worst', | |
'outtmpl': 'youtube-dl__%(title)s-%(id)s.%(ext)s' | |
} | |
start = time.time() | |
with youtube_dl.YoutubeDL(ydl_opts) as ydl: | |
ydl.download([url]) | |
dl_time = time.time() - start | |
paths = glob.glob(sys.path[0] + "/youtube-dl__*") | |
dl_rate = os.path.getsize(paths[0]) / 1024 / 1024 / dl_time | |
print("ytdl downloaded: " + str(paths[0])) | |
print("ytdl downloaded in " + str(round(dl_time, 2)) + "s at " + str(round(dl_rate,2)) + " MB/s") | |
def test_pafy(url): | |
p = pafy.new(url) | |
for stream in p.videostreams: | |
if str(stream) == "video:webm@256x144": | |
size = stream.get_filesize() | |
start = time.time() | |
stream.download(filepath="pafy__" + stream.title + "." + stream.extension) | |
dl_time = time.time() - start | |
dl_rate = size / 1024 / 1024 / dl_time | |
print(".") | |
print("pafy downloaded in " + str(round(dl_time, 2)) + "s at " + str(round(dl_rate,2)) + " MB/s") | |
print(".") | |
url = "https://www.youtube.com/watch?v=Yq7Eh6JTKIg" | |
test_ytdl(url) | |
test_pafy(url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment