]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/ninecninemedia.py
Add support for zsh completion.
[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 parse_duration,
10 ExtractorError
11 )
12
13
14 class NineCNineMediaIE(InfoExtractor):
15 _VALID_URL = r'9c9media:(?P<destination_code>[^:]+):(?P<id>\d+)'
16
17 def _real_extract(self, url):
18 destination_code, video_id = re.match(self._VALID_URL, url).groups()
19 api_base_url = 'http://capi.9c9media.com/destinations/%s/platforms/desktop/contents/%s/' % (destination_code, video_id)
20 content = self._download_json(api_base_url, video_id, query={
21 '$include': '[contentpackages]',
22 })
23 title = content['Name']
24 if len(content['ContentPackages']) > 1:
25 raise ExtractorError('multiple content packages')
26 content_package = content['ContentPackages'][0]
27 stacks_base_url = api_base_url + 'contentpackages/%s/stacks/' % content_package['Id']
28 stacks = self._download_json(stacks_base_url, video_id)['Items']
29 if len(stacks) > 1:
30 raise ExtractorError('multiple stacks')
31 stack = stacks[0]
32 stack_base_url = '%s%s/manifest.' % (stacks_base_url, stack['Id'])
33 formats = []
34 formats.extend(self._extract_m3u8_formats(
35 stack_base_url + 'm3u8', video_id, 'mp4',
36 'm3u8_native', m3u8_id='hls', fatal=False))
37 formats.extend(self._extract_f4m_formats(
38 stack_base_url + 'f4m', video_id,
39 f4m_id='hds', fatal=False))
40 mp4_url = self._download_webpage(stack_base_url + 'pd', video_id, fatal=False)
41 if mp4_url:
42 formats.append({
43 'url': mp4_url,
44 'format_id': 'mp4',
45 })
46 self._sort_formats(formats)
47
48 return {
49 'id': video_id,
50 'title': title,
51 'description': content.get('Desc') or content.get('ShortDesc'),
52 'timestamp': parse_iso8601(content.get('BroadcastDateTime')),
53 'duration': parse_duration(content.get('BroadcastTime')),
54 'formats': formats,
55 }