aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/extractor/cliphunter.py
blob: d891fa3012c7bf7e2fe59838002a014b7c0fb8bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from __future__ import unicode_literals

import re
import string

from .common import InfoExtractor
from ..utils import (
    ExtractorError,
)

translation_table = {
    'a': 'h', 'd': 'e', 'e': 'v', 'f': 'o', 'g': 'f', 'i': 'd', 'l': 'n',
    'm': 'a', 'n': 'm', 'p': 'u', 'q': 't', 'r': 's', 'v': 'p', 'x': 'r',
    'y': 'l', 'z': 'i',
    '$': ':', '&': '.', '(': '=', '^': '&', '=': '/',
}


class CliphunterIE(InfoExtractor):
    IE_NAME = 'cliphunter'

    _VALID_URL = r'''(?x)http://(?:www\.)?cliphunter\.com/w/
        (?P<id>[0-9]+)/
        (?P<seo>.+?)(?:$|[#\?])
    '''
    _TEST = {
        'url': 'http://www.cliphunter.com/w/1012420/Fun_Jynx_Maze_solo',
        'file': '1012420.flv',
        'md5': '15e7740f30428abf70f4223478dc1225',
        'info_dict': {
            'title': 'Fun Jynx Maze solo',
        }
    }

    def _real_extract(self, url):
        mobj = re.match(self._VALID_URL, url)
        video_id = mobj.group('id')

        webpage = self._download_webpage(url, video_id)

        pl_fiji = self._search_regex(
            r'pl_fiji = \'([^\']+)\'', webpage, 'video data')
        pl_c_qual = self._search_regex(
            r'pl_c_qual = "(.)"', webpage, 'video quality')
        video_title = self._search_regex(
            r'mediaTitle = "([^"]+)"', webpage, 'title')

        video_url = ''.join(translation_table.get(c, c) for c in pl_fiji)

        formats = [{
            'url': video_url,
            'format_id': pl_c_qual,
        }]

        return {
            'id': video_id,
            'title': video_title,
            'formats': formats,
        }