mirror of
https://github.com/ytdl-org/youtube-dl
synced 2024-12-22 20:20:09 +09:00
[utils] Introduce parse_bitrate
This commit is contained in:
parent
e5cfb779ea
commit
0dc41787af
@ -55,6 +55,7 @@ from youtube_dl.utils import (
|
|||||||
parse_count,
|
parse_count,
|
||||||
parse_iso8601,
|
parse_iso8601,
|
||||||
parse_resolution,
|
parse_resolution,
|
||||||
|
parse_bitrate,
|
||||||
pkcs1pad,
|
pkcs1pad,
|
||||||
read_batch_urls,
|
read_batch_urls,
|
||||||
sanitize_filename,
|
sanitize_filename,
|
||||||
@ -1030,6 +1031,13 @@ class TestUtil(unittest.TestCase):
|
|||||||
self.assertEqual(parse_resolution('4k'), {'height': 2160})
|
self.assertEqual(parse_resolution('4k'), {'height': 2160})
|
||||||
self.assertEqual(parse_resolution('8K'), {'height': 4320})
|
self.assertEqual(parse_resolution('8K'), {'height': 4320})
|
||||||
|
|
||||||
|
def test_parse_bitrate(self):
|
||||||
|
self.assertEqual(parse_bitrate(None), None)
|
||||||
|
self.assertEqual(parse_bitrate(''), None)
|
||||||
|
self.assertEqual(parse_bitrate('300kbps'), 300)
|
||||||
|
self.assertEqual(parse_bitrate('1500kbps'), 1500)
|
||||||
|
self.assertEqual(parse_bitrate('300 kbps'), 300)
|
||||||
|
|
||||||
def test_version_tuple(self):
|
def test_version_tuple(self):
|
||||||
self.assertEqual(version_tuple('1'), (1,))
|
self.assertEqual(version_tuple('1'), (1,))
|
||||||
self.assertEqual(version_tuple('10.23.344'), (10, 23, 344))
|
self.assertEqual(version_tuple('10.23.344'), (10, 23, 344))
|
||||||
|
@ -1798,6 +1798,14 @@ def parse_resolution(s):
|
|||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
def parse_bitrate(s):
|
||||||
|
if not isinstance(s, compat_str):
|
||||||
|
return
|
||||||
|
mobj = re.search(r'\b(\d+)\s*kbps', s)
|
||||||
|
if mobj:
|
||||||
|
return int(mobj.group(1))
|
||||||
|
|
||||||
|
|
||||||
def month_by_name(name, lang='en'):
|
def month_by_name(name, lang='en'):
|
||||||
""" Return the number of a month by (locale-independently) English name """
|
""" Return the number of a month by (locale-independently) English name """
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user