From ede9dff4e6b2cbbf8ca81eb6681c744d61fcbf89 Mon Sep 17 00:00:00 2001 From: tcely Date: Mon, 2 Dec 2024 10:56:19 -0500 Subject: [PATCH] Use new multiple key sorting --- tubesync/sync/matching.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tubesync/sync/matching.py b/tubesync/sync/matching.py index c453ff96..5d5b5dbd 100644 --- a/tubesync/sync/matching.py +++ b/tubesync/sync/matching.py @@ -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: