[cleanup] Misc (#8968)
[yt-dlp.git] / yt_dlp / extractor / vidlii.py
blob44353b7fc45a19e6848dfa9364a57267a3ae652d
1 import re
3 from .common import InfoExtractor
4 from ..networking import HEADRequest
5 from ..utils import (
6 format_field,
7 float_or_none,
8 get_element_by_id,
9 int_or_none,
10 str_to_int,
11 strip_or_none,
12 unified_strdate,
13 urljoin,
17 class VidLiiIE(InfoExtractor):
18 _VALID_URL = r'https?://(?:www\.)?vidlii\.com/(?:watch|embed)\?.*?\bv=(?P<id>[0-9A-Za-z_-]{11})'
19 _TESTS = [{
20 'url': 'https://www.vidlii.com/watch?v=tJluaH4BJ3v',
21 'md5': '9bf7d1e005dfa909b6efb0a1ff5175e2',
22 'info_dict': {
23 'id': 'tJluaH4BJ3v',
24 'ext': 'mp4',
25 'title': 'Vidlii is against me',
26 'description': 'md5:fa3f119287a2bfb922623b52b1856145',
27 'thumbnail': 're:https://.*.jpg',
28 'uploader': 'APPle5auc31995',
29 'uploader_url': 'https://www.vidlii.com/user/APPle5auc31995',
30 'upload_date': '20171107',
31 'duration': 212,
32 'view_count': int,
33 'comment_count': int,
34 'average_rating': float,
35 'categories': ['News & Politics'],
36 'tags': ['Vidlii', 'Jan', 'Videogames'],
38 }, {
39 'url': 'https://www.vidlii.com/watch?v=zTAtaAgOLKt',
40 'md5': '5778f7366aa4c569b77002f8bf6b614f',
41 'info_dict': {
42 'id': 'zTAtaAgOLKt',
43 'ext': 'mp4',
44 'title': 'FULPTUBE SUCKS.',
45 'description': 'md5:087b2ca355d4c8f8f77e97c43e72d711',
46 'thumbnail': 'https://www.vidlii.com/usfi/thmp/zTAtaAgOLKt.jpg',
47 'uploader': 'Homicide',
48 'uploader_url': 'https://www.vidlii.com/user/Homicide',
49 'upload_date': '20210612',
50 'duration': 89,
51 'view_count': int,
52 'comment_count': int,
53 'average_rating': float,
54 'categories': ['News & Politics'],
55 'tags': ['fulp', 'tube', 'sucks', 'bad', 'fulptube'],
57 }, {
58 'url': 'https://www.vidlii.com/embed?v=tJluaH4BJ3v&a=0',
59 'only_matching': True,
62 def _real_extract(self, url):
63 video_id = self._match_id(url)
65 webpage = self._download_webpage(
66 'https://www.vidlii.com/watch?v=%s' % video_id, video_id)
67 formats = []
69 sources = [source[1] for source in re.findall(
70 r'src\s*:\s*(["\'])(?P<url>(?:https?://)?(?:(?!\1).)+)\1',
71 webpage) or []]
72 for source in sources:
73 source = urljoin(url, source)
74 height = int(self._search_regex(r'(\d+).mp4', source, 'height', default=360))
75 if self._request_webpage(HEADRequest(source), video_id, f'Checking {height}p url', errnote=False):
76 formats.append({
77 'url': source,
78 'format_id': f'{height}p',
79 'height': height,
82 title = self._search_regex(
83 (r'<h1>([^<]+)</h1>', r'<title>([^<]+) - VidLii<'), webpage,
84 'title')
86 description = self._html_search_meta(
87 ('description', 'twitter:description'), webpage,
88 default=None) or strip_or_none(
89 get_element_by_id('des_text', webpage))
91 thumbnail = self._html_search_meta(
92 'twitter:image', webpage, default=None)
93 if not thumbnail:
94 thumbnail_path = self._search_regex(
95 r'img\s*:\s*(["\'])(?P<url>(?:(?!\1).)+)\1', webpage,
96 'thumbnail', fatal=False, group='url')
97 if thumbnail_path:
98 thumbnail = urljoin(url, thumbnail_path)
100 uploader = self._search_regex(
101 r'<div[^>]+class=["\']wt_person[^>]+>\s*<a[^>]+\bhref=["\']/user/[^>]+>([^<]+)',
102 webpage, 'uploader', fatal=False)
103 uploader_url = format_field(uploader, None, 'https://www.vidlii.com/user/%s')
105 upload_date = unified_strdate(self._html_search_meta(
106 'datePublished', webpage, default=None) or self._search_regex(
107 r'<date>([^<]+)', webpage, 'upload date', fatal=False))
109 duration = int_or_none(self._html_search_meta(
110 'video:duration', webpage, 'duration',
111 default=None) or self._search_regex(
112 r'duration\s*:\s*(\d+)', webpage, 'duration', fatal=False))
114 view_count = str_to_int(self._search_regex(
115 (r'<strong>([,0-9]+)</strong> views',
116 r'Views\s*:\s*<strong>([,0-9]+)</strong>'),
117 webpage, 'view count', fatal=False))
119 comment_count = int_or_none(self._search_regex(
120 (r'<span[^>]+id=["\']cmt_num[^>]+>(\d+)',
121 r'Comments\s*:\s*<strong>(\d+)'),
122 webpage, 'comment count', fatal=False))
124 average_rating = float_or_none(self._search_regex(
125 r'rating\s*:\s*([\d.]+)', webpage, 'average rating', fatal=False))
127 category = self._html_search_regex(
128 r'<div>Category\s*:\s*</div>\s*<div>\s*<a[^>]+>([^<]+)', webpage,
129 'category', fatal=False)
130 categories = [category] if category else None
132 tags = [
133 strip_or_none(tag)
134 for tag in re.findall(
135 r'<a[^>]+\bhref=["\']/results\?.*?q=[^>]*>([^<]+)',
136 webpage) if strip_or_none(tag)
137 ] or None
139 return {
140 'id': video_id,
141 'title': title,
142 'description': description,
143 'thumbnail': thumbnail,
144 'uploader': uploader,
145 'formats': formats,
146 'uploader_url': uploader_url,
147 'upload_date': upload_date,
148 'duration': duration,
149 'view_count': view_count,
150 'comment_count': comment_count,
151 'average_rating': average_rating,
152 'categories': categories,
153 'tags': tags,