]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/mnet.py
98bab2e100c9ef25b2aca714d55aab7ff95201e3
[yt-dlp.git] / yt_dlp / extractor / mnet.py
1 from .common import InfoExtractor
2 from ..utils import (
3 int_or_none,
4 parse_duration,
5 parse_iso8601,
6 )
7
8
9 class MnetIE(InfoExtractor):
10 _VALID_URL = r'https?://(?:www\.)?mnet\.(?:com|interest\.me)/tv/vod/(?:.*?\bclip_id=)?(?P<id>[0-9]+)'
11 _TESTS = [{
12 'url': 'http://www.mnet.com/tv/vod/171008',
13 'info_dict': {
14 'id': '171008',
15 'title': 'SS_이해인@히든박스',
16 'description': 'md5:b9efa592c3918b615ba69fe9f8a05c55',
17 'duration': 88,
18 'upload_date': '20151231',
19 'timestamp': 1451564040,
20 'age_limit': 0,
21 'thumbnails': 'mincount:5',
22 'thumbnail': r're:^https?://.*\.jpg$',
23 'ext': 'flv',
24 },
25 'params': {
26 # rtmp download
27 'skip_download': True,
28 },
29 }, {
30 'url': 'http://mnet.interest.me/tv/vod/172790',
31 'only_matching': True,
32 }, {
33 'url': 'http://www.mnet.com/tv/vod/vod_view.asp?clip_id=172790&tabMenu=',
34 'only_matching': True,
35 }]
36
37 def _real_extract(self, url):
38 video_id = self._match_id(url)
39
40 # TODO: extract rtmp formats
41 # no stype -> rtmp url
42 # stype=H -> m3u8 url
43 # stype=M -> mpd url
44 info = self._download_json(
45 'http://content.api.mnet.com/player/vodConfig',
46 video_id, 'Downloading vod config JSON', query={
47 'id': video_id,
48 'ctype': 'CLIP',
49 'stype': 'H',
50 })['data']['info']
51
52 title = info['title']
53
54 cdn_data = self._download_json(
55 info['cdn'], video_id, 'Downloading vod cdn JSON')['data'][0]
56 m3u8_url = cdn_data['url']
57 token = cdn_data.get('token')
58 if token and token != '-':
59 m3u8_url += '?' + token
60 formats = self._extract_wowza_formats(
61 m3u8_url, video_id, skip_protocols=['rtmp', 'rtsp', 'f4m'])
62
63 description = info.get('ment')
64 duration = parse_duration(info.get('time'))
65 timestamp = parse_iso8601(info.get('date'), delimiter=' ')
66 age_limit = info.get('adult')
67 if age_limit is not None:
68 age_limit = 0 if age_limit == 'N' else 18
69 thumbnails = [{
70 'id': thumb_format,
71 'url': thumb['url'],
72 'width': int_or_none(thumb.get('width')),
73 'height': int_or_none(thumb.get('height')),
74 } for thumb_format, thumb in info.get('cover', {}).items() if thumb.get('url')]
75
76 return {
77 'id': video_id,
78 'title': title,
79 'description': description,
80 'duration': duration,
81 'timestamp': timestamp,
82 'age_limit': age_limit,
83 'thumbnails': thumbnails,
84 'formats': formats,
85 }