]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/vuclip.py
[ie/matchtv] Fix extractor (#10190)
[yt-dlp.git] / yt_dlp / extractor / vuclip.py
CommitLineData
aec74dd9 1import re
add96eb9 2import urllib.parse
aec74dd9
PH
3
4from .common import InfoExtractor
1cc79574 5from ..utils import (
59c03a9b 6 ExtractorError,
aec74dd9 7 parse_duration,
e2dbcaa1 8 remove_end,
aec74dd9
PH
9)
10
11
12class VuClipIE(InfoExtractor):
5886b38d 13 _VALID_URL = r'https?://(?:m\.)?vuclip\.com/w\?.*?cid=(?P<id>[0-9]+)'
aec74dd9
PH
14
15 _TEST = {
ecc90093 16 'url': 'http://m.vuclip.com/w?cid=1129900602&bu=8589892792&frm=w&z=34801&op=0&oc=843169247&section=recommend',
aec74dd9 17 'info_dict': {
ecc90093 18 'id': '1129900602',
aec74dd9 19 'ext': '3gp',
ecc90093
YCH
20 'title': 'Top 10 TV Convicts',
21 'duration': 733,
add96eb9 22 },
aec74dd9
PH
23 }
24
25 def _real_extract(self, url):
1cc79574 26 video_id = self._match_id(url)
a7a747d6 27 webpage = self._download_webpage(url, video_id)
1cc79574 28
aec74dd9
PH
29 ad_m = re.search(
30 r'''value="No.*?" onClick="location.href='([^"']+)'"''', webpage)
31 if ad_m:
add96eb9 32 urlr = urllib.parse.urlparse(url)
aec74dd9
PH
33 adfree_url = urlr.scheme + '://' + urlr.netloc + ad_m.group(1)
34 webpage = self._download_webpage(
35 adfree_url, video_id, note='Download post-ad page')
36
59c03a9b
PH
37 error_msg = self._html_search_regex(
38 r'<p class="message">(.*?)</p>', webpage, 'error message',
39 default=None)
40 if error_msg:
41 raise ExtractorError(
add96eb9 42 f'{self.IE_NAME} said: {error_msg}', expected=True)
59c03a9b
PH
43
44 # These clowns alternate between two page types
e2dbcaa1
YCH
45 video_url = self._search_regex(
46 r'<a[^>]+href="([^"]+)"[^>]*><img[^>]+src="[^"]*/play\.gif',
47 webpage, 'video URL', default=None)
48 if video_url:
49 formats = [{
50 'url': video_url,
51 }]
52 else:
ecc90093 53 formats = self._parse_html5_media_entries(url, webpage, video_id)[0]['formats']
aec74dd9 54
e2dbcaa1
YCH
55 title = remove_end(self._html_search_regex(
56 r'<title>(.*?)-\s*Vuclip</title>', webpage, 'title').strip(), ' - Video')
aec74dd9 57
e2dbcaa1
YCH
58 duration = parse_duration(self._html_search_regex(
59 r'[(>]([0-9]+:[0-9]+)(?:<span|\))', webpage, 'duration', fatal=False))
aec74dd9
PH
60
61 return {
62 'id': video_id,
63 'formats': formats,
64 'title': title,
65 'duration': duration,
66 }