]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/playvid.py
Allow extractors to specify section_start/end for clips
[yt-dlp.git] / yt_dlp / extractor / playvid.py
CommitLineData
4ea3137e
M
1import re
2
3from .common import InfoExtractor
1cc79574 4from ..compat import (
388ad0c0
S
5 compat_urllib_parse_unquote,
6 compat_urllib_parse_unquote_plus,
1cc79574 7)
4ea3137e 8from ..utils import (
e987e91f 9 clean_html,
1cc79574 10 ExtractorError,
4ea3137e
M
11)
12
4ea3137e 13
db95dc13 14class PlayvidIE(InfoExtractor):
92519402 15 _VALID_URL = r'https?://(?:www\.)?playvid\.com/watch(\?v=|/)(?P<id>.+?)(?:#|$)'
2a49d016 16 _TESTS = [{
1cc79574
PH
17 'url': 'http://www.playvid.com/watch/RnmBNgtrrJu',
18 'md5': 'ffa2f6b2119af359f544388d8c01eb6c',
4ea3137e 19 'info_dict': {
1cc79574 20 'id': 'RnmBNgtrrJu',
db95dc13 21 'ext': 'mp4',
1cc79574
PH
22 'title': 'md5:9256d01c6317e3f703848b5906880dc8',
23 'duration': 82,
4ea3137e 24 'age_limit': 18,
2a49d016
YCH
25 },
26 'skip': 'Video removed due to ToS',
27 }, {
28 'url': 'http://www.playvid.com/watch/hwb0GpNkzgH',
29 'md5': '39d49df503ad7b8f23a4432cbf046477',
30 'info_dict': {
31 'id': 'hwb0GpNkzgH',
32 'ext': 'mp4',
33 'title': 'Ellen Euro Cutie Blond Takes a Sexy Survey Get Facial in The Park',
34 'age_limit': 18,
ec85ded8 35 'thumbnail': r're:^https?://.*\.jpg$',
2a49d016
YCH
36 },
37 }]
4ea3137e
M
38
39 def _real_extract(self, url):
1cc79574 40 video_id = self._match_id(url)
4ea3137e
M
41 webpage = self._download_webpage(url, video_id)
42
e987e91f
S
43 m_error = re.search(
44 r'<div class="block-error">\s*<div class="heading">\s*<div>(?P<msg>.+?)</div>\s*</div>', webpage)
45 if m_error:
46 raise ExtractorError(clean_html(m_error.group('msg')), expected=True)
47
4ea3137e
M
48 video_title = None
49 duration = None
50 video_thumbnail = None
51 formats = []
52
53 # most of the information is stored in the flashvars
db95dc13
PH
54 flashvars = self._html_search_regex(
55 r'flashvars="(.+?)"', webpage, 'flashvars')
4ea3137e 56
388ad0c0 57 infos = compat_urllib_parse_unquote(flashvars).split(r'&')
db95dc13
PH
58 for info in infos:
59 videovars_match = re.match(r'^video_vars\[(.+?)\]=(.+?)$', info)
60 if videovars_match:
61 key = videovars_match.group(1)
62 val = videovars_match.group(2)
4ea3137e 63
db95dc13 64 if key == 'title':
388ad0c0 65 video_title = compat_urllib_parse_unquote_plus(val)
db95dc13
PH
66 if key == 'duration':
67 try:
68 duration = int(val)
69 except ValueError:
70 pass
71 if key == 'big_thumb':
72 video_thumbnail = val
4ea3137e 73
db95dc13
PH
74 videourl_match = re.match(
75 r'^video_urls\]\[(?P<resolution>[0-9]+)p', key)
76 if videourl_match:
77 height = int(videourl_match.group('resolution'))
78 formats.append({
79 'height': height,
80 'url': val,
81 })
82 self._sort_formats(formats)
4ea3137e
M
83
84 # Extract title - should be in the flashvars; if not, look elsewhere
85 if video_title is None:
04f3fd2c 86 video_title = self._html_extract_title(webpage)
4ea3137e
M
87
88 return {
89 'id': video_id,
90 'formats': formats,
91 'title': video_title,
92 'thumbnail': video_thumbnail,
93 'duration': duration,
94 'description': None,
95 'age_limit': 18
96 }