]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/cliphunter.py
Merge remote-tracking branch 'lenaten/8tracks'
[yt-dlp.git] / youtube_dl / extractor / cliphunter.py
CommitLineData
efc86777
PH
1from __future__ import unicode_literals
2
f54aee02 3import json
008af866 4import re
008af866
P
5
6from .common import InfoExtractor
d55433bb 7
008af866 8
f54aee02 9_translation_table = {
b6d3a996
PH
10 'a': 'h', 'd': 'e', 'e': 'v', 'f': 'o', 'g': 'f', 'i': 'd', 'l': 'n',
11 'm': 'a', 'n': 'm', 'p': 'u', 'q': 't', 'r': 's', 'v': 'p', 'x': 'r',
12 'y': 'l', 'z': 'i',
13 '$': ':', '&': '.', '(': '=', '^': '&', '=': '/',
14}
008af866
P
15
16
f54aee02
PH
17def _decode(s):
18 return ''.join(_translation_table.get(c, c) for c in s)
19
20
008af866 21class CliphunterIE(InfoExtractor):
efc86777 22 IE_NAME = 'cliphunter'
008af866 23
b6d3a996
PH
24 _VALID_URL = r'''(?x)http://(?:www\.)?cliphunter\.com/w/
25 (?P<id>[0-9]+)/
26 (?P<seo>.+?)(?:$|[#\?])
27 '''
28 _TEST = {
efc86777 29 'url': 'http://www.cliphunter.com/w/1012420/Fun_Jynx_Maze_solo',
f54aee02 30 'md5': 'a2ba71eebf523859fe527a61018f723e',
efc86777 31 'info_dict': {
f54aee02
PH
32 'id': '1012420',
33 'ext': 'mp4',
efc86777 34 'title': 'Fun Jynx Maze solo',
f54aee02
PH
35 'thumbnail': 're:^https?://.*\.jpg$',
36 'age_limit': 18,
008af866 37 }
efc86777 38 }
008af866
P
39
40 def _real_extract(self, url):
c9f08154 41 video_id = self._match_id(url)
008af866
P
42 webpage = self._download_webpage(url, video_id)
43
f54aee02
PH
44 video_title = self._search_regex(
45 r'mediaTitle = "([^"]+)"', webpage, 'title')
46
b6d3a996
PH
47 pl_fiji = self._search_regex(
48 r'pl_fiji = \'([^\']+)\'', webpage, 'video data')
49 pl_c_qual = self._search_regex(
50 r'pl_c_qual = "(.)"', webpage, 'video quality')
f54aee02 51 video_url = _decode(pl_fiji)
008af866
P
52 formats = [{
53 'url': video_url,
f54aee02 54 'format_id': 'default-%s' % pl_c_qual,
008af866
P
55 }]
56
f54aee02
PH
57 qualities_json = self._search_regex(
58 r'var pl_qualities\s*=\s*(.*?);\n', webpage, 'quality info')
59 qualities_data = json.loads(qualities_json)
60
61 for i, t in enumerate(
62 re.findall(r"pl_fiji_([a-z0-9]+)\s*=\s*'([^']+')", webpage)):
63 quality_id, crypted_url = t
64 video_url = _decode(crypted_url)
65 f = {
66 'format_id': quality_id,
67 'url': video_url,
68 'quality': i,
69 }
70 if quality_id in qualities_data:
71 qd = qualities_data[quality_id]
72 m = re.match(
73 r'''(?x)<b>(?P<width>[0-9]+)x(?P<height>[0-9]+)<\\/b>
74 \s*\(\s*(?P<tbr>[0-9]+)\s*kb\\/s''', qd)
75 if m:
76 f['width'] = int(m.group('width'))
77 f['height'] = int(m.group('height'))
78 f['tbr'] = int(m.group('tbr'))
79 formats.append(f)
80 self._sort_formats(formats)
81
82 thumbnail = self._search_regex(
83 r"var\s+mov_thumb\s*=\s*'([^']+)';",
84 webpage, 'thumbnail', fatal=False)
f54aee02 85
008af866
P
86 return {
87 'id': video_id,
88 'title': video_title,
89 'formats': formats,
f54aee02
PH
90 'age_limit': self._rta_search(webpage),
91 'thumbnail': thumbnail,
008af866 92 }