From b5626f19791002fa024ec7e15272d5641375f3ea Mon Sep 17 00:00:00 2001 From: Oleksis Date: Sat, 6 Apr 2019 02:29:01 -0400 Subject: [PATCH] [picta] Fix KeyError when missing attributes in MPD Get element attribute using element.get('key') instead of element.attrib['index'] manifests like: SegmentList/Initialization@sourceURL SegmentList/SegmentURL@media Example MPD manifest https://www.picta.cu/videos/3bf20311b6564d61a0fd519b3c7dcced/manifest.mpd --- youtube_dl/extractor/common.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/youtube_dl/extractor/common.py b/youtube_dl/extractor/common.py index c4ea2882f..cec918b77 100644 --- a/youtube_dl/extractor/common.py +++ b/youtube_dl/extractor/common.py @@ -2054,8 +2054,8 @@ class InfoExtractor(object): def extract_Initialization(source): initialization = source.find(_add_ns('Initialization')) - if initialization is not None: - ms_info['initialization_url'] = initialization.attrib['sourceURL'] + if initialization is not None and initialization.get('sourceURL') is not None: + ms_info['initialization_url'] = initialization.get('sourceURL') segment_list = element.find(_add_ns('SegmentList')) if segment_list is not None: @@ -2063,7 +2063,9 @@ class InfoExtractor(object): extract_Initialization(segment_list) segment_urls_e = segment_list.findall(_add_ns('SegmentURL')) if segment_urls_e: - ms_info['segment_urls'] = [segment.attrib['media'] for segment in segment_urls_e] + segment_urls = [segment.get('media') for segment in segment_urls_e if segment.get('media') is not None] + if len(segment_urls) > 0: + ms_info['segment_urls'] = segment_urls else: segment_template = element.find(_add_ns('SegmentTemplate')) if segment_template is not None: