]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/vidlii.py
[ie/matchtv] Fix extractor (#10190)
[yt-dlp.git] / yt_dlp / extractor / vidlii.py
index f4774256bd502ae6ce96699fd52f165e0e2600ff..d9e33ca9e58b9f60235ee1b79aa25918503cd350 100644 (file)
@@ -1,13 +1,13 @@
-# coding: utf-8
-from __future__ import unicode_literals
-
 import re
 
 from .common import InfoExtractor
+from ..networking import HEADRequest
 from ..utils import (
     float_or_none,
+    format_field,
     get_element_by_id,
     int_or_none,
+    str_to_int,
     strip_or_none,
     unified_strdate,
     urljoin,
@@ -34,7 +34,26 @@ class VidLiiIE(InfoExtractor):
             'average_rating': float,
             'categories': ['News & Politics'],
             'tags': ['Vidlii', 'Jan', 'Videogames'],
-        }
+        },
+    }, {
+        'url': 'https://www.vidlii.com/watch?v=zTAtaAgOLKt',
+        'md5': '5778f7366aa4c569b77002f8bf6b614f',
+        'info_dict': {
+            'id': 'zTAtaAgOLKt',
+            'ext': 'mp4',
+            'title': 'FULPTUBE SUCKS.',
+            'description': 'md5:087b2ca355d4c8f8f77e97c43e72d711',
+            'thumbnail': 'https://www.vidlii.com/usfi/thmp/zTAtaAgOLKt.jpg',
+            'uploader': 'Homicide',
+            'uploader_url': 'https://www.vidlii.com/user/Homicide',
+            'upload_date': '20210612',
+            'duration': 89,
+            'view_count': int,
+            'comment_count': int,
+            'average_rating': float,
+            'categories': ['News & Politics'],
+            'tags': ['fulp', 'tube', 'sucks', 'bad', 'fulptube'],
+        },
     }, {
         'url': 'https://www.vidlii.com/embed?v=tJluaH4BJ3v&a=0',
         'only_matching': True,
@@ -44,11 +63,21 @@ def _real_extract(self, url):
         video_id = self._match_id(url)
 
         webpage = self._download_webpage(
-            'https://www.vidlii.com/watch?v=%s' % video_id, video_id)
-
-        video_url = self._search_regex(
-            r'src\s*:\s*(["\'])(?P<url>(?:https?://)?(?:(?!\1).)+)\1', webpage,
-            'video url', group='url')
+            f'https://www.vidlii.com/watch?v={video_id}', video_id)
+        formats = []
+
+        sources = [source[1] for source in re.findall(
+            r'src\s*:\s*(["\'])(?P<url>(?:https?://)?(?:(?!\1).)+)\1',
+            webpage) or []]
+        for source in sources:
+            source = urljoin(url, source)
+            height = int(self._search_regex(r'(\d+).mp4', source, 'height', default=360))
+            if self._request_webpage(HEADRequest(source), video_id, f'Checking {height}p url', errnote=False):
+                formats.append({
+                    'url': source,
+                    'format_id': f'{height}p',
+                    'height': height,
+                })
 
         title = self._search_regex(
             (r'<h1>([^<]+)</h1>', r'<title>([^<]+) - VidLii<'), webpage,
@@ -71,7 +100,7 @@ def _real_extract(self, url):
         uploader = self._search_regex(
             r'<div[^>]+class=["\']wt_person[^>]+>\s*<a[^>]+\bhref=["\']/user/[^>]+>([^<]+)',
             webpage, 'uploader', fatal=False)
-        uploader_url = 'https://www.vidlii.com/user/%s' % uploader if uploader else None
+        uploader_url = format_field(uploader, None, 'https://www.vidlii.com/user/%s')
 
         upload_date = unified_strdate(self._html_search_meta(
             'datePublished', webpage, default=None) or self._search_regex(
@@ -82,9 +111,9 @@ def _real_extract(self, url):
             default=None) or self._search_regex(
             r'duration\s*:\s*(\d+)', webpage, 'duration', fatal=False))
 
-        view_count = int_or_none(self._search_regex(
-            (r'<strong>(\d+)</strong> views',
-             r'Views\s*:\s*<strong>(\d+)</strong>'),
+        view_count = str_to_int(self._search_regex(
+            (r'<strong>([,0-9]+)</strong> views',
+             r'Views\s*:\s*<strong>([,0-9]+)</strong>'),
             webpage, 'view count', fatal=False))
 
         comment_count = int_or_none(self._search_regex(
@@ -109,11 +138,11 @@ def _real_extract(self, url):
 
         return {
             'id': video_id,
-            'url': video_url,
             'title': title,
             'description': description,
             'thumbnail': thumbnail,
             'uploader': uploader,
+            'formats': formats,
             'uploader_url': uploader_url,
             'upload_date': upload_date,
             'duration': duration,