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