]> gitweb @ CieloNegro.org - youtube-dl.git/blob - youtube_dl/extractor/onionstudios.py
[fox] Add new extractor(closes #3063)
[youtube-dl.git] / youtube_dl / extractor / onionstudios.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import determine_ext
8
9
10 class OnionStudiosIE(InfoExtractor):
11     _VALID_URL = r'https?://(?:www\.)?onionstudios\.com/(?:videos/[^/]+-|embed\?.*\bid=)(?P<id>\d+)(?!-)'
12
13     _TESTS = [{
14         'url': 'http://www.onionstudios.com/videos/hannibal-charges-forward-stops-for-a-cocktail-2937',
15         'md5': 'd4851405d31adfadf71cd7a487b765bb',
16         'info_dict': {
17             'id': '2937',
18             'ext': 'mp4',
19             'title': 'Hannibal charges forward, stops for a cocktail',
20             'description': 'md5:545299bda6abf87e5ec666548c6a9448',
21             'thumbnail': 're:^https?://.*\.jpg$',
22             'uploader': 'The A.V. Club',
23             'uploader_id': 'TheAVClub',
24         },
25     }, {
26         'url': 'http://www.onionstudios.com/embed?id=2855&autoplay=true',
27         'only_matching': True,
28     }]
29
30     @staticmethod
31     def _extract_url(webpage):
32         mobj = re.search(
33             r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?onionstudios\.com/embed.+?)\1', webpage)
34         if mobj:
35             return mobj.group('url')
36
37     def _real_extract(self, url):
38         video_id = self._match_id(url)
39
40         webpage = self._download_webpage(
41             'http://www.onionstudios.com/embed?id=%s' % video_id, video_id)
42
43         formats = []
44         for src in re.findall(r'<source[^>]+src="([^"]+)"', webpage):
45             if determine_ext(src) != 'm3u8':  # m3u8 always results in 403
46                 formats.append({
47                     'url': src,
48                 })
49         self._sort_formats(formats)
50
51         title = self._search_regex(
52             r'share_title\s*=\s*(["\'])(?P<title>[^\1]+?)\1',
53             webpage, 'title', group='title')
54         description = self._search_regex(
55             r'share_description\s*=\s*(["\'])(?P<description>[^\1]+?)\1',
56             webpage, 'description', default=None, group='description')
57         thumbnail = self._search_regex(
58             r'poster\s*=\s*(["\'])(?P<thumbnail>[^\1]+?)\1',
59             webpage, 'thumbnail', default=False, group='thumbnail')
60
61         uploader_id = self._search_regex(
62             r'twitter_handle\s*=\s*(["\'])(?P<uploader_id>[^\1]+?)\1',
63             webpage, 'uploader id', fatal=False, group='uploader_id')
64         uploader = self._search_regex(
65             r'window\.channelName\s*=\s*(["\'])Embedded:(?P<uploader>[^\1]+?)\1',
66             webpage, 'uploader', default=False, group='uploader')
67
68         return {
69             'id': video_id,
70             'title': title,
71             'description': description,
72             'thumbnail': thumbnail,
73             'uploader': uploader,
74             'uploader_id': uploader_id,
75             'formats': formats,
76         }