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