]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/ninecninemedia.py
Prepare to release.
[youtubedl] / youtube_dl / extractor / ninecninemedia.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 parse_iso8601,
9 float_or_none,
10 ExtractorError,
11 int_or_none,
12 )
13
14
15 class NineCNineMediaIE(InfoExtractor):
16 IE_NAME = '9c9media'
17 _GEO_COUNTRIES = ['CA']
18 _VALID_URL = r'9c9media:(?P<destination_code>[^:]+):(?P<id>\d+)'
19 _API_BASE_TEMPLATE = 'http://capi.9c9media.com/destinations/%s/platforms/desktop/contents/%s/'
20
21 def _real_extract(self, url):
22 destination_code, content_id = re.match(self._VALID_URL, url).groups()
23 api_base_url = self._API_BASE_TEMPLATE % (destination_code, content_id)
24 content = self._download_json(api_base_url, content_id, query={
25 '$include': '[Media,Season,ContentPackages]',
26 })
27 title = content['Name']
28 if len(content['ContentPackages']) > 1:
29 raise ExtractorError('multiple content packages')
30 content_package = content['ContentPackages'][0]
31 package_id = content_package['Id']
32 content_package_url = api_base_url + 'contentpackages/%s/' % package_id
33 content_package = self._download_json(
34 content_package_url, content_id, query={
35 '$include': '[HasClosedCaptions]',
36 })
37
38 if content_package.get('Constraints', {}).get('Security', {}).get('Type'):
39 raise ExtractorError('This video is DRM protected.', expected=True)
40
41 manifest_base_url = content_package_url + 'manifest.'
42 formats = []
43 formats.extend(self._extract_m3u8_formats(
44 manifest_base_url + 'm3u8', content_id, 'mp4',
45 'm3u8_native', m3u8_id='hls', fatal=False))
46 formats.extend(self._extract_f4m_formats(
47 manifest_base_url + 'f4m', content_id,
48 f4m_id='hds', fatal=False))
49 formats.extend(self._extract_mpd_formats(
50 manifest_base_url + 'mpd', content_id,
51 mpd_id='dash', fatal=False))
52 self._sort_formats(formats)
53
54 thumbnails = []
55 for image in content.get('Images', []):
56 image_url = image.get('Url')
57 if not image_url:
58 continue
59 thumbnails.append({
60 'url': image_url,
61 'width': int_or_none(image.get('Width')),
62 'height': int_or_none(image.get('Height')),
63 })
64
65 tags, categories = [], []
66 for source_name, container in (('Tags', tags), ('Genres', categories)):
67 for e in content.get(source_name, []):
68 e_name = e.get('Name')
69 if not e_name:
70 continue
71 container.append(e_name)
72
73 season = content.get('Season', {})
74
75 info = {
76 'id': content_id,
77 'title': title,
78 'description': content.get('Desc') or content.get('ShortDesc'),
79 'timestamp': parse_iso8601(content.get('BroadcastDateTime')),
80 'episode_number': int_or_none(content.get('Episode')),
81 'season': season.get('Name'),
82 'season_number': season.get('Number'),
83 'season_id': season.get('Id'),
84 'series': content.get('Media', {}).get('Name'),
85 'tags': tags,
86 'categories': categories,
87 'duration': float_or_none(content_package.get('Duration')),
88 'formats': formats,
89 }
90
91 if content_package.get('HasClosedCaptions'):
92 info['subtitles'] = {
93 'en': [{
94 'url': manifest_base_url + 'vtt',
95 'ext': 'vtt',
96 }, {
97 'url': manifest_base_url + 'srt',
98 'ext': 'srt',
99 }]
100 }
101
102 return info