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