From cd6683c2d81accd07962739b9835602e4c8d6b18 Mon Sep 17 00:00:00 2001 From: Shyam Sunder Date: Sun, 5 Apr 2020 14:58:58 -0400 Subject: [PATCH] server/posts/upload: make youtube-dl use best format Fixes #313 --- server/szurubooru/func/net.py | 13 +++++++------ server/szurubooru/tests/func/test_net.py | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/server/szurubooru/func/net.py b/server/szurubooru/func/net.py index 80a5de0..882e519 100644 --- a/server/szurubooru/func/net.py +++ b/server/szurubooru/func/net.py @@ -32,7 +32,7 @@ def _youtube_dl_wrapper(url: str) -> bytes: options = { 'quiet': True, 'ignoreerrors': False, - 'format': 'webm/mp4', + 'format': 'best[ext=webm]/best[ext=mp4]/best[ext=flv]', 'logger': logger, 'noplaylist': True, 'max_filesize': config.config['max_dl_filesize'], @@ -46,11 +46,12 @@ def _youtube_dl_wrapper(url: str) -> bytes: try: ydl_info = ydl.extract_info(url, download=True) # need to confirm if download was skipped due to size - if ydl_info['filesize'] > config.config['max_dl_filesize']: - raise errors.DownloadTooLargeError( - 'Requested video too large (%d MB > %d MB)' % ( - ydl_info['filesize'] / 1.0e6, - config.config['max_dl_filesize'] / 1.0e6)) + if 'filesize' in ydl_info: + if ydl_info['filesize'] > config.config['max_dl_filesize']: + raise errors.DownloadTooLargeError( + 'Requested video too large (%d MB > %d MB)' % ( + ydl_info['filesize'] / 1.0e6, + config.config['max_dl_filesize'] / 1.0e6)) ydl_filename = ydl.prepare_filename(ydl_info) except YoutubeDLError as ex: raise errors.ThirdPartyError( diff --git a/server/szurubooru/tests/func/test_net.py b/server/szurubooru/tests/func/test_net.py index a3b075d..64951e2 100644 --- a/server/szurubooru/tests/func/test_net.py +++ b/server/szurubooru/tests/func/test_net.py @@ -68,7 +68,7 @@ def test_too_large_download(): def test_video_download(): url = 'https://www.youtube.com/watch?v=C0DPdy98e4c' - expected_sha1 = '508f89ee85bc6186e18cfaa4f4d0279bcf2418ab' + expected_sha1 = '365af1c8f59c6865e1a84c6e13e3e25ff89e0ba1' actual_content = net.download(url, use_video_downloader=True) assert get_sha1(actual_content) == expected_sha1