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