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