]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/cliphunter.py
Update changelog.
[youtubedl] / youtube_dl / extractor / cliphunter.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..utils import int_or_none
5
6
7 _translation_table = {
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 }
13
14
15 def _decode(s):
16 return ''.join(_translation_table.get(c, c) for c in s)
17
18
19 class CliphunterIE(InfoExtractor):
20 IE_NAME = 'cliphunter'
21
22 _VALID_URL = r'''(?x)http://(?:www\.)?cliphunter\.com/w/
23 (?P<id>[0-9]+)/
24 (?P<seo>.+?)(?:$|[#\?])
25 '''
26 _TEST = {
27 'url': 'http://www.cliphunter.com/w/1012420/Fun_Jynx_Maze_solo',
28 'md5': 'b7c9bbd4eb3a226ab91093714dcaa480',
29 'info_dict': {
30 'id': '1012420',
31 'ext': 'flv',
32 'title': 'Fun Jynx Maze solo',
33 'thumbnail': 're:^https?://.*\.jpg$',
34 'age_limit': 18,
35 }
36 }
37
38 def _real_extract(self, url):
39 video_id = self._match_id(url)
40 webpage = self._download_webpage(url, video_id)
41
42 video_title = self._search_regex(
43 r'mediaTitle = "([^"]+)"', webpage, 'title')
44
45 gexo_files = self._parse_json(
46 self._search_regex(
47 r'var\s+gexoFiles\s*=\s*({.+?});', webpage, 'gexo files'),
48 video_id)
49
50 formats = []
51 for format_id, f in gexo_files.items():
52 video_url = f.get('url')
53 if not video_url:
54 continue
55 fmt = f.get('fmt')
56 height = f.get('h')
57 format_id = '%s_%sp' % (fmt, height) if fmt and height else format_id
58 formats.append({
59 'url': _decode(video_url),
60 'format_id': format_id,
61 'width': int_or_none(f.get('w')),
62 'height': int_or_none(height),
63 'tbr': int_or_none(f.get('br')),
64 })
65 self._sort_formats(formats)
66
67 thumbnail = self._search_regex(
68 r"var\s+mov_thumb\s*=\s*'([^']+)';",
69 webpage, 'thumbnail', fatal=False)
70
71 return {
72 'id': video_id,
73 'title': video_title,
74 'formats': formats,
75 'age_limit': self._rta_search(webpage),
76 'thumbnail': thumbnail,
77 }