server/posts/upload: make youtube-dl use best format

Fixes #313
This commit is contained in:
Shyam Sunder 2020-04-05 14:58:58 -04:00
parent 2c6434b08d
commit cd6683c2d8
2 changed files with 8 additions and 7 deletions

View file

@ -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(

View file

@ -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