Merge remote-tracking branch 'epitron/metadata-pp'
[youtube-dl] / youtube_dl / extractor / ivi.py
index 10279478bacdf82169b62e7cfb3d518dcb4fe326..98d1d272a6bb5085dadae9c8233a0e2592571636 100644 (file)
@@ -13,7 +13,7 @@ from ..utils import (
 class IviIE(InfoExtractor):
     IE_DESC = u'ivi.ru'
     IE_NAME = u'ivi'
-    _VALID_URL = r'^https?://(?:www\.)?(?P<url>ivi\.ru/watch(?:/(?P<compilationid>[^/]+))?/(?P<videoid>\d+))'
+    _VALID_URL = r'^https?://(?:www\.)?ivi\.ru/watch(?:/(?P<compilationid>[^/]+))?/(?P<videoid>\d+)'
 
     _TESTS = [
         # Single movie
@@ -84,14 +84,16 @@ class IviIE(InfoExtractor):
 
         result = video_json[u'result']
 
-        formats = [{'url': x[u'url'],
-                    'format_id': x[u'content_format']
-                    } for x in result[u'files'] if x[u'content_format'] in self._known_formats]
-        formats.sort(key=lambda fmt: self._known_formats.index(fmt['format_id']))
+        formats = [{
+            'url': x[u'url'],
+            'format_id': x[u'content_format'],
+            'preference': self._known_formats.index(x[u'content_format']),
+        } for x in result[u'files'] if x[u'content_format'] in self._known_formats]
 
-        if len(formats) == 0:
-            self._downloader.report_warning(u'No media links available for %s' % video_id)
-            return
+        self._sort_formats(formats)
+
+        if not formats:
+            raise ExtractorError(u'No media links available for %s' % video_id)
 
         duration = result[u'duration']
         compilation = result[u'compilation']
@@ -103,9 +105,7 @@ class IviIE(InfoExtractor):
         previews.sort(key=lambda fmt: self._known_thumbnails.index(fmt['content_format']))
         thumbnail = previews[-1][u'url'] if len(previews) > 0 else None
 
-        video_page_url = 'http://' + mobj.group('url')
-        video_page = self._download_webpage(video_page_url, video_id, u'Downloading video page')
-
+        video_page = self._download_webpage(url, video_id, u'Downloading video page')
         description = self._extract_description(video_page)
         comment_count = self._extract_comment_count(video_page)