mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-09 19:00:39 +00:00
[utils] Improve parse_count
This commit is contained in:
parent
d43de6821c
commit
352d5da812
@ -1156,9 +1156,16 @@ class TestUtil(unittest.TestCase):
|
||||
self.assertEqual(parse_count('1000'), 1000)
|
||||
self.assertEqual(parse_count('1.000'), 1000)
|
||||
self.assertEqual(parse_count('1.1k'), 1100)
|
||||
self.assertEqual(parse_count('1.1 k'), 1100)
|
||||
self.assertEqual(parse_count('1,1 k'), 1100)
|
||||
self.assertEqual(parse_count('1.1kk'), 1100000)
|
||||
self.assertEqual(parse_count('1.1kk '), 1100000)
|
||||
self.assertEqual(parse_count('1,1kk'), 1100000)
|
||||
self.assertEqual(parse_count('100 views'), 100)
|
||||
self.assertEqual(parse_count('1,100 views'), 1100)
|
||||
self.assertEqual(parse_count('1.1kk views'), 1100000)
|
||||
self.assertEqual(parse_count('10M views'), 10000000)
|
||||
self.assertEqual(parse_count('has 10M views'), 10000000)
|
||||
|
||||
def test_parse_resolution(self):
|
||||
self.assertEqual(parse_resolution(None), {})
|
||||
|
@ -2211,7 +2211,7 @@ def parse_count(s):
|
||||
if s is None:
|
||||
return None
|
||||
|
||||
s = s.strip()
|
||||
s = re.sub(r'^[^\d]+\s', '', s).strip()
|
||||
|
||||
if re.match(r'^[\d,.]+$', s):
|
||||
return str_to_int(s)
|
||||
@ -2223,9 +2223,17 @@ def parse_count(s):
|
||||
'M': 1000 ** 2,
|
||||
'kk': 1000 ** 2,
|
||||
'KK': 1000 ** 2,
|
||||
'b': 1000 ** 3,
|
||||
'B': 1000 ** 3,
|
||||
}
|
||||
|
||||
return lookup_unit_table(_UNIT_TABLE, s)
|
||||
ret = lookup_unit_table(_UNIT_TABLE, s)
|
||||
if ret is not None:
|
||||
return ret
|
||||
|
||||
mobj = re.match(r'([\d,.]+)(?:$|\s)', s)
|
||||
if mobj:
|
||||
return str_to_int(mobj.group(1))
|
||||
|
||||
|
||||
def parse_resolution(s):
|
||||
|
Loading…
Reference in New Issue
Block a user