[ard] Make more robust against missing thumbnails
authorPhilipp Hagemeister <phihag@phihag.de>
Sat, 13 Sep 2014 07:09:55 +0000 (09:09 +0200)
committerPhilipp Hagemeister <phihag@phihag.de>
Sat, 13 Sep 2014 07:09:57 +0000 (09:09 +0200)
I cannot reproduce this error, it's from travis.

youtube_dl/extractor/ard.py
youtube_dl/utils.py

index ef94c72395723b31bd444e80b6ba12d990acf38b..12457f0f996db46d48823836c50e98048162c83c 100644 (file)
@@ -13,6 +13,7 @@ from ..utils import (
     int_or_none,
     parse_duration,
     unified_strdate,
+    xpath_text,
 )
 
 
@@ -157,8 +158,9 @@ class ARDIE(InfoExtractor):
         player_url = mobj.group('mainurl') + '~playerXml.xml'
         doc = self._download_xml(player_url, display_id)
         video_node = doc.find('./video')
-        upload_date = unified_strdate(video_node.find('./broadcastDate').text)
-        thumbnail = video_node.find('.//teaserImage//variant/url').text
+        upload_date = unified_strdate(xpath_text(
+            video_node, './broadcastDate'))
+        thumbnail = xpath_text(video_node, './/teaserImage//variant/url')
 
         formats = []
         for a in video_node.findall('.//asset'):
index 8828161e58fb84401a824656b18fda7be7b71c1f..7536b3b364c5718380f9481fc5c5add87cc775a8 100644 (file)
@@ -304,6 +304,17 @@ def xpath_with_ns(path, ns_map):
     return '/'.join(replaced)
 
 
+def xpath_text(node, xpath, name=None, fatal=False):
+    n = node.find(xpath)
+    if n is None:
+        if fatal:
+            name = xpath if name is None else name
+            raise ExtractorError('Could not find XML element %s' % name)
+        else:
+            return None
+    return n.text
+
+
 compat_html_parser.locatestarttagend = re.compile(r"""<[a-zA-Z][-.a-zA-Z0-9:_]*(?:\s+(?:(?<=['"\s])[^\s/>][^\s/=>]*(?:\s*=+\s*(?:'[^']*'|"[^"]*"|(?!['"])[^>\s]*))?\s*)*)?\s*""", re.VERBOSE) # backport bugfix
 class BaseHTMLParser(compat_html_parser.HTMLParser):
     def __init(self):