mirror of
https://github.com/mxpv/podsync.git
synced 2024-05-11 05:55:04 +00:00
Fix resolver for vimeo, choose video quality
This commit is contained in:
@@ -12,3 +12,6 @@ class TestYtdl(unittest.TestCase):
|
||||
def test_vimeo(self):
|
||||
self.assertIsNotNone(
|
||||
ytdl._resolve('https://vimeo.com/237715420', {'format': 'video', 'quality': 'low', 'provider': 'vimeo'}))
|
||||
self.assertIsNotNone(
|
||||
ytdl._resolve('https://vimeo.com/275211960', {'format': 'video', 'quality': 'high', 'provider': 'vimeo' })
|
||||
)
|
||||
|
||||
@@ -67,9 +67,9 @@ def _resolve(url, metadata):
|
||||
with youtube_dl.YoutubeDL(opts) as ytdl:
|
||||
info = ytdl.extract_info(url, download=False)
|
||||
if provider == 'youtube':
|
||||
return _choose_url(info, metadata)
|
||||
return _yt_choose_url(info, metadata)
|
||||
elif provider == 'vimeo':
|
||||
return info['url']
|
||||
return _vimeo_choose_url(info, metadata)
|
||||
else:
|
||||
raise ValueError('undefined provider')
|
||||
except DownloadError:
|
||||
@@ -79,7 +79,7 @@ def _resolve(url, metadata):
|
||||
raise
|
||||
|
||||
|
||||
def _choose_url(info, metadata):
|
||||
def _yt_choose_url(info, metadata):
|
||||
is_video = metadata['format'] == 'video'
|
||||
|
||||
# Filter formats by file extension
|
||||
@@ -101,5 +101,16 @@ def _choose_url(info, metadata):
|
||||
return item['url']
|
||||
|
||||
|
||||
def _vimeo_choose_url(info, metadata):
|
||||
# Query formats with 'extension' = mp4 and 'format_id' = http-1080p/http-720p/../http-360p
|
||||
fmt_list = [x for x in info['formats'] if x['ext'] == 'mp4' and x['format_id'].startswith('http-')]
|
||||
|
||||
ordered = sorted(fmt_list, key=lambda x: x['width'], reverse=True)
|
||||
is_high_quality = metadata['quality'] == 'high'
|
||||
item = ordered[0] if is_high_quality else ordered[-1]
|
||||
|
||||
return item['url']
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0', port=5002, workers=32)
|
||||
app.run(host='0.0.0.0', port=5002, workers=32)
|
||||
|
||||
Reference in New Issue
Block a user