Merge pull request #991 from tcely/patch-2
Expand resolution matching to include height
This commit is contained in:
1 file changed
+56
-29
+56
-29
@@ -121,17 +121,20 @@ def get_best_video_format(media):
|
|||||||
return False, False
|
return False, False
|
||||||
video_formats = multi_key_sort(video_formats, sort_keys, True)
|
video_formats = multi_key_sort(video_formats, sort_keys, True)
|
||||||
source_resolution = media.source.source_resolution.strip().upper()
|
source_resolution = media.source.source_resolution.strip().upper()
|
||||||
|
source_resolution_height = media.source.source_resolution_height
|
||||||
source_vcodec = media.source.source_vcodec
|
source_vcodec = media.source.source_vcodec
|
||||||
exact_match, best_match = None, None
|
exact_match, best_match = None, None
|
||||||
for fmt in video_formats:
|
def matched_resolution(fmt):
|
||||||
# format_note was blank, match height instead
|
if fmt['format'] == source_resolution:
|
||||||
if '' == fmt['format'] and fmt['height'] == media.source.source_resolution_height:
|
return True
|
||||||
fmt['format'] = source_resolution
|
elif fmt['height'] == source_resolution_height:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
# Of our filtered video formats, check for resolution + codec + hdr + fps match
|
# Of our filtered video formats, check for resolution + codec + hdr + fps match
|
||||||
if media.source.prefer_60fps and media.source.prefer_hdr:
|
if media.source.prefer_60fps and media.source.prefer_hdr:
|
||||||
for fmt in video_formats:
|
for fmt in video_formats:
|
||||||
# Check for an exact match
|
# Check for an exact match
|
||||||
if (source_resolution == fmt['format'] and
|
if (matched_resolution(fmt) and
|
||||||
source_vcodec == fmt['vcodec'] and
|
source_vcodec == fmt['vcodec'] and
|
||||||
fmt['is_hdr'] and
|
fmt['is_hdr'] and
|
||||||
fmt['is_60fps']):
|
fmt['is_60fps']):
|
||||||
@@ -142,7 +145,7 @@ def get_best_video_format(media):
|
|||||||
if not best_match:
|
if not best_match:
|
||||||
for fmt in video_formats:
|
for fmt in video_formats:
|
||||||
# Check for a resolution, hdr and fps match but drop the codec
|
# 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']):
|
fmt['is_hdr'] and fmt['is_60fps']):
|
||||||
# Close match
|
# Close match
|
||||||
exact_match, best_match = False, fmt
|
exact_match, best_match = False, fmt
|
||||||
@@ -158,7 +161,7 @@ def get_best_video_format(media):
|
|||||||
if not best_match:
|
if not best_match:
|
||||||
for fmt in video_formats:
|
for fmt in video_formats:
|
||||||
# Check for resolution, codec and 60fps match
|
# Check for resolution, codec and 60fps match
|
||||||
if (source_resolution == fmt['format'] and
|
if (matched_resolution(fmt) and
|
||||||
source_vcodec == fmt['vcodec'] and
|
source_vcodec == fmt['vcodec'] and
|
||||||
fmt['is_60fps']):
|
fmt['is_60fps']):
|
||||||
exact_match, best_match = False, fmt
|
exact_match, best_match = False, fmt
|
||||||
@@ -166,21 +169,21 @@ def get_best_video_format(media):
|
|||||||
if not best_match:
|
if not best_match:
|
||||||
for fmt in video_formats:
|
for fmt in video_formats:
|
||||||
# Check for resolution and hdr match
|
# Check for resolution and hdr match
|
||||||
if (source_resolution == fmt['format'] and
|
if (matched_resolution(fmt) and
|
||||||
fmt['is_hdr']):
|
fmt['is_hdr']):
|
||||||
exact_match, best_match = False, fmt
|
exact_match, best_match = False, fmt
|
||||||
break
|
break
|
||||||
if not best_match:
|
if not best_match:
|
||||||
for fmt in video_formats:
|
for fmt in video_formats:
|
||||||
# Check for resolution and 60fps match
|
# Check for resolution and 60fps match
|
||||||
if (source_resolution == fmt['format'] and
|
if (matched_resolution(fmt) and
|
||||||
fmt['is_60fps']):
|
fmt['is_60fps']):
|
||||||
exact_match, best_match = False, fmt
|
exact_match, best_match = False, fmt
|
||||||
break
|
break
|
||||||
if not best_match:
|
if not best_match:
|
||||||
for fmt in video_formats:
|
for fmt in video_formats:
|
||||||
# Check for resolution, codec and hdr match
|
# Check for resolution, codec and hdr match
|
||||||
if (source_resolution == fmt['format'] and
|
if (matched_resolution(fmt) and
|
||||||
source_vcodec == fmt['vcodec'] and
|
source_vcodec == fmt['vcodec'] and
|
||||||
fmt['is_hdr']):
|
fmt['is_hdr']):
|
||||||
exact_match, best_match = False, fmt
|
exact_match, best_match = False, fmt
|
||||||
@@ -188,14 +191,20 @@ def get_best_video_format(media):
|
|||||||
if not best_match:
|
if not best_match:
|
||||||
for fmt in video_formats:
|
for fmt in video_formats:
|
||||||
# Check for resolution and codec
|
# Check for resolution and codec
|
||||||
if (source_resolution == fmt['format'] and
|
if (matched_resolution(fmt) and
|
||||||
source_vcodec == fmt['vcodec']):
|
source_vcodec == fmt['vcodec']):
|
||||||
exact_match, best_match = False, fmt
|
exact_match, best_match = False, fmt
|
||||||
break
|
break
|
||||||
if not best_match:
|
if not best_match:
|
||||||
for fmt in video_formats:
|
for fmt in video_formats:
|
||||||
# Check for resolution
|
# 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
|
exact_match, best_match = False, fmt
|
||||||
break
|
break
|
||||||
if not best_match:
|
if not best_match:
|
||||||
@@ -205,7 +214,7 @@ def get_best_video_format(media):
|
|||||||
if media.source.prefer_60fps and not media.source.prefer_hdr:
|
if media.source.prefer_60fps and not media.source.prefer_hdr:
|
||||||
for fmt in video_formats:
|
for fmt in video_formats:
|
||||||
# Check for an exact match
|
# Check for an exact match
|
||||||
if (source_resolution == fmt['format'] and
|
if (matched_resolution(fmt) and
|
||||||
source_vcodec == fmt['vcodec'] and
|
source_vcodec == fmt['vcodec'] and
|
||||||
fmt['is_60fps'] and
|
fmt['is_60fps'] and
|
||||||
not fmt['is_hdr']):
|
not fmt['is_hdr']):
|
||||||
@@ -216,7 +225,7 @@ def get_best_video_format(media):
|
|||||||
if not best_match:
|
if not best_match:
|
||||||
for fmt in video_formats:
|
for fmt in video_formats:
|
||||||
# Check for a resolution and fps match but drop the codec
|
# 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
|
fmt['is_60fps'] and
|
||||||
not fmt['is_hdr']):
|
not fmt['is_hdr']):
|
||||||
exact_match, best_match = False, fmt
|
exact_match, best_match = False, fmt
|
||||||
@@ -239,7 +248,7 @@ def get_best_video_format(media):
|
|||||||
if not best_match:
|
if not best_match:
|
||||||
for fmt in video_formats:
|
for fmt in video_formats:
|
||||||
# Check for codec and resolution match but drop 60fps
|
# 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
|
source_vcodec == fmt['vcodec'] and
|
||||||
not fmt['is_hdr']):
|
not fmt['is_hdr']):
|
||||||
exact_match, best_match = False, fmt
|
exact_match, best_match = False, fmt
|
||||||
@@ -247,14 +256,20 @@ def get_best_video_format(media):
|
|||||||
if not best_match:
|
if not best_match:
|
||||||
for fmt in video_formats:
|
for fmt in video_formats:
|
||||||
# Check for codec and resolution match only
|
# Check for codec and resolution match only
|
||||||
if (source_resolution == fmt['format'] and
|
if (matched_resolution(fmt) and
|
||||||
source_vcodec == fmt['vcodec']):
|
source_vcodec == fmt['vcodec']):
|
||||||
exact_match, best_match = False, fmt
|
exact_match, best_match = False, fmt
|
||||||
break
|
break
|
||||||
if not best_match:
|
if not best_match:
|
||||||
for fmt in video_formats:
|
for fmt in video_formats:
|
||||||
# Check for resolution
|
# 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
|
exact_match, best_match = False, fmt
|
||||||
break
|
break
|
||||||
if not best_match:
|
if not best_match:
|
||||||
@@ -264,7 +279,7 @@ def get_best_video_format(media):
|
|||||||
elif media.source.prefer_hdr and not media.source.prefer_60fps:
|
elif media.source.prefer_hdr and not media.source.prefer_60fps:
|
||||||
for fmt in video_formats:
|
for fmt in video_formats:
|
||||||
# Check for an exact match
|
# Check for an exact match
|
||||||
if (source_resolution == fmt['format'] and
|
if (matched_resolution(fmt) and
|
||||||
source_vcodec == fmt['vcodec'] and
|
source_vcodec == fmt['vcodec'] and
|
||||||
fmt['is_hdr']):
|
fmt['is_hdr']):
|
||||||
# Exact match
|
# Exact match
|
||||||
@@ -274,7 +289,7 @@ def get_best_video_format(media):
|
|||||||
if not best_match:
|
if not best_match:
|
||||||
for fmt in video_formats:
|
for fmt in video_formats:
|
||||||
# Check for a resolution and fps match but drop the codec
|
# 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
|
fmt['is_hdr'] and
|
||||||
not fmt['is_60fps']):
|
not fmt['is_60fps']):
|
||||||
exact_match, best_match = False, fmt
|
exact_match, best_match = False, fmt
|
||||||
@@ -297,7 +312,7 @@ def get_best_video_format(media):
|
|||||||
if not best_match:
|
if not best_match:
|
||||||
for fmt in video_formats:
|
for fmt in video_formats:
|
||||||
# Check for codec and resolution match but drop hdr
|
# 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
|
source_vcodec == fmt['vcodec'] and
|
||||||
not fmt['is_60fps']):
|
not fmt['is_60fps']):
|
||||||
exact_match, best_match = False, fmt
|
exact_match, best_match = False, fmt
|
||||||
@@ -305,14 +320,20 @@ def get_best_video_format(media):
|
|||||||
if not best_match:
|
if not best_match:
|
||||||
for fmt in video_formats:
|
for fmt in video_formats:
|
||||||
# Check for codec and resolution match only
|
# Check for codec and resolution match only
|
||||||
if (source_resolution == fmt['format'] and
|
if (matched_resolution(fmt) and
|
||||||
source_vcodec == fmt['vcodec']):
|
source_vcodec == fmt['vcodec']):
|
||||||
exact_match, best_match = False, fmt
|
exact_match, best_match = False, fmt
|
||||||
break
|
break
|
||||||
if not best_match:
|
if not best_match:
|
||||||
for fmt in video_formats:
|
for fmt in video_formats:
|
||||||
# Check for resolution
|
# 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
|
exact_match, best_match = False, fmt
|
||||||
break
|
break
|
||||||
if not best_match:
|
if not best_match:
|
||||||
@@ -322,7 +343,7 @@ def get_best_video_format(media):
|
|||||||
elif not media.source.prefer_hdr and not media.source.prefer_60fps:
|
elif not media.source.prefer_hdr and not media.source.prefer_60fps:
|
||||||
for fmt in video_formats:
|
for fmt in video_formats:
|
||||||
# Check for an exact match
|
# Check for an exact match
|
||||||
if (source_resolution == fmt['format'] and
|
if (matched_resolution(fmt) and
|
||||||
source_vcodec == fmt['vcodec'] and
|
source_vcodec == fmt['vcodec'] and
|
||||||
not fmt['is_60fps'] and
|
not fmt['is_60fps'] and
|
||||||
not fmt['is_hdr']):
|
not fmt['is_hdr']):
|
||||||
@@ -333,7 +354,7 @@ def get_best_video_format(media):
|
|||||||
if not best_match:
|
if not best_match:
|
||||||
for fmt in video_formats:
|
for fmt in video_formats:
|
||||||
# Check for a resolution, hdr and fps match but drop the codec
|
# 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']):
|
not fmt['is_hdr'] and not fmt['is_60fps']):
|
||||||
# Close match
|
# Close match
|
||||||
exact_match, best_match = False, fmt
|
exact_match, best_match = False, fmt
|
||||||
@@ -349,7 +370,7 @@ def get_best_video_format(media):
|
|||||||
if not best_match:
|
if not best_match:
|
||||||
for fmt in video_formats:
|
for fmt in video_formats:
|
||||||
# Check for resolution, codec and hdr match
|
# Check for resolution, codec and hdr match
|
||||||
if (source_resolution == fmt['format'] and
|
if (matched_resolution(fmt) and
|
||||||
source_vcodec == fmt['vcodec'] and
|
source_vcodec == fmt['vcodec'] and
|
||||||
not fmt['is_hdr']):
|
not fmt['is_hdr']):
|
||||||
exact_match, best_match = False, fmt
|
exact_match, best_match = False, fmt
|
||||||
@@ -357,7 +378,7 @@ def get_best_video_format(media):
|
|||||||
if not best_match:
|
if not best_match:
|
||||||
for fmt in video_formats:
|
for fmt in video_formats:
|
||||||
# Check for resolution, codec and 60fps match
|
# Check for resolution, codec and 60fps match
|
||||||
if (source_resolution == fmt['format'] and
|
if (matched_resolution(fmt) and
|
||||||
source_vcodec == fmt['vcodec'] and
|
source_vcodec == fmt['vcodec'] and
|
||||||
not fmt['is_60fps']):
|
not fmt['is_60fps']):
|
||||||
exact_match, best_match = False, fmt
|
exact_match, best_match = False, fmt
|
||||||
@@ -365,21 +386,27 @@ def get_best_video_format(media):
|
|||||||
if not best_match:
|
if not best_match:
|
||||||
for fmt in video_formats:
|
for fmt in video_formats:
|
||||||
# Check for resolution and codec
|
# Check for resolution and codec
|
||||||
if (source_resolution == fmt['format'] and
|
if (matched_resolution(fmt) and
|
||||||
source_vcodec == fmt['vcodec']):
|
source_vcodec == fmt['vcodec']):
|
||||||
exact_match, best_match = False, fmt
|
exact_match, best_match = False, fmt
|
||||||
break
|
break
|
||||||
if not best_match:
|
if not best_match:
|
||||||
for fmt in video_formats:
|
for fmt in video_formats:
|
||||||
# Check for resolution and not hdr
|
# Check for resolution and not hdr
|
||||||
if (source_resolution == fmt['format'] and
|
if (matched_resolution(fmt) and
|
||||||
not fmt['is_hdr']):
|
not fmt['is_hdr']):
|
||||||
exact_match, best_match = False, fmt
|
exact_match, best_match = False, fmt
|
||||||
break
|
break
|
||||||
if not best_match:
|
if not best_match:
|
||||||
for fmt in video_formats:
|
for fmt in video_formats:
|
||||||
# Check for resolution
|
# 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
|
exact_match, best_match = False, fmt
|
||||||
break
|
break
|
||||||
if not best_match:
|
if not best_match:
|
||||||
|
|||||||
Reference in new issue
Block a user