]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/minoto.py
debian/changelog: Make more readable.
[youtubedl] / youtube_dl / extractor / minoto.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 int_or_none,
9 parse_codecs,
10 )
11
12
13 class MinotoIE(InfoExtractor):
14 _VALID_URL = r'(?:minoto:|https?://(?:play|iframe|embed)\.minoto-video\.com/(?P<player_id>[0-9]+)/)(?P<id>[a-zA-Z0-9]+)'
15
16 def _real_extract(self, url):
17 mobj = re.match(self._VALID_URL, url)
18 player_id = mobj.group('player_id') or '1'
19 video_id = mobj.group('id')
20 video_data = self._download_json('http://play.minoto-video.com/%s/%s.js' % (player_id, video_id), video_id)
21 video_metadata = video_data['video-metadata']
22 formats = []
23 for fmt in video_data['video-files']:
24 fmt_url = fmt.get('url')
25 if not fmt_url:
26 continue
27 container = fmt.get('container')
28 if container == 'hls':
29 formats.extend(fmt_url, video_id, 'mp4', m3u8_id='hls', fatal=False)
30 else:
31 fmt_profile = fmt.get('profile') or {}
32 formats.append({
33 'format_id': fmt_profile.get('name-short'),
34 'format_note': fmt_profile.get('name'),
35 'url': fmt_url,
36 'container': container,
37 'tbr': int_or_none(fmt.get('bitrate')),
38 'filesize': int_or_none(fmt.get('filesize')),
39 'width': int_or_none(fmt.get('width')),
40 'height': int_or_none(fmt.get('height')),
41 'codecs': parse_codecs(fmt.get('codecs')),
42 })
43 self._sort_formats(formats)
44
45 return {
46 'id': video_id,
47 'title': video_metadata['title'],
48 'description': video_metadata.get('description'),
49 'thumbnail': video_metadata.get('video-poster', {}).get('url'),
50 'formats': formats,
51 }