]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/playvid.py
cd3905acb0fcd0ef9fe08beec2bda41fd2f94f70
[youtubedl] / youtube_dl / extractor / playvid.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7 ExtractorError,
8 clean_html,
9 compat_urllib_parse,
10 )
11
12
13 class PlayvidIE(InfoExtractor):
14 _VALID_URL = r'^https?://www\.playvid\.com/watch(\?v=|/)(?P<id>.+?)(?:#|$)'
15 _TEST = {
16 'url': 'http://www.playvid.com/watch/agbDDi7WZTV',
17 'md5': '44930f8afa616efdf9482daf4fe53e1e',
18 'info_dict': {
19 'id': 'agbDDi7WZTV',
20 'ext': 'mp4',
21 'title': 'Michelle Lewin in Miami Beach',
22 'duration': 240,
23 'age_limit': 18,
24 }
25 }
26
27 def _real_extract(self, url):
28 mobj = re.match(self._VALID_URL, url)
29 video_id = mobj.group('id')
30
31 webpage = self._download_webpage(url, video_id)
32
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
38 video_title = None
39 duration = None
40 video_thumbnail = None
41 formats = []
42
43 # most of the information is stored in the flashvars
44 flashvars = self._html_search_regex(
45 r'flashvars="(.+?)"', webpage, 'flashvars')
46
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)
53
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
63
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)
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 }