aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/extractor/onionstudios.py
blob: cf5c39e66b95052bd9d297232fb4fe51a966dcc2 (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
# coding: utf-8
from __future__ import unicode_literals

import re

from .common import InfoExtractor
from ..compat import compat_str
from ..utils import js_to_json


class OnionStudiosIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?onionstudios\.com/(?:video(?:s/[^/]+-|/)|embed\?.*\bid=)(?P<id>\d+)(?!-)'

    _TESTS = [{
        'url': 'http://www.onionstudios.com/videos/hannibal-charges-forward-stops-for-a-cocktail-2937',
        'md5': '5a118d466d62b5cd03647cf2c593977f',
        'info_dict': {
            'id': '3459881',
            'ext': 'mp4',
            'title': 'Hannibal charges forward, stops for a cocktail',
            'description': 'md5:545299bda6abf87e5ec666548c6a9448',
            'thumbnail': r're:^https?://.*\.jpg$',
            'uploader': 'a.v. club',
            'upload_date': '20150619',
            'timestamp': 1434728546,
        },
    }, {
        'url': 'http://www.onionstudios.com/embed?id=2855&autoplay=true',
        'only_matching': True,
    }, {
        'url': 'http://www.onionstudios.com/video/6139.json',
        'only_matching': True,
    }]

    @staticmethod
    def _extract_url(webpage):
        mobj = re.search(
            r'(?s)<(?:iframe|bulbs-video)[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?onionstudios\.com/(?:embed.+?|video/\d+\.json))\1', webpage)
        if mobj:
            return mobj.group('url')

    def _real_extract(self, url):
        video_id = self._match_id(url)

        webpage = self._download_webpage(
            'http://onionstudios.com/embed/dc94dc2899fe644c0e7241fa04c1b732.js',
            video_id)
        mcp_id = compat_str(self._parse_json(self._search_regex(
            r'window\.mcpMapping\s*=\s*({.+?});', webpage,
            'MCP Mapping'), video_id, js_to_json)[video_id]['mcp_id'])
        return self.url_result(
            'http://kinja.com/ajax/inset/iframe?id=mcp-' + mcp_id,
            'KinjaEmbed', mcp_id)