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