1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-11-29 19:47:54 +01:00

utils: lookup_unit_table: Use a stricter regex

In parse_count multiple units start with the same letter, so it would match different units depending on the order they were sorted when iterating over them.
This commit is contained in:
Jaime Marquínez Ferrándiz 2016-03-18 19:18:55 +01:00
parent 4c3b16d5d1
commit 09fc33198a

View File

@ -1346,7 +1346,7 @@ def format_bytes(bytes):
def lookup_unit_table(unit_table, s): def lookup_unit_table(unit_table, s):
units_re = '|'.join(re.escape(u) for u in unit_table) units_re = '|'.join(re.escape(u) for u in unit_table)
m = re.match( m = re.match(
r'(?P<num>[0-9]+(?:[,.][0-9]*)?)\s*(?P<unit>%s)' % units_re, s) r'(?P<num>[0-9]+(?:[,.][0-9]*)?)\s*(?P<unit>%s)$' % units_re, s)
if not m: if not m:
return None return None
num_str = m.group('num').replace(',', '.') num_str = m.group('num').replace(',', '.')