mirror of
https://github.com/meeb/tubesync.git
synced 2025-06-24 05:56:37 +00:00
Use new multiple key sorting
This commit is contained in:
parent
4b60073ef0
commit
ede9dff4e6
@ -5,6 +5,7 @@
|
||||
'''
|
||||
|
||||
|
||||
from .utils import multi_key_sort
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
@ -49,6 +50,7 @@ def get_best_audio_format(media):
|
||||
'''
|
||||
# Order all audio-only formats by bitrate
|
||||
audio_formats = []
|
||||
sort_keys = [('abr', True)] # key, reverse
|
||||
for fmt in media.iter_formats():
|
||||
# If the format has a video stream, skip it
|
||||
if fmt['vcodec'] is not None:
|
||||
@ -56,7 +58,7 @@ def get_best_audio_format(media):
|
||||
if not fmt['acodec']:
|
||||
continue
|
||||
audio_formats.append(fmt)
|
||||
audio_formats = list(reversed(sorted(audio_formats, key=lambda k: k['abr'])))
|
||||
audio_formats = list(multi_key_sort(audio_formats, sort_keys))
|
||||
if not audio_formats:
|
||||
# Media has no audio formats at all
|
||||
return False, False
|
||||
@ -86,6 +88,7 @@ def get_best_video_format(media):
|
||||
return False, False
|
||||
# Filter video-only formats by resolution that matches the source
|
||||
video_formats = []
|
||||
sort_keys = [('height', True), ('id', True)] # key, reverse
|
||||
for fmt in media.iter_formats():
|
||||
# If the format has an audio stream, skip it
|
||||
if fmt['acodec'] is not None:
|
||||
@ -109,7 +112,7 @@ def get_best_video_format(media):
|
||||
else:
|
||||
# Can't fallback
|
||||
return False, False
|
||||
video_formats = list(reversed(sorted(video_formats, key=lambda k: k['height'])))
|
||||
video_formats = list(multi_key_sort(video_formats, sort_keys))
|
||||
source_resolution = media.source.source_resolution.strip().upper()
|
||||
source_vcodec = media.source.source_vcodec
|
||||
if not video_formats:
|
||||
|
Loading…
Reference in New Issue
Block a user