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