]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/aparat.py
[ie/crunchyroll] Fix stream extraction (#10005)
[yt-dlp.git] / yt_dlp / extractor / aparat.py
index da06a3cac2a0f3328013276266ddd7760e4cd19e..4a989d837b86da097e059ba6c3797cb354ece0dd 100644 (file)
@@ -1,6 +1,3 @@
-# coding: utf-8
-from __future__ import unicode_literals
-
 from .common import InfoExtractor
 from ..utils import (
     get_element_by_id,
@@ -13,6 +10,7 @@
 
 class AparatIE(InfoExtractor):
     _VALID_URL = r'https?://(?:www\.)?aparat\.com/(?:v/|video/video/embed/videohash/)(?P<id>[a-zA-Z0-9]+)'
+    _EMBED_REGEX = [r'<iframe .*?src="(?P<url>http://www\.aparat\.com/video/[^"]+)"']
 
     _TESTS = [{
         'url': 'http://www.aparat.com/v/wP8On',
@@ -33,19 +31,22 @@ class AparatIE(InfoExtractor):
         'only_matching': True,
     }]
 
+    def _parse_options(self, webpage, video_id, fatal=True):
+        return self._parse_json(self._search_regex(
+            r'options\s*=\s*({.+?})\s*;', webpage, 'options', default='{}'), video_id)
+
     def _real_extract(self, url):
         video_id = self._match_id(url)
 
-        # Provides more metadata
+        # If available, provides more metadata
         webpage = self._download_webpage(url, video_id, fatal=False)
+        options = self._parse_options(webpage, video_id, fatal=False)
 
-        if not webpage:
+        if not options:
             webpage = self._download_webpage(
                 'http://www.aparat.com/video/video/embed/vt/frame/showvideo/yes/videohash/' + video_id,
-                video_id)
-
-        options = self._parse_json(self._search_regex(
-            r'options\s*=\s*({.+?})\s*;', webpage, 'options'), video_id)
+                video_id, 'Downloading embed webpage')
+            options = self._parse_options(webpage, video_id)
 
         formats = []
         for sources in (options.get('multiSRC') or []):
@@ -72,7 +73,6 @@ def _real_extract(self, url):
                             r'(\d+)[pP]', label or '', 'height',
                             default=None)),
                     })
-        self._sort_formats(formats)
 
         info = self._search_json_ld(webpage, video_id, default={})