Improve URL extraction
[youtube-dl] / youtube_dl / extractor / twitch.py
index ec96ae5064e759b8632620c4462a894cb9c6435c..89ee44224bb0b9cc066386ee3ef63d6e5f5481a3 100644 (file)
@@ -27,6 +27,7 @@ from ..utils import (
     unified_timestamp,
     update_url_query,
     urlencode_postdata,
+    url_or_none,
     urljoin,
 )
 
@@ -61,7 +62,7 @@ class TwitchBaseIE(InfoExtractor):
         self._login()
 
     def _login(self):
-        (username, password) = self._get_login_info()
+        username, password = self._get_login_info()
         if username is None:
             return
 
@@ -663,8 +664,8 @@ class TwitchClipsIE(TwitchBaseIE):
         for option in status['quality_options']:
             if not isinstance(option, dict):
                 continue
-            source = option.get('source')
-            if not source or not isinstance(source, compat_str):
+            source = url_or_none(option.get('source'))
+            if not source:
                 continue
             formats.append({
                 'url': source,
@@ -673,6 +674,8 @@ class TwitchClipsIE(TwitchBaseIE):
                 'fps': int_or_none(option.get('frame_rate')),
             })
 
+        self._sort_formats(formats)
+
         info = {
             'formats': formats,
         }