Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 56 additions & 29 deletions tubesync/sync/matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,20 @@ def get_best_video_format(media):
return False, False
video_formats = multi_key_sort(video_formats, sort_keys, True)
source_resolution = media.source.source_resolution.strip().upper()
source_resolution_height = media.source.source_resolution_height
source_vcodec = media.source.source_vcodec
exact_match, best_match = None, None
for fmt in video_formats:
# format_note was blank, match height instead
if '' == fmt['format'] and fmt['height'] == media.source.source_resolution_height:
fmt['format'] = source_resolution
def matched_resolution(fmt):
if fmt['format'] == source_resolution:
return True
elif fmt['height'] == source_resolution_height:
return True
return False
# Of our filtered video formats, check for resolution + codec + hdr + fps match
if media.source.prefer_60fps and media.source.prefer_hdr:
for fmt in video_formats:
# Check for an exact match
if (source_resolution == fmt['format'] and
if (matched_resolution(fmt) and
source_vcodec == fmt['vcodec'] and
fmt['is_hdr'] and
fmt['is_60fps']):
Expand All @@ -142,7 +145,7 @@ def get_best_video_format(media):
if not best_match:
for fmt in video_formats:
# Check for a resolution, hdr and fps match but drop the codec
if (source_resolution == fmt['format'] and
if (matched_resolution(fmt) and
fmt['is_hdr'] and fmt['is_60fps']):
# Close match
exact_match, best_match = False, fmt
Expand All @@ -158,44 +161,50 @@ def get_best_video_format(media):
if not best_match:
for fmt in video_formats:
# Check for resolution, codec and 60fps match
if (source_resolution == fmt['format'] and
if (matched_resolution(fmt) and
source_vcodec == fmt['vcodec'] and
fmt['is_60fps']):
exact_match, best_match = False, fmt
break
if not best_match:
for fmt in video_formats:
# Check for resolution and hdr match
if (source_resolution == fmt['format'] and
if (matched_resolution(fmt) and
fmt['is_hdr']):
exact_match, best_match = False, fmt
break
if not best_match:
for fmt in video_formats:
# Check for resolution and 60fps match
if (source_resolution == fmt['format'] and
if (matched_resolution(fmt) and
fmt['is_60fps']):
exact_match, best_match = False, fmt
break
if not best_match:
for fmt in video_formats:
# Check for resolution, codec and hdr match
if (source_resolution == fmt['format'] and
if (matched_resolution(fmt) and
source_vcodec == fmt['vcodec'] and
fmt['is_hdr']):
exact_match, best_match = False, fmt
break
if not best_match:
for fmt in video_formats:
# Check for resolution and codec
if (source_resolution == fmt['format'] and
if (matched_resolution(fmt) and
source_vcodec == fmt['vcodec']):
exact_match, best_match = False, fmt
break
if not best_match:
for fmt in video_formats:
# Check for resolution
if source_resolution == fmt['format']:
if matched_resolution(fmt):
exact_match, best_match = False, fmt
break
if not best_match:
for fmt in video_formats:
# Check for codec
if (source_vcodec == fmt['vcodec']):
exact_match, best_match = False, fmt
break
if not best_match:
Expand All @@ -205,7 +214,7 @@ def get_best_video_format(media):
if media.source.prefer_60fps and not media.source.prefer_hdr:
for fmt in video_formats:
# Check for an exact match
if (source_resolution == fmt['format'] and
if (matched_resolution(fmt) and
source_vcodec == fmt['vcodec'] and
fmt['is_60fps'] and
not fmt['is_hdr']):
Expand All @@ -216,7 +225,7 @@ def get_best_video_format(media):
if not best_match:
for fmt in video_formats:
# Check for a resolution and fps match but drop the codec
if (source_resolution == fmt['format'] and
if (matched_resolution(fmt) and
fmt['is_60fps'] and
not fmt['is_hdr']):
exact_match, best_match = False, fmt
Expand All @@ -239,22 +248,28 @@ def get_best_video_format(media):
if not best_match:
for fmt in video_formats:
# Check for codec and resolution match but drop 60fps
if (source_resolution == fmt['format'] and
if (matched_resolution(fmt) and
source_vcodec == fmt['vcodec'] and
not fmt['is_hdr']):
exact_match, best_match = False, fmt
break
if not best_match:
for fmt in video_formats:
# Check for codec and resolution match only
if (source_resolution == fmt['format'] and
if (matched_resolution(fmt) and
source_vcodec == fmt['vcodec']):
exact_match, best_match = False, fmt
break
if not best_match:
for fmt in video_formats:
# Check for resolution
if source_resolution == fmt['format']:
if matched_resolution(fmt):
exact_match, best_match = False, fmt
break
if not best_match:
for fmt in video_formats:
# Check for codec
if (source_vcodec == fmt['vcodec']):
exact_match, best_match = False, fmt
break
if not best_match:
Expand All @@ -264,7 +279,7 @@ def get_best_video_format(media):
elif media.source.prefer_hdr and not media.source.prefer_60fps:
for fmt in video_formats:
# Check for an exact match
if (source_resolution == fmt['format'] and
if (matched_resolution(fmt) and
source_vcodec == fmt['vcodec'] and
fmt['is_hdr']):
# Exact match
Expand All @@ -274,7 +289,7 @@ def get_best_video_format(media):
if not best_match:
for fmt in video_formats:
# Check for a resolution and fps match but drop the codec
if (source_resolution == fmt['format'] and
if (matched_resolution(fmt) and
fmt['is_hdr'] and
not fmt['is_60fps']):
exact_match, best_match = False, fmt
Expand All @@ -297,22 +312,28 @@ def get_best_video_format(media):
if not best_match:
for fmt in video_formats:
# Check for codec and resolution match but drop hdr
if (source_resolution == fmt['format'] and
if (matched_resolution(fmt) and
source_vcodec == fmt['vcodec'] and
not fmt['is_60fps']):
exact_match, best_match = False, fmt
break
if not best_match:
for fmt in video_formats:
# Check for codec and resolution match only
if (source_resolution == fmt['format'] and
if (matched_resolution(fmt) and
source_vcodec == fmt['vcodec']):
exact_match, best_match = False, fmt
break
if not best_match:
for fmt in video_formats:
# Check for resolution
if source_resolution == fmt['format']:
if matched_resolution(fmt):
exact_match, best_match = False, fmt
break
if not best_match:
for fmt in video_formats:
# Check for codec
if (source_vcodec == fmt['vcodec']):
exact_match, best_match = False, fmt
break
if not best_match:
Expand All @@ -322,7 +343,7 @@ def get_best_video_format(media):
elif not media.source.prefer_hdr and not media.source.prefer_60fps:
for fmt in video_formats:
# Check for an exact match
if (source_resolution == fmt['format'] and
if (matched_resolution(fmt) and
source_vcodec == fmt['vcodec'] and
not fmt['is_60fps'] and
not fmt['is_hdr']):
Expand All @@ -333,7 +354,7 @@ def get_best_video_format(media):
if not best_match:
for fmt in video_formats:
# Check for a resolution, hdr and fps match but drop the codec
if (source_resolution == fmt['format'] and
if (matched_resolution(fmt) and
not fmt['is_hdr'] and not fmt['is_60fps']):
# Close match
exact_match, best_match = False, fmt
Expand All @@ -349,37 +370,43 @@ def get_best_video_format(media):
if not best_match:
for fmt in video_formats:
# Check for resolution, codec and hdr match
if (source_resolution == fmt['format'] and
if (matched_resolution(fmt) and
source_vcodec == fmt['vcodec'] and
not fmt['is_hdr']):
exact_match, best_match = False, fmt
break
if not best_match:
for fmt in video_formats:
# Check for resolution, codec and 60fps match
if (source_resolution == fmt['format'] and
if (matched_resolution(fmt) and
source_vcodec == fmt['vcodec'] and
not fmt['is_60fps']):
exact_match, best_match = False, fmt
break
if not best_match:
for fmt in video_formats:
# Check for resolution and codec
if (source_resolution == fmt['format'] and
if (matched_resolution(fmt) and
source_vcodec == fmt['vcodec']):
exact_match, best_match = False, fmt
break
if not best_match:
for fmt in video_formats:
# Check for resolution and not hdr
if (source_resolution == fmt['format'] and
if (matched_resolution(fmt) and
not fmt['is_hdr']):
exact_match, best_match = False, fmt
break
if not best_match:
for fmt in video_formats:
# Check for resolution
if source_resolution == fmt['format']:
if matched_resolution(fmt):
exact_match, best_match = False, fmt
break
if not best_match:
for fmt in video_formats:
# Check for codec
if (source_vcodec == fmt['vcodec']):
exact_match, best_match = False, fmt
break
if not best_match:
Expand Down