]>
Commit | Line | Data |
---|---|---|
522c55b7 NJ |
1 | from .common import InfoExtractor |
2 | from ..utils import ( | |
3 | ExtractorError, | |
4 | qualities, | |
5 | unified_strdate, | |
6 | ) | |
7 | ||
8 | ||
9 | class MgoonIE(InfoExtractor): | |
10 | _VALID_URL = r'''(?x)https?://(?:www\.)? | |
11 | (?:(:?m\.)?mgoon\.com/(?:ch/(?:.+)/v|play/view)| | |
12 | video\.mgoon\.com)/(?P<id>[0-9]+)''' | |
13 | _API_URL = 'http://mpos.mgoon.com/player/video?id={0:}' | |
14 | _TESTS = [ | |
15 | { | |
16 | 'url': 'http://m.mgoon.com/ch/hi6618/v/5582148', | |
17 | 'md5': 'dd46bb66ab35cf6d51cc812fd82da79d', | |
18 | 'info_dict': { | |
19 | 'id': '5582148', | |
20 | 'uploader_id': 'hi6618', | |
21 | 'duration': 240.419, | |
22 | 'upload_date': '20131220', | |
23 | 'ext': 'mp4', | |
24 | 'title': 'md5:543aa4c27a4931d371c3f433e8cebebc', | |
ec85ded8 | 25 | 'thumbnail': r're:^https?://.*\.jpg$', |
522c55b7 NJ |
26 | } |
27 | }, | |
28 | { | |
29 | 'url': 'http://www.mgoon.com/play/view/5582148', | |
30 | 'only_matching': True, | |
31 | }, | |
32 | { | |
33 | 'url': 'http://video.mgoon.com/5582148', | |
34 | 'only_matching': True, | |
35 | }, | |
36 | ] | |
37 | ||
38 | def _real_extract(self, url): | |
5ad28e7f | 39 | mobj = self._match_valid_url(url) |
522c55b7 NJ |
40 | video_id = mobj.group('id') |
41 | ||
42 | data = self._download_json(self._API_URL.format(video_id), video_id) | |
43 | ||
44 | if data.get('errorInfo', {}).get('code') != 'NONE': | |
45 | raise ExtractorError('%s encountered an error: %s' % ( | |
46 | self.IE_NAME, data['errorInfo']['message']), expected=True) | |
47 | ||
48 | v_info = data['videoInfo'] | |
49 | title = v_info.get('v_title') | |
50 | thumbnail = v_info.get('v_thumbnail') | |
51 | duration = v_info.get('v_duration') | |
52 | upload_date = unified_strdate(v_info.get('v_reg_date')) | |
53 | uploader_id = data.get('userInfo', {}).get('u_alias') | |
54 | if duration: | |
55 | duration /= 1000.0 | |
56 | ||
57 | age_limit = None | |
58 | if data.get('accessInfo', {}).get('code') == 'VIDEO_STATUS_ADULT': | |
59 | age_limit = 18 | |
60 | ||
61 | formats = [] | |
62 | get_quality = qualities(['360p', '480p', '720p', '1080p']) | |
63 | for fmt in data['videoFiles']: | |
64 | formats.append({ | |
65 | 'format_id': fmt['label'], | |
66 | 'quality': get_quality(fmt['label']), | |
67 | 'url': fmt['url'], | |
68 | 'ext': fmt['format'], | |
69 | ||
70 | }) | |
71 | self._sort_formats(formats) | |
72 | ||
73 | return { | |
74 | 'id': video_id, | |
75 | 'title': title, | |
76 | 'formats': formats, | |
77 | 'thumbnail': thumbnail, | |
78 | 'duration': duration, | |
79 | 'upload_date': upload_date, | |
80 | 'uploader_id': uploader_id, | |
81 | 'age_limit': age_limit, | |
82 | } |