]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/mnet.py
Fix "invalid escape sequences" error on Python 3.6
[yt-dlp.git] / youtube_dl / extractor / mnet.py
CommitLineData
e0317686
KH
1# coding: utf-8
2from __future__ import unicode_literals
3
4from .common import InfoExtractor
5from ..utils import (
6 int_or_none,
7 parse_duration,
8 parse_iso8601,
9)
10
11
12class MnetIE(InfoExtractor):
13 _VALID_URL = r'https?://(?:www\.)?mnet\.(?:com|interest\.me)/tv/vod/(?:.*?\bclip_id=)?(?P<id>[0-9]+)'
98e68806
S
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',
ec85ded8 25 'thumbnail': r're:^https?://.*\.jpg$',
98e68806 26 'ext': 'flv',
e0317686 27 },
98e68806
S
28 'params': {
29 # rtmp download
30 'skip_download': True,
e0317686 31 },
98e68806
S
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 }]
e0317686
KH
39
40 def _real_extract(self, url):
41 video_id = self._match_id(url)
98e68806
S
42
43 info = self._download_json(
44 'http://content.api.mnet.com/player/vodConfig?id=%s&ctype=CLIP' % video_id,
45 video_id, 'Downloading vod config JSON')['data']['info']
e0317686
KH
46
47 title = info['title']
98e68806
S
48
49 rtmp_info = self._download_json(
50 info['cdn'], video_id, 'Downloading vod cdn JSON')
51
52 formats = [{
53 'url': rtmp_info['serverurl'] + rtmp_info['fileurl'],
54 'ext': 'flv',
55 'page_url': url,
56 'player_url': 'http://flvfile.mnet.com/service/player/201602/cjem_player_tv.swf?v=201602191318',
57 }]
58
e0317686
KH
59 description = info.get('ment')
60 duration = parse_duration(info.get('time'))
61 timestamp = parse_iso8601(info.get('date'), delimiter=' ')
62 age_limit = info.get('adult')
63 if age_limit is not None:
64 age_limit = 0 if age_limit == 'N' else 18
98e68806
S
65 thumbnails = [{
66 'id': thumb_format,
67 'url': thumb['url'],
68 'width': int_or_none(thumb.get('width')),
69 'height': int_or_none(thumb.get('height')),
70 } for thumb_format, thumb in info.get('cover', {}).items() if thumb.get('url')]
e0317686
KH
71
72 return {
73 'id': video_id,
74 'title': title,
e0317686
KH
75 'description': description,
76 'duration': duration,
77 'timestamp': timestamp,
78 'age_limit': age_limit,
79 'thumbnails': thumbnails,
98e68806 80 'formats': formats,
e0317686 81 }