]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/onionstudios.py
Update changelog.
[youtubedl] / 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 (
8 determine_ext,
9 int_or_none,
10 float_or_none,
11 mimetype2ext,
12 )
13
14
15 class OnionStudiosIE(InfoExtractor):
16 _VALID_URL = r'https?://(?:www\.)?onionstudios\.com/(?:video(?:s/[^/]+-|/)|embed\?.*\bid=)(?P<id>\d+)(?!-)'
17
18 _TESTS = [{
19 'url': 'http://www.onionstudios.com/videos/hannibal-charges-forward-stops-for-a-cocktail-2937',
20 'md5': '719d1f8c32094b8c33902c17bcae5e34',
21 'info_dict': {
22 'id': '2937',
23 'ext': 'mp4',
24 'title': 'Hannibal charges forward, stops for a cocktail',
25 'thumbnail': r're:^https?://.*\.jpg$',
26 'uploader': 'The A.V. Club',
27 'uploader_id': 'the-av-club',
28 },
29 }, {
30 'url': 'http://www.onionstudios.com/embed?id=2855&autoplay=true',
31 'only_matching': True,
32 }, {
33 'url': 'http://www.onionstudios.com/video/6139.json',
34 'only_matching': True,
35 }]
36
37 @staticmethod
38 def _extract_url(webpage):
39 mobj = re.search(
40 r'(?s)<(?:iframe|bulbs-video)[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?onionstudios\.com/(?:embed.+?|video/\d+\.json))\1', webpage)
41 if mobj:
42 return mobj.group('url')
43
44 def _real_extract(self, url):
45 video_id = self._match_id(url)
46
47 video_data = self._download_json(
48 'http://www.onionstudios.com/video/%s.json' % video_id, video_id)
49
50 title = video_data['title']
51
52 formats = []
53 for source in video_data.get('sources', []):
54 source_url = source.get('url')
55 if not source_url:
56 continue
57 ext = mimetype2ext(source.get('content_type')) or determine_ext(source_url)
58 if ext == 'm3u8':
59 formats.extend(self._extract_m3u8_formats(
60 source_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
61 else:
62 tbr = int_or_none(source.get('bitrate'))
63 formats.append({
64 'format_id': ext + ('-%d' % tbr if tbr else ''),
65 'url': source_url,
66 'width': int_or_none(source.get('width')),
67 'tbr': tbr,
68 'ext': ext,
69 })
70 self._sort_formats(formats)
71
72 return {
73 'id': video_id,
74 'title': title,
75 'thumbnail': video_data.get('poster_url'),
76 'uploader': video_data.get('channel_name'),
77 'uploader_id': video_data.get('channel_slug'),
78 'duration': float_or_none(video_data.get('duration', 1000)),
79 'tags': video_data.get('tags'),
80 'formats': formats,
81 }