From f570fb57b9bec1b9c181b4d7386e61169e3d29d1 Mon Sep 17 00:00:00 2001 From: tcely Date: Thu, 5 Dec 2024 07:57:24 -0500 Subject: [PATCH 1/5] Adjust to correct 60 fps case --- tubesync/sync/matching.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tubesync/sync/matching.py b/tubesync/sync/matching.py index c453ff96..93fcdae3 100644 --- a/tubesync/sync/matching.py +++ b/tubesync/sync/matching.py @@ -331,7 +331,7 @@ def get_best_video_format(media): for fmt in video_formats: # Check for a codec, hdr and fps match but drop the resolution if (source_vcodec == fmt['vcodec'] and - not fmt['is_hdr'] and fmt['is_60fps']): + not fmt['is_hdr'] and not fmt['is_60fps']): # Close match exact_match, best_match = False, fmt break From 6fdcc5ffa5494fe25f53aef4e96ca6f7a319432d Mon Sep 17 00:00:00 2001 From: tcely Date: Thu, 5 Dec 2024 17:56:53 -0500 Subject: [PATCH 2/5] Handle STR0NNN in a generic way The function should return 'VP9' for: - vp9.1.2.3 - vp09.4.5.6 As well as other variations. It also works for avc01 or av01, or any others that fit the pattern. --- tubesync/sync/utils.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/tubesync/sync/utils.py b/tubesync/sync/utils.py index cf72462e..168cccf0 100644 --- a/tubesync/sync/utils.py +++ b/tubesync/sync/utils.py @@ -134,6 +134,21 @@ def seconds_to_timestr(seconds): return '{:02d}:{:02d}:{:02d}'.format(hour, minutes, seconds) +def normalize_codec(codec_str): + result = str(codec_str) + parts = result.split('.') + if len(parts) > 0: + result = parts[0].strip() + else: + return None + if 'NONE' == result: + return None + if str(0) in result: + prefix = result.rstrip('0123456789') + result = prefix + str(int(result[len(prefix):])) + return result.upper() + + def parse_media_format(format_dict): ''' This parser primarily adapts the format dict returned by youtube-dl into a @@ -141,21 +156,9 @@ def parse_media_format(format_dict): any internals, update it here. ''' vcodec_full = format_dict.get('vcodec', '') - vcodec_parts = vcodec_full.split('.') - if len(vcodec_parts) > 0: - vcodec = vcodec_parts[0].strip().upper() - else: - vcodec = None - if vcodec == 'NONE': - vcodec = None + vcodec = normalize_codec(vcodec_full) acodec_full = format_dict.get('acodec', '') - acodec_parts = acodec_full.split('.') - if len(acodec_parts) > 0: - acodec = acodec_parts[0].strip().upper() - else: - acodec = None - if acodec == 'NONE': - acodec = None + acodec = normalize_codec(acodec_full) try: fps = int(format_dict.get('fps', 0)) except (ValueError, TypeError): From fb663d508fd0efdf6b6879b02a5c1fe0116c4d4b Mon Sep 17 00:00:00 2001 From: tcely Date: Thu, 5 Dec 2024 18:27:46 -0500 Subject: [PATCH 3/5] Uppercase the codec string first, not last --- tubesync/sync/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tubesync/sync/utils.py b/tubesync/sync/utils.py index 168cccf0..33ea678c 100644 --- a/tubesync/sync/utils.py +++ b/tubesync/sync/utils.py @@ -135,7 +135,7 @@ def seconds_to_timestr(seconds): def normalize_codec(codec_str): - result = str(codec_str) + result = str(codec_str).upper() parts = result.split('.') if len(parts) > 0: result = parts[0].strip() @@ -146,7 +146,7 @@ def normalize_codec(codec_str): if str(0) in result: prefix = result.rstrip('0123456789') result = prefix + str(int(result[len(prefix):])) - return result.upper() + return result def parse_media_format(format_dict): From 049c6f37641fc5e6e628b705c373d5610848a84e Mon Sep 17 00:00:00 2001 From: tcely Date: Mon, 9 Dec 2024 18:05:45 -0500 Subject: [PATCH 4/5] Accept '-' in sub_langs --- tubesync/sync/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tubesync/sync/models.py b/tubesync/sync/models.py index 2f116356..88fd0b12 100644 --- a/tubesync/sync/models.py +++ b/tubesync/sync/models.py @@ -422,7 +422,7 @@ class Source(models.Model): help_text=_('List of subtitles langs to download, comma-separated. Example: en,fr or all,-fr,-live_chat'), validators=[ RegexValidator( - regex=r"^(\-?[\_\.a-zA-Z]+,)*(\-?[\_\.a-zA-Z]+){1}$", + regex=r"^(\-?[\_\.a-zA-Z-]+,)*(\-?[\_\.a-zA-Z-]+){1}$", message=_('Subtitle langs must be a comma-separated list of langs. example: en,fr or all,-fr,-live_chat') ) ] From 63d0f4f15a563f71bd66dff55f41fad2e700276f Mon Sep 17 00:00:00 2001 From: tcely Date: Tue, 10 Dec 2024 02:02:30 -0500 Subject: [PATCH 5/5] Simplify regex for sub_langs --- tubesync/sync/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tubesync/sync/models.py b/tubesync/sync/models.py index 88fd0b12..4f9de7f7 100644 --- a/tubesync/sync/models.py +++ b/tubesync/sync/models.py @@ -422,7 +422,7 @@ class Source(models.Model): help_text=_('List of subtitles langs to download, comma-separated. Example: en,fr or all,-fr,-live_chat'), validators=[ RegexValidator( - regex=r"^(\-?[\_\.a-zA-Z-]+,)*(\-?[\_\.a-zA-Z-]+){1}$", + regex=r"^(\-?[\_\.a-zA-Z-]+(,|$))+", message=_('Subtitle langs must be a comma-separated list of langs. example: en,fr or all,-fr,-live_chat') ) ]