]>
Commit | Line | Data |
---|---|---|
aec74dd9 PH |
1 | from __future__ import unicode_literals |
2 | ||
3 | import re | |
4 | ||
5 | from .common import InfoExtractor | |
1cc79574 | 6 | from ..compat import ( |
aec74dd9 | 7 | compat_urllib_parse_urlparse, |
1cc79574 PH |
8 | ) |
9 | from ..utils import ( | |
59c03a9b | 10 | ExtractorError, |
aec74dd9 PH |
11 | parse_duration, |
12 | qualities, | |
13 | ) | |
14 | ||
15 | ||
16 | class VuClipIE(InfoExtractor): | |
f44e5d8b | 17 | _VALID_URL = r'http://(?:m\.)?vuclip\.com/w\?.*?cid=(?P<id>[0-9]+)' |
aec74dd9 PH |
18 | |
19 | _TEST = { | |
59c03a9b | 20 | 'url': 'http://m.vuclip.com/w?cid=922692425&fid=70295&z=1010&nvar&frm=index.html', |
aec74dd9 | 21 | 'info_dict': { |
59c03a9b | 22 | 'id': '922692425', |
aec74dd9 | 23 | 'ext': '3gp', |
59c03a9b PH |
24 | 'title': 'The Toy Soldiers - Hollywood Movie Trailer', |
25 | 'duration': 180, | |
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 | |
aec74dd9 | 49 | links_code = self._search_regex( |
59c03a9b PH |
50 | r'''(?xs) |
51 | (?: | |
5d8dcb53 | 52 | <img\s+src="[^"]*/play.gif".*?>| |
59c03a9b PH |
53 | <!--\ player\ end\ -->\s*</div><!--\ thumb\ end--> |
54 | ) | |
55 | (.*?) | |
56 | (?: | |
2d29ac4f | 57 | <a\s+href="fblike|<div\s+class="social"> |
59c03a9b PH |
58 | ) |
59 | ''', webpage, 'links') | |
aec74dd9 PH |
60 | title = self._html_search_regex( |
61 | r'<title>(.*?)-\s*Vuclip</title>', webpage, 'title').strip() | |
62 | ||
63 | quality_order = qualities(['Reg', 'Hi']) | |
64 | formats = [] | |
65 | for url, q in re.findall( | |
59c03a9b | 66 | r'<a\s+href="(?P<url>[^"]+)".*?>(?:<button[^>]*>)?(?P<q>[^<]+)(?:</button>)?</a>', links_code): |
aec74dd9 PH |
67 | format_id = compat_urllib_parse_urlparse(url).scheme + '-' + q |
68 | formats.append({ | |
69 | 'format_id': format_id, | |
70 | 'url': url, | |
71 | 'quality': quality_order(q), | |
72 | }) | |
73 | self._sort_formats(formats) | |
74 | ||
75 | duration = parse_duration(self._search_regex( | |
59c03a9b | 76 | r'\(([0-9:]+)\)</span>', webpage, 'duration', fatal=False)) |
aec74dd9 PH |
77 | |
78 | return { | |
79 | 'id': video_id, | |
80 | 'formats': formats, | |
81 | 'title': title, | |
82 | 'duration': duration, | |
83 | } |