]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/vidlii.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / vidlii.py
CommitLineData
8c73ef37
S
1import re
2
3from .common import InfoExtractor
4from ..utils import (
7333296f 5 HEADRequest,
e0ddbd02 6 format_field,
8c73ef37
S
7 float_or_none,
8 get_element_by_id,
9 int_or_none,
7333296f 10 str_to_int,
8c73ef37
S
11 strip_or_none,
12 unified_strdate,
13 urljoin,
14)
15
16
17class 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'],
37 }
7333296f
P
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'],
56 },
8c73ef37
S
57 }, {
58 'url': 'https://www.vidlii.com/embed?v=tJluaH4BJ3v&a=0',
59 'only_matching': True,
60 }]
61
62 def _real_extract(self, url):
63 video_id = self._match_id(url)
64
65 webpage = self._download_webpage(
66 'https://www.vidlii.com/watch?v=%s' % video_id, video_id)
7333296f
P
67 formats = []
68
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 height = int(self._search_regex(r'(\d+).mp4', source, 'height', default=360))
74 if self._request_webpage(HEADRequest(source), video_id, f'Checking {height}p url', errnote=False):
75 formats.append({
76 'url': source,
77 'format_id': f'{height}p',
78 'height': height,
79 })
8c73ef37
S
80
81 title = self._search_regex(
82 (r'<h1>([^<]+)</h1>', r'<title>([^<]+) - VidLii<'), webpage,
83 'title')
84
85 description = self._html_search_meta(
86 ('description', 'twitter:description'), webpage,
87 default=None) or strip_or_none(
88 get_element_by_id('des_text', webpage))
89
90 thumbnail = self._html_search_meta(
91 'twitter:image', webpage, default=None)
92 if not thumbnail:
93 thumbnail_path = self._search_regex(
94 r'img\s*:\s*(["\'])(?P<url>(?:(?!\1).)+)\1', webpage,
95 'thumbnail', fatal=False, group='url')
96 if thumbnail_path:
97 thumbnail = urljoin(url, thumbnail_path)
98
99 uploader = self._search_regex(
100 r'<div[^>]+class=["\']wt_person[^>]+>\s*<a[^>]+\bhref=["\']/user/[^>]+>([^<]+)',
101 webpage, 'uploader', fatal=False)
a70635b8 102 uploader_url = format_field(uploader, None, 'https://www.vidlii.com/user/%s')
8c73ef37
S
103
104 upload_date = unified_strdate(self._html_search_meta(
105 'datePublished', webpage, default=None) or self._search_regex(
106 r'<date>([^<]+)', webpage, 'upload date', fatal=False))
107
108 duration = int_or_none(self._html_search_meta(
109 'video:duration', webpage, 'duration',
110 default=None) or self._search_regex(
111 r'duration\s*:\s*(\d+)', webpage, 'duration', fatal=False))
112
7333296f
P
113 view_count = str_to_int(self._search_regex(
114 (r'<strong>([,0-9]+)</strong> views',
115 r'Views\s*:\s*<strong>([,0-9]+)</strong>'),
8c73ef37
S
116 webpage, 'view count', fatal=False))
117
118 comment_count = int_or_none(self._search_regex(
119 (r'<span[^>]+id=["\']cmt_num[^>]+>(\d+)',
120 r'Comments\s*:\s*<strong>(\d+)'),
121 webpage, 'comment count', fatal=False))
122
123 average_rating = float_or_none(self._search_regex(
124 r'rating\s*:\s*([\d.]+)', webpage, 'average rating', fatal=False))
125
126 category = self._html_search_regex(
127 r'<div>Category\s*:\s*</div>\s*<div>\s*<a[^>]+>([^<]+)', webpage,
128 'category', fatal=False)
129 categories = [category] if category else None
130
131 tags = [
132 strip_or_none(tag)
133 for tag in re.findall(
134 r'<a[^>]+\bhref=["\']/results\?.*?q=[^>]*>([^<]+)',
135 webpage) if strip_or_none(tag)
136 ] or None
137
138 return {
139 'id': video_id,
8c73ef37
S
140 'title': title,
141 'description': description,
142 'thumbnail': thumbnail,
143 'uploader': uploader,
7333296f 144 'formats': formats,
8c73ef37
S
145 'uploader_url': uploader_url,
146 'upload_date': upload_date,
147 'duration': duration,
148 'view_count': view_count,
149 'comment_count': comment_count,
150 'average_rating': average_rating,
151 'categories': categories,
152 'tags': tags,
153 }