2 from __future__ import unicode_literals
6 from .common import InfoExtractor
13 class MailRuIE(InfoExtractor):
15 IE_DESC = 'Видео@Mail.Ru'
16 _VALID_URL = r'https?://(?:(?:www|m)\.)?my\.mail\.ru/(?:video/.*#video=/?(?P<idv1>(?:[^/]+/){3}\d+)|(?:(?P<idv2prefix>(?:[^/]+/){2})video/(?P<idv2suffix>[^/]+/\d+))\.html|video/embed/(?P<meta_id>\d+))'
19 'url': 'http://my.mail.ru/video/top#video=/mail/sonypicturesrus/75/76',
20 'md5': 'dea205f03120046894db4ebb6159879a',
24 'title': 'Новый Человек-Паук. Высокое напряжение. Восстание Электро',
25 'timestamp': 1393232740,
26 'upload_date': '20140224',
27 'uploader': 'sonypicturesrus',
28 'uploader_id': 'sonypicturesrus@mail.ru',
31 'skip': 'Not accessible from Travis CI server',
34 'url': 'http://my.mail.ru/corp/hitech/video/news_hi-tech_mail_ru/1263.html',
35 'md5': '00a91a58c3402204dcced523777b475f',
37 'id': '46843144_1263',
39 'title': 'Samsung Galaxy S5 Hammer Smash Fail Battery Explosion',
40 'timestamp': 1397039888,
41 'upload_date': '20140409',
42 'uploader': 'hitech@corp.mail.ru',
43 'uploader_id': 'hitech@corp.mail.ru',
46 'skip': 'Not accessible from Travis CI server',
49 # only available via metaUrl API
50 'url': 'http://my.mail.ru/mail/720pizle/video/_myvideo/502.html',
51 'md5': '3b26d2491c6949d031a32b96bd97c096',
56 'timestamp': 1449094163,
57 'upload_date': '20151202',
58 'uploader': '720pizle@mail.ru',
59 'uploader_id': '720pizle@mail.ru',
62 'skip': 'Not accessible from Travis CI server',
65 'url': 'http://m.my.mail.ru/mail/3sktvtr/video/_myvideo/138.html',
66 'only_matching': True,
69 'url': 'https://my.mail.ru/video/embed/7949340477499637815',
70 'only_matching': True,
74 def _real_extract(self, url):
75 mobj = re.match(self._VALID_URL, url)
76 meta_id = mobj.group('meta_id')
81 video_id = mobj.group('idv1')
83 video_id = mobj.group('idv2prefix') + mobj.group('idv2suffix')
85 webpage = self._download_webpage(url, video_id)
87 page_config = self._parse_json(self._search_regex(
88 r'(?s)<script[^>]+class="sp-video__page-config"[^>]*>(.+?)</script>',
89 webpage, 'page config', default='{}'), video_id, fatal=False)
90 if page_config or meta_id:
92 meta_url = page_config.get('metaUrl') or page_config.get('video', {}).get('metaUrl')
94 meta_url = 'https://my.mail.ru/+/video/meta/' + meta_id
96 video_data = self._download_json(
97 meta_url, video_id, 'Downloading video meta JSON', fatal=False)
99 # Fallback old approach
101 video_data = self._download_json(
102 'http://api.video.mail.ru/videos/%s.json?new=1' % video_id,
103 video_id, 'Downloading video JSON')
106 for f in video_data['videos']:
107 video_url = f.get('url')
110 format_id = f.get('key')
111 height = int_or_none(self._search_regex(
112 r'^(\d+)[pP]$', format_id, 'height', default=None)) if format_id else None
115 'format_id': format_id,
118 self._sort_formats(formats)
120 meta_data = video_data['meta']
121 title = remove_end(meta_data['title'], '.mp4')
123 author = video_data.get('author')
124 uploader = author.get('name')
125 uploader_id = author.get('id') or author.get('email')
126 view_count = int_or_none(video_data.get('viewsCount') or video_data.get('views_count'))
128 acc_id = meta_data.get('accId')
129 item_id = meta_data.get('itemId')
130 content_id = '%s_%s' % (acc_id, item_id) if acc_id and item_id else video_id
132 thumbnail = meta_data.get('poster')
133 duration = int_or_none(meta_data.get('duration'))
134 timestamp = int_or_none(meta_data.get('timestamp'))
139 'thumbnail': thumbnail,
140 'timestamp': timestamp,
141 'uploader': uploader,
142 'uploader_id': uploader_id,
143 'duration': duration,
144 'view_count': view_count,