X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=youtube_dl%2Futils.py;h=c0325f054ddfccd2c601acaee3812be5e00a4e6e;hb=5ae17037a31edec0dd232f6ccb72212ab4dc5f2e;hp=65556d056a7edfe12b94e82d0f55baa93360aa70;hpb=a2973eb59733c5f86a249c627d654b789020bc7d;p=youtube-dl diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 65556d056..c0325f054 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -259,15 +259,6 @@ def get_element_by_attribute(attribute, value, html): return unescapeHTML(res) -def extract_attributes(attributes_str, attributes_regex=r'(?s)\s*([^\s=]+)\s*=\s*["\']([^"\']+)["\']'): - attributes = re.findall(attributes_regex, attributes_str) - attributes_dict = {} - if attributes: - for (attribute_name, attribute_value) in attributes: - attributes_dict[attribute_name] = attribute_value - return attributes_dict - - def clean_html(html): """Clean an HTML snippet into a readable string""" @@ -405,10 +396,14 @@ def _htmlentity_transform(entity): numstr = '0%s' % numstr else: base = 10 - return compat_chr(int(numstr, base)) + # See https://github.com/rg3/youtube-dl/issues/7518 + try: + return compat_chr(int(numstr, base)) + except ValueError: + pass # Unknown entity in name, return its literal representation - return ('&%s;' % entity) + return '&%s;' % entity def unescapeHTML(s): @@ -930,6 +925,21 @@ def determine_ext(url, default_ext='unknown_video'): guess = url.partition('?')[0].rpartition('.')[2] if re.match(r'^[A-Za-z0-9]+$', guess): return guess + elif guess.rstrip('/') in ( + 'mp4', 'm4a', 'm4p', 'm4b', 'm4r', 'm4v', 'aac', + 'flv', 'f4v', 'f4a', 'f4b', + 'webm', 'ogg', 'ogv', 'oga', 'ogx', 'spx', 'opus', + 'mkv', 'mka', 'mk3d', + 'avi', 'divx', + 'mov', + 'asf', 'wmv', 'wma', + '3gp', '3g2', + 'mp3', + 'flac', + 'ape', + 'wav', + 'f4f', 'f4m', 'm3u8', 'smil'): + return guess.rstrip('/') else: return default_ext @@ -1673,7 +1683,9 @@ def urlencode_postdata(*args, **kargs): def encode_dict(d, encoding='utf-8'): - return dict((k.encode(encoding), v.encode(encoding)) for k, v in d.items()) + def encode(v): + return v.encode(encoding) if isinstance(v, compat_basestring) else v + return dict((encode(k), encode(v)) for k, v in d.items()) US_RATINGS = {