[utils] Introduce parse_bitrate
[youtube-dl] / youtube_dl / utils.py
index 630dab8eb391d35114776ee7ca89dac5368c187b..f2726a5799c981742b0b45e101ae976ad8ea1ed9 100644 (file)
@@ -1798,6 +1798,14 @@ def parse_resolution(s):
     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'):
     """ Return the number of a month by (locale-independently) English name """