]>
Commit | Line | Data |
---|---|---|
4ea3137e M |
1 | from __future__ import unicode_literals |
2 | ||
3 | import re | |
4 | ||
5 | from .common import InfoExtractor | |
1cc79574 PH |
6 | from ..compat import ( |
7 | compat_urllib_parse, | |
8 | ) | |
4ea3137e | 9 | from ..utils import ( |
e987e91f | 10 | clean_html, |
1cc79574 | 11 | ExtractorError, |
4ea3137e M |
12 | ) |
13 | ||
4ea3137e | 14 | |
db95dc13 | 15 | class PlayvidIE(InfoExtractor): |
1cc79574 | 16 | _VALID_URL = r'https?://www\.playvid\.com/watch(\?v=|/)(?P<id>.+?)(?:#|$)' |
4ea3137e | 17 | _TEST = { |
1cc79574 PH |
18 | 'url': 'http://www.playvid.com/watch/RnmBNgtrrJu', |
19 | 'md5': 'ffa2f6b2119af359f544388d8c01eb6c', | |
4ea3137e | 20 | 'info_dict': { |
1cc79574 | 21 | 'id': 'RnmBNgtrrJu', |
db95dc13 | 22 | 'ext': 'mp4', |
1cc79574 PH |
23 | 'title': 'md5:9256d01c6317e3f703848b5906880dc8', |
24 | 'duration': 82, | |
4ea3137e M |
25 | 'age_limit': 18, |
26 | } | |
27 | } | |
28 | ||
29 | def _real_extract(self, url): | |
1cc79574 | 30 | video_id = self._match_id(url) |
4ea3137e M |
31 | webpage = self._download_webpage(url, video_id) |
32 | ||
e987e91f S |
33 | m_error = re.search( |
34 | r'<div class="block-error">\s*<div class="heading">\s*<div>(?P<msg>.+?)</div>\s*</div>', webpage) | |
35 | if m_error: | |
36 | raise ExtractorError(clean_html(m_error.group('msg')), expected=True) | |
37 | ||
4ea3137e M |
38 | video_title = None |
39 | duration = None | |
40 | video_thumbnail = None | |
41 | formats = [] | |
42 | ||
43 | # most of the information is stored in the flashvars | |
db95dc13 PH |
44 | flashvars = self._html_search_regex( |
45 | r'flashvars="(.+?)"', webpage, 'flashvars') | |
4ea3137e | 46 | |
db95dc13 PH |
47 | infos = compat_urllib_parse.unquote(flashvars).split(r'&') |
48 | for info in infos: | |
49 | videovars_match = re.match(r'^video_vars\[(.+?)\]=(.+?)$', info) | |
50 | if videovars_match: | |
51 | key = videovars_match.group(1) | |
52 | val = videovars_match.group(2) | |
4ea3137e | 53 | |
db95dc13 PH |
54 | if key == 'title': |
55 | video_title = compat_urllib_parse.unquote_plus(val) | |
56 | if key == 'duration': | |
57 | try: | |
58 | duration = int(val) | |
59 | except ValueError: | |
60 | pass | |
61 | if key == 'big_thumb': | |
62 | video_thumbnail = val | |
4ea3137e | 63 | |
db95dc13 PH |
64 | videourl_match = re.match( |
65 | r'^video_urls\]\[(?P<resolution>[0-9]+)p', key) | |
66 | if videourl_match: | |
67 | height = int(videourl_match.group('resolution')) | |
68 | formats.append({ | |
69 | 'height': height, | |
70 | 'url': val, | |
71 | }) | |
72 | self._sort_formats(formats) | |
4ea3137e M |
73 | |
74 | # Extract title - should be in the flashvars; if not, look elsewhere | |
75 | if video_title is None: | |
76 | video_title = self._html_search_regex( | |
77 | r'<title>(.*?)</title', webpage, 'title') | |
78 | ||
79 | return { | |
80 | 'id': video_id, | |
81 | 'formats': formats, | |
82 | 'title': video_title, | |
83 | 'thumbnail': video_thumbnail, | |
84 | 'duration': duration, | |
85 | 'description': None, | |
86 | 'age_limit': 18 | |
87 | } |