]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/cliphunter.py
[vimeo:watchlater] Fix extraction (Closes #3886)
[yt-dlp.git] / youtube_dl / extractor / cliphunter.py
CommitLineData
efc86777
PH
1from __future__ import unicode_literals
2
008af866 3from .common import InfoExtractor
3e055aa5 4from ..utils import determine_ext
d55433bb 5
008af866 6
f54aee02 7_translation_table = {
b6d3a996
PH
8 'a': 'h', 'd': 'e', 'e': 'v', 'f': 'o', 'g': 'f', 'i': 'd', 'l': 'n',
9 'm': 'a', 'n': 'm', 'p': 'u', 'q': 't', 'r': 's', 'v': 'p', 'x': 'r',
10 'y': 'l', 'z': 'i',
11 '$': ':', '&': '.', '(': '=', '^': '&', '=': '/',
12}
008af866
P
13
14
f54aee02
PH
15def _decode(s):
16 return ''.join(_translation_table.get(c, c) for c in s)
17
18
008af866 19class CliphunterIE(InfoExtractor):
efc86777 20 IE_NAME = 'cliphunter'
008af866 21
b6d3a996
PH
22 _VALID_URL = r'''(?x)http://(?:www\.)?cliphunter\.com/w/
23 (?P<id>[0-9]+)/
24 (?P<seo>.+?)(?:$|[#\?])
25 '''
26 _TEST = {
efc86777 27 'url': 'http://www.cliphunter.com/w/1012420/Fun_Jynx_Maze_solo',
3e055aa5 28 'md5': 'b7c9bbd4eb3a226ab91093714dcaa480',
efc86777 29 'info_dict': {
f54aee02 30 'id': '1012420',
3e055aa5 31 'ext': 'flv',
efc86777 32 'title': 'Fun Jynx Maze solo',
f54aee02
PH
33 'thumbnail': 're:^https?://.*\.jpg$',
34 'age_limit': 18,
008af866 35 }
efc86777 36 }
008af866
P
37
38 def _real_extract(self, url):
c9f08154 39 video_id = self._match_id(url)
008af866
P
40 webpage = self._download_webpage(url, video_id)
41
f54aee02
PH
42 video_title = self._search_regex(
43 r'mediaTitle = "([^"]+)"', webpage, 'title')
44
3e055aa5
NJ
45 fmts = {}
46 for fmt in ('mp4', 'flv'):
47 fmt_list = self._parse_json(self._search_regex(
48 r'var %sjson\s*=\s*(\[.*?\]);' % fmt, webpage, '%s formats' % fmt), video_id)
49 for f in fmt_list:
50 fmts[f['fname']] = _decode(f['sUrl'])
51
52 qualities = self._parse_json(self._search_regex(
53 r'var player_btns\s*=\s*(.*?);\n', webpage, 'quality info'), video_id)
54
55 formats = []
56 for fname, url in fmts.items():
f54aee02 57 f = {
3e055aa5 58 'url': url,
f54aee02 59 }
3e055aa5
NJ
60 if fname in qualities:
61 qual = qualities[fname]
62 f.update({
63 'format_id': '%s_%sp' % (determine_ext(url), qual['h']),
64 'width': qual['w'],
65 'height': qual['h'],
66 'tbr': qual['br'],
67 })
f54aee02 68 formats.append(f)
3e055aa5 69
f54aee02
PH
70 self._sort_formats(formats)
71
72 thumbnail = self._search_regex(
73 r"var\s+mov_thumb\s*=\s*'([^']+)';",
74 webpage, 'thumbnail', fatal=False)
f54aee02 75
008af866
P
76 return {
77 'id': video_id,
78 'title': video_title,
79 'formats': formats,
f54aee02
PH
80 'age_limit': self._rta_search(webpage),
81 'thumbnail': thumbnail,
008af866 82 }