]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/mgtv.py
Update list of supported sites
[youtubedl] / youtube_dl / extractor / mgtv.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import int_or_none
6
7
8 class MGTVIE(InfoExtractor):
9 _VALID_URL = r'https?://www\.mgtv\.com/v/(?:[^/]+/)*(?P<id>\d+)\.html'
10 IE_DESC = '芒果TV'
11
12 _TEST = {
13 'url': 'http://www.mgtv.com/v/1/290525/f/3116640.html',
14 'md5': '1bdadcf760a0b90946ca68ee9a2db41a',
15 'info_dict': {
16 'id': '3116640',
17 'ext': 'mp4',
18 'title': '我是歌手第四季双年巅峰会:韩红李玟“双王”领军对抗',
19 'description': '我是歌手第四季双年巅峰会',
20 'duration': 7461,
21 'thumbnail': 're:^https?://.*\.jpg$',
22 },
23 }
24
25 def _real_extract(self, url):
26 video_id = self._match_id(url)
27 api_data = self._download_json(
28 'http://v.api.mgtv.com/player/video', video_id,
29 query={'video_id': video_id})['data']
30 info = api_data['info']
31
32 formats = []
33 for idx, stream in enumerate(api_data['stream']):
34 stream_url = stream.get('url')
35 if not stream_url:
36 continue
37 tbr = int_or_none(self._search_regex(
38 r'(\d+)\.mp4', stream_url, 'tbr', default=None))
39
40 def extract_format(stream_url, format_id, idx, query={}):
41 format_info = self._download_json(
42 stream_url, video_id,
43 note='Download video info for format %s' % format_id or '#%d' % idx, query=query)
44 return {
45 'format_id': format_id,
46 'url': format_info['info'],
47 'ext': 'mp4',
48 'tbr': tbr,
49 }
50
51 formats.append(extract_format(
52 stream_url, 'hls-%d' % tbr if tbr else None, idx * 2))
53 formats.append(extract_format(stream_url.replace(
54 '/playlist.m3u8', ''), 'http-%d' % tbr if tbr else None, idx * 2 + 1, {'pno': 1031}))
55 self._sort_formats(formats)
56
57 return {
58 'id': video_id,
59 'title': info['title'].strip(),
60 'formats': formats,
61 'description': info.get('desc'),
62 'duration': int_or_none(info.get('duration')),
63 'thumbnail': info.get('thumb'),
64 }