X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=youtube_dl%2Futils.py;h=71713f63aff9b451863b109428df0b475892b802;hb=25d9243141394cf505fb9daea824e52801b19766;hp=630dab8eb391d35114776ee7ca89dac5368c187b;hpb=067aa17edf5a46a8cbc4d6b90864eddf051fa2bc;p=youtube-dl diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 630dab8eb..71713f63a 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -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 """ @@ -1914,7 +1922,7 @@ def int_or_none(v, scale=1, default=None, get_attr=None, invscale=1): return default try: return int(v) * invscale // scale - except ValueError: + except (ValueError, TypeError): return default @@ -1935,7 +1943,7 @@ def float_or_none(v, scale=1, invscale=1, default=None): return default try: return float(v) * invscale / scale - except ValueError: + except (ValueError, TypeError): return default