From 9d3d997e9ae2b75a9e45ebdbdf76314b7cd0b5d5 Mon Sep 17 00:00:00 2001 From: tcely Date: Wed, 19 Feb 2025 00:53:05 -0500 Subject: [PATCH] Select a combined format if nothing else is available --- tubesync/sync/models.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tubesync/sync/models.py b/tubesync/sync/models.py index 1809d18a..15083606 100644 --- a/tubesync/sync/models.py +++ b/tubesync/sync/models.py @@ -822,6 +822,25 @@ class Media(models.Model): if audio_format and video_format: return f'{video_format}+{audio_format}' else: + # last resort: any combined format + fallback_hd_cutoff = getattr(settings, 'VIDEO_HEIGHT_IS_HD', 500) + + for fmt in reversed(list(self.iter_formats())): + select_fmt = ( + fmt.get('id') and + fmt.get('acodec') and + fmt.get('vcodec') and + self.source.can_fallback and + ( + (self.source.fallback == Val(Fallback.NEXT_BEST)) or + ( + self.source.fallback == Val(Fallback.NEXT_BEST_HD) and + (fmt.get('height') or 0) >= fallback_hd_cutoff + ) + ) + ) + if select_fmt: + return str(fmt.get('id')) return False return False