mirror of
https://github.com/mxpv/podsync.git
synced 2024-05-11 05:55:04 +00:00
Improve audio sorting, add tests
This commit is contained in:
8
cmd/ytdl/test_ytdl.py
Normal file
8
cmd/ytdl/test_ytdl.py
Normal file
@@ -0,0 +1,8 @@
|
||||
import ytdl
|
||||
import unittest
|
||||
|
||||
|
||||
class TestYtdl(unittest.TestCase):
|
||||
def test_resolve(self):
|
||||
self.assertIsNotNone(ytdl._resolve('https://youtube.com/watch?v=ygIUF678y40', {'format': 'video', 'quality': 'low'}))
|
||||
self.assertIsNotNone(ytdl._resolve('https://youtube.com/watch?v=WyaEiO4hyik', {'format': 'audio', 'quality': 'high'}))
|
||||
@@ -83,7 +83,10 @@ def _choose_url(info, metadata):
|
||||
|
||||
# Sort list by field (width for videos, file size for audio)
|
||||
sort_field = 'width' if is_video else 'filesize'
|
||||
ordered = sorted(fmt_list, key=lambda x: x[sort_field] or x['format_id'], reverse=True)
|
||||
# Sometime 'filesize' field can be None
|
||||
if not all(x[sort_field] is not None for x in fmt_list):
|
||||
sort_field = 'format_id'
|
||||
ordered = sorted(fmt_list, key=lambda x: x[sort_field], reverse=True)
|
||||
|
||||
# Choose an item depending on quality, better at the beginning
|
||||
is_high_quality = metadata['quality'] == 'high'
|
||||
|
||||
Reference in New Issue
Block a user