]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/veoh.py
[ie/matchtv] Fix extractor (#10190)
[yt-dlp.git] / yt_dlp / extractor / veoh.py
index 70280ae850ba0bac5a9e5c509f183a6af920932c..dc1bf96ec6e759d6f34899f78b53a5f8f782200c 100644 (file)
@@ -1,9 +1,14 @@
+import functools
+import json
+
 from .common import InfoExtractor
 from ..utils import (
+    ExtractorError,
+    OnDemandPagedList,
     int_or_none,
     parse_duration,
     qualities,
-    try_get
+    try_get,
 )
 
 
@@ -75,7 +80,7 @@ class VeohIE(InfoExtractor):
             'age_limit': 18,
             'categories': ['technology_and_gaming', 'gaming'],
             'tags': ['puzzle', 'of', 'flesh'],
-        }
+        },
     }]
 
     def _real_extract(self, url):
@@ -100,7 +105,6 @@ def _real_extract(self, url):
                     'quality': q(f_id),
                     'url': f_url,
                 })
-        self._sort_formats(formats)
 
         categories = metadata.get('categoryPath')
         if not categories:
@@ -123,3 +127,62 @@ def _real_extract(self, url):
             'categories': categories,
             'tags': tags.split(', ') if tags else None,
         }
+
+
+class VeohUserIE(VeohIE):  # XXX: Do not subclass from concrete IE
+    _VALID_URL = r'https?://(?:www\.)?veoh\.com/users/(?P<id>[\w-]+)'
+    IE_NAME = 'veoh:user'
+
+    _TESTS = [
+        {
+            'url': 'https://www.veoh.com/users/valentinazoe',
+            'info_dict': {
+                'id': 'valentinazoe',
+                'title': 'valentinazoe (Uploads)',
+            },
+            'playlist_mincount': 75,
+        },
+        {
+            'url': 'https://www.veoh.com/users/PiensaLibre',
+            'info_dict': {
+                'id': 'PiensaLibre',
+                'title': 'PiensaLibre (Uploads)',
+            },
+            'playlist_mincount': 2,
+        }]
+
+    _PAGE_SIZE = 16
+
+    def _fetch_page(self, uploader, page):
+        response = self._download_json(
+            'https://www.veoh.com/users/published/videos', uploader,
+            note=f'Downloading videos page {page + 1}',
+            headers={
+                'x-csrf-token': self._TOKEN,
+                'content-type': 'application/json;charset=UTF-8',
+            },
+            data=json.dumps({
+                'username': uploader,
+                'maxResults': self._PAGE_SIZE,
+                'page': page + 1,
+                'requestName': 'userPage',
+            }).encode())
+        if not response.get('success'):
+            raise ExtractorError(response['message'])
+
+        for video in response['videos']:
+            yield self.url_result(f'https://www.veoh.com/watch/{video["permalinkId"]}', VeohIE,
+                                  video['permalinkId'], video.get('title'))
+
+    def _real_initialize(self):
+        webpage = self._download_webpage(
+            'https://www.veoh.com', None, note='Downloading authorization token')
+        self._TOKEN = self._search_regex(
+            r'csrfToken:\s*(["\'])(?P<token>[0-9a-zA-Z]{40})\1', webpage,
+            'request token', group='token')
+
+    def _real_extract(self, url):
+        uploader = self._match_id(url)
+        return self.playlist_result(OnDemandPagedList(
+            functools.partial(self._fetch_page, uploader),
+            self._PAGE_SIZE), uploader, f'{uploader} (Uploads)')