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