]>
Commit | Line | Data |
---|---|---|
1da19488 YCH |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | from .common import InfoExtractor | |
30eaa3a7 | 5 | from ..compat import compat_str |
1da19488 YCH |
6 | from ..utils import int_or_none |
7 | ||
8 | ||
9 | class MGTVIE(InfoExtractor): | |
30eaa3a7 | 10 | _VALID_URL = r'https?://(?:www\.)?mgtv\.com/(v|b)/(?:[^/]+/)*(?P<id>\d+)\.html' |
a292cba2 | 11 | IE_DESC = '芒果TV' |
1da19488 | 12 | |
dc35ba0e | 13 | _TESTS = [{ |
1da19488 | 14 | 'url': 'http://www.mgtv.com/v/1/290525/f/3116640.html', |
30eaa3a7 | 15 | 'md5': 'b1ffc0fc163152acf6beaa81832c9ee7', |
1da19488 YCH |
16 | 'info_dict': { |
17 | 'id': '3116640', | |
18 | 'ext': 'mp4', | |
19 | 'title': '我是歌手第四季双年巅峰会:韩红李玟“双王”领军对抗', | |
20 | 'description': '我是歌手第四季双年巅峰会', | |
21 | 'duration': 7461, | |
ec85ded8 | 22 | 'thumbnail': r're:^https?://.*\.jpg$', |
1da19488 | 23 | }, |
dc35ba0e | 24 | }, { |
30eaa3a7 | 25 | 'url': 'http://www.mgtv.com/b/301817/3826653.html', |
dc35ba0e S |
26 | 'only_matching': True, |
27 | }] | |
1da19488 YCH |
28 | |
29 | def _real_extract(self, url): | |
30 | video_id = self._match_id(url) | |
31 | api_data = self._download_json( | |
30eaa3a7 | 32 | 'http://pcweb.api.mgtv.com/player/video', video_id, |
89e2fff2 RA |
33 | query={'video_id': video_id}, |
34 | headers=self.geo_verification_headers())['data'] | |
1da19488 | 35 | info = api_data['info'] |
30eaa3a7 RA |
36 | title = info['title'].strip() |
37 | stream_domain = api_data['stream_domain'][0] | |
1da19488 YCH |
38 | |
39 | formats = [] | |
40 | for idx, stream in enumerate(api_data['stream']): | |
30eaa3a7 RA |
41 | stream_path = stream.get('url') |
42 | if not stream_path: | |
43 | continue | |
44 | format_data = self._download_json( | |
45 | stream_domain + stream_path, video_id, | |
46 | note='Download video info for format #%d' % idx) | |
47 | format_url = format_data.get('info') | |
48 | if not format_url: | |
b9e7bc55 | 49 | continue |
50 | tbr = int_or_none(self._search_regex( | |
30eaa3a7 RA |
51 | r'_(\d+)_mp4/', format_url, 'tbr', default=None)) |
52 | formats.append({ | |
53 | 'format_id': compat_str(tbr or idx), | |
54 | 'url': format_url, | |
55 | 'ext': 'mp4', | |
56 | 'tbr': tbr, | |
57 | 'protocol': 'm3u8_native', | |
58 | }) | |
1da19488 YCH |
59 | self._sort_formats(formats) |
60 | ||
61 | return { | |
62 | 'id': video_id, | |
30eaa3a7 | 63 | 'title': title, |
1da19488 YCH |
64 | 'formats': formats, |
65 | 'description': info.get('desc'), | |
66 | 'duration': int_or_none(info.get('duration')), | |
67 | 'thumbnail': info.get('thumb'), | |
68 | } |