mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2026-07-02 16:28:52 +00:00
[utils] parse_resolution: Support fps suffixes (#17073)
Authored by: doe1080
This commit is contained in:
parent
7a569456f2
commit
1249676e98
@ -1405,7 +1405,11 @@ class TestUtil(unittest.TestCase):
|
|||||||
self.assertEqual(parse_resolution('1920×1080 '), {'width': 1920, 'height': 1080})
|
self.assertEqual(parse_resolution('1920×1080 '), {'width': 1920, 'height': 1080})
|
||||||
self.assertEqual(parse_resolution('1920 x 1080'), {'width': 1920, 'height': 1080})
|
self.assertEqual(parse_resolution('1920 x 1080'), {'width': 1920, 'height': 1080})
|
||||||
self.assertEqual(parse_resolution('720p'), {'height': 720})
|
self.assertEqual(parse_resolution('720p'), {'height': 720})
|
||||||
|
self.assertEqual(parse_resolution('1080p60'), {'height': 1080})
|
||||||
|
self.assertEqual(parse_resolution('1080p120', parse_fps=True), {'height': 1080, 'fps': 120})
|
||||||
self.assertEqual(parse_resolution('4k'), {'height': 2160})
|
self.assertEqual(parse_resolution('4k'), {'height': 2160})
|
||||||
|
self.assertEqual(parse_resolution('4K60'), {'height': 2160})
|
||||||
|
self.assertEqual(parse_resolution('4K120', parse_fps=True), {'height': 2160, 'fps': 120})
|
||||||
self.assertEqual(parse_resolution('8K'), {'height': 4320})
|
self.assertEqual(parse_resolution('8K'), {'height': 4320})
|
||||||
self.assertEqual(parse_resolution('pre_1920x1080_post'), {'width': 1920, 'height': 1080})
|
self.assertEqual(parse_resolution('pre_1920x1080_post'), {'width': 1920, 'height': 1080})
|
||||||
self.assertEqual(parse_resolution('ep1x2'), {})
|
self.assertEqual(parse_resolution('ep1x2'), {})
|
||||||
|
|||||||
@ -1873,7 +1873,8 @@ def parse_count(s):
|
|||||||
return str_to_int(mobj.group(1))
|
return str_to_int(mobj.group(1))
|
||||||
|
|
||||||
|
|
||||||
def parse_resolution(s, *, lenient=False):
|
@partial_application
|
||||||
|
def parse_resolution(s, *, lenient=False, parse_fps=False):
|
||||||
if s is None:
|
if s is None:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
@ -1887,13 +1888,19 @@ def parse_resolution(s, *, lenient=False):
|
|||||||
'height': int(mobj.group('h')),
|
'height': int(mobj.group('h')),
|
||||||
}
|
}
|
||||||
|
|
||||||
mobj = re.search(r'(?<![a-zA-Z0-9])(\d+)[pPiI](?![a-zA-Z0-9])', s)
|
fps_suffix = r'(?P<fps>\d{2,3})?'
|
||||||
|
mobj = re.search(rf'(?<![a-zA-Z0-9])(?P<height>\d+)[pPiI]{fps_suffix}(?![a-zA-Z0-9])', s)
|
||||||
|
scale = 1
|
||||||
|
if not mobj:
|
||||||
|
mobj = re.search(rf'\b(?P<height>[48])[kK]{fps_suffix}\b', s)
|
||||||
|
scale = 540
|
||||||
if mobj:
|
if mobj:
|
||||||
return {'height': int(mobj.group(1))}
|
res = {'height': int(mobj.group('height')) * scale}
|
||||||
|
if parse_fps:
|
||||||
|
if fps := mobj.group('fps'):
|
||||||
|
res['fps'] = int(fps)
|
||||||
|
|
||||||
mobj = re.search(r'\b([48])[kK]\b', s)
|
return res
|
||||||
if mobj:
|
|
||||||
return {'height': int(mobj.group(1)) * 540}
|
|
||||||
|
|
||||||
if lenient:
|
if lenient:
|
||||||
mobj = re.search(r'(?<!\d)(\d{2,5})w(?![a-zA-Z0-9])', s)
|
mobj = re.search(r'(?<!\d)(\d{2,5})w(?![a-zA-Z0-9])', s)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user