summary refs log tree commit diff
diff options
context:
space:
mode:
authorNaglis Jonaitis <njonaitis@gmail.com>2014-09-15 16:59:03 +0300
committerNaglis Jonaitis <njonaitis@gmail.com>2014-09-15 16:59:03 +0300
commitd0e8b3d59bbb0951a4bf7e85baca8c40d3824dd6 (patch)
tree2900c81a836078378d6b0e8d3d14b5fa6508e870
parentca0e7a2b17387c552c41afe705016b98d6677f51 (diff)
downloadyoutube-dl-d0e8b3d59bbb0951a4bf7e85baca8c40d3824dd6.tar.gz
youtube-dl-d0e8b3d59bbb0951a4bf7e85baca8c40d3824dd6.tar.xz
youtube-dl-d0e8b3d59bbb0951a4bf7e85baca8c40d3824dd6.zip
[nosvideo] Make more robust against missing metadata
-rw-r--r--youtube_dl/extractor/nosvideo.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/youtube_dl/extractor/nosvideo.py b/youtube_dl/extractor/nosvideo.py
index 8c2c428fc..f3be8f552 100644
--- a/youtube_dl/extractor/nosvideo.py
+++ b/youtube_dl/extractor/nosvideo.py
@@ -8,11 +8,11 @@ from ..utils import (
     ExtractorError,
     compat_urllib_request,
     urlencode_postdata,
+    xpath_text,
     xpath_with_ns,
 )
 
 _x = lambda p: xpath_with_ns(p, {'xspf': 'http://xspf.org/ns/0/'})
-_find = lambda el, p: el.find(_x(p)).text.strip()
 
 
 class NosVideoIE(InfoExtractor):
@@ -53,9 +53,15 @@ class NosVideoIE(InfoExtractor):
         playlist = self._download_xml(playlist_url, video_id)
 
         track = playlist.find(_x('.//xspf:track'))
-        title = _find(track, './xspf:title')
-        url = _find(track, './xspf:file')
-        thumbnail = _find(track, './xspf:image')
+        if track is None:
+            raise ExtractorError(
+                'XML playlist is missing the \'track\' element',
+                expected=True)
+        title = xpath_text(track, _x('./xspf:title'), 'title')
+        url = xpath_text(track, _x('./xspf:file'), 'URL', fatal=True)
+        thumbnail = xpath_text(track, _x('./xspf:image'), 'thumbnail')
+        if title is not None:
+            title = title.strip()
 
         formats = [{
             'format_id': 'sd',