diff options
author | Remita Amine <remitamine@gmail.com> | 2017-05-02 00:06:19 +0100 |
---|---|---|
committer | Remita Amine <remitamine@gmail.com> | 2017-05-02 00:06:58 +0100 |
commit | 7fc875195fd74c235d6ca86afc642f683a485a4b (patch) | |
tree | b4d930b4fa53ee0bd8b39993a432d9b63a95a943 /youtube_dl | |
parent | c6fe5a7e12a5ebbe137b889afb8aefc206d132af (diff) |
[amp] imporove thumbnail and subtitle extraction
Diffstat (limited to 'youtube_dl')
-rw-r--r-- | youtube_dl/extractor/amp.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/youtube_dl/extractor/amp.py b/youtube_dl/extractor/amp.py index 98f8e69cd..fde1a8ff7 100644 --- a/youtube_dl/extractor/amp.py +++ b/youtube_dl/extractor/amp.py @@ -34,9 +34,12 @@ class AMPIE(InfoExtractor): if isinstance(media_thumbnail, dict): media_thumbnail = [media_thumbnail] for thumbnail_data in media_thumbnail: - thumbnail = thumbnail_data['@attributes'] + thumbnail = thumbnail_data.get('@attributes', {}) + thumbnail_url = thumbnail.get('url') + if not thumbnail_url: + continue thumbnails.append({ - 'url': self._proto_relative_url(thumbnail['url'], 'http:'), + 'url': self._proto_relative_url(thumbnail_url, 'http:'), 'width': int_or_none(thumbnail.get('width')), 'height': int_or_none(thumbnail.get('height')), }) @@ -47,9 +50,14 @@ class AMPIE(InfoExtractor): if isinstance(media_subtitle, dict): media_subtitle = [media_subtitle] for subtitle_data in media_subtitle: - subtitle = subtitle_data['@attributes'] - lang = subtitle.get('lang') or 'en' - subtitles[lang] = [{'url': subtitle['href']}] + subtitle = subtitle_data.get('@attributes', {}) + subtitle_href = subtitle.get('href') + if not subtitle_href: + continue + subtitles.setdefault(subtitle.get('lang') or 'en', []).append({ + 'url': subtitle_href, + 'ext': mimetype2ext(subtitle.get('type')) or determine_ext(subtitle_href), + }) formats = [] media_content = get_media_node('content') |