]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/vidio.py
[extractor/youtube] Fix live chat for videos with content warning
[yt-dlp.git] / yt_dlp / extractor / vidio.py
index b9ee67d20e7a111c1d83990779468b2792230d2f..599996bf95dae48235e7d4e2d2510313fac6d507 100644 (file)
@@ -1,12 +1,8 @@
-# coding: utf-8
-from __future__ import unicode_literals
-
-import re
-
 from .common import InfoExtractor
 from ..utils import (
     clean_html,
     ExtractorError,
+    format_field,
     get_element_by_class,
     int_or_none,
     parse_iso8601,
@@ -23,11 +19,7 @@ class VidioBaseIE(InfoExtractor):
     _LOGIN_URL = 'https://www.vidio.com/users/login'
     _NETRC_MACHINE = 'vidio'
 
-    def _login(self):
-        username, password = self._get_login_info()
-        if username is None:
-            return
-
+    def _perform_login(self, username, password):
         def is_logged_in():
             res = self._download_json(
                 'https://www.vidio.com/interactions.json', None, 'Checking if logged in', fatal=False) or {}
@@ -63,10 +55,9 @@ def is_logged_in():
                     'Unable to log in: %s. %s' % (reason, clean_html(subreason)), expected=True)
             raise ExtractorError('Unable to log in')
 
-    def _real_initialize(self):
+    def _initialize_pre_login(self):
         self._api_key = self._download_json(
             'https://www.vidio.com/auth', None, data=b'')['api_key']
-        self._login()
 
     def _call_api(self, url, video_id, note=None):
         return self._download_json(url, video_id, note=note, headers={
@@ -110,7 +101,7 @@ class VidioIE(VidioBaseIE):
     }]
 
     def _real_extract(self, url):
-        match = re.match(self._VALID_URL, url).groupdict()
+        match = self._match_valid_url(url).groupdict()
         video_id, display_id = match.get('id'), match.get('display_id')
         data = self._call_api('https://api.vidio.com/videos/' + video_id, display_id)
         video = data['videos'][0]
@@ -161,7 +152,7 @@ def _real_extract(self, url):
             'uploader': user.get('name'),
             'timestamp': parse_iso8601(video.get('created_at')),
             'uploader_id': username,
-            'uploader_url': 'https://www.vidio.com/@' + username if username else None,
+            'uploader_url': format_field(username, template='https://www.vidio.com/@%s'),
             'channel': channel.get('name'),
             'channel_id': str_or_none(channel.get('id')),
             'view_count': get_count('view_count'),
@@ -194,7 +185,7 @@ def _playlist_entries(self, playlist_url, display_id):
 
     def _real_extract(self, url):
         url, idata = unsmuggle_url(url, {})
-        playlist_id, display_id = re.match(self._VALID_URL, url).groups()
+        playlist_id, display_id = self._match_valid_url(url).groups()
 
         playlist_url = idata.get('url')
         if playlist_url:  # Smuggled data contains an API URL. Download only that playlist
@@ -236,7 +227,7 @@ class VidioLiveIE(VidioBaseIE):
     }]
 
     def _real_extract(self, url):
-        video_id, display_id = re.match(self._VALID_URL, url).groups()
+        video_id, display_id = self._match_valid_url(url).groups()
         stream_data = self._call_api(
             'https://www.vidio.com/api/livestreamings/%s/detail' % video_id, display_id)
         stream_meta = stream_data['livestreamings'][0]
@@ -248,8 +239,7 @@ def _real_extract(self, url):
         formats = []
         if stream_meta.get('is_drm'):
             if not self.get_param('allow_unplayable_formats'):
-                self.raise_no_formats(
-                    'This video is DRM protected.', expected=True)
+                self.report_drm(video_id)
         if stream_meta.get('is_premium'):
             sources = self._download_json(
                 'https://www.vidio.com/interactions_stream.json?video_id=%s&type=livestreamings' % video_id,
@@ -293,5 +283,5 @@ def _real_extract(self, url):
             'uploader': user.get('name'),
             'timestamp': parse_iso8601(stream_meta.get('start_time')),
             'uploader_id': username,
-            'uploader_url': 'https://www.vidio.com/@' + username if username else None,
+            'uploader_url': format_field(username, template='https://www.vidio.com/@%s'),
         }