]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/cliphunter.py
2edab90a33d553225b8c790b8d391f0e40b55cf8
[youtubedl] / youtube_dl / extractor / cliphunter.py
1 from __future__ import unicode_literals
2
3 import json
4 import re
5
6 from .common import InfoExtractor
7
8
9 _translation_table = {
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 }
15
16
17 def _decode(s):
18 return ''.join(_translation_table.get(c, c) for c in s)
19
20
21 class CliphunterIE(InfoExtractor):
22 IE_NAME = 'cliphunter'
23
24 _VALID_URL = r'''(?x)http://(?:www\.)?cliphunter\.com/w/
25 (?P<id>[0-9]+)/
26 (?P<seo>.+?)(?:$|[#\?])
27 '''
28 _TEST = {
29 'url': 'http://www.cliphunter.com/w/1012420/Fun_Jynx_Maze_solo',
30 'md5': 'a2ba71eebf523859fe527a61018f723e',
31 'info_dict': {
32 'id': '1012420',
33 'ext': 'mp4',
34 'title': 'Fun Jynx Maze solo',
35 'thumbnail': 're:^https?://.*\.jpg$',
36 'age_limit': 18,
37 }
38 }
39
40 def _real_extract(self, url):
41 video_id = self._match_id(url)
42 webpage = self._download_webpage(url, video_id)
43
44 video_title = self._search_regex(
45 r'mediaTitle = "([^"]+)"', webpage, 'title')
46
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')
51 video_url = _decode(pl_fiji)
52 formats = [{
53 'url': video_url,
54 'format_id': 'default-%s' % pl_c_qual,
55 }]
56
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)
85
86 return {
87 'id': video_id,
88 'title': video_title,
89 'formats': formats,
90 'age_limit': self._rta_search(webpage),
91 'thumbnail': thumbnail,
92 }