]>
Commit | Line | Data |
---|---|---|
69bb54eb S |
1 | # encoding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
69bb54eb S |
5 | |
6 | from .common import InfoExtractor | |
7 | ||
8 | ||
9 | class MailRuIE(InfoExtractor): | |
10 | IE_NAME = 'mailru' | |
11 | IE_DESC = 'Видео@Mail.Ru' | |
ceb7a17f | 12 | _VALID_URL = r'http://(?:www\.)?my\.mail\.ru/(?:video/.*#video=/?(?P<idv1>(?:[^/]+/){3}\d+)|(?:(?P<idv2prefix>(?:[^/]+/){2})video/(?P<idv2suffix>[^/]+/\d+))\.html)' |
69bb54eb | 13 | |
ceb7a17f S |
14 | _TESTS = [ |
15 | { | |
16 | 'url': 'http://my.mail.ru/video/top#video=/mail/sonypicturesrus/75/76', | |
17 | 'md5': 'dea205f03120046894db4ebb6159879a', | |
18 | 'info_dict': { | |
00d9ef0b | 19 | 'id': '46301138_76', |
ceb7a17f S |
20 | 'ext': 'mp4', |
21 | 'title': 'Новый Человек-Паук. Высокое напряжение. Восстание Электро', | |
22 | 'timestamp': 1393232740, | |
23 | 'upload_date': '20140224', | |
24 | 'uploader': 'sonypicturesrus', | |
25 | 'uploader_id': 'sonypicturesrus@mail.ru', | |
26 | 'duration': 184, | |
27 | }, | |
28 | }, | |
29 | { | |
30 | 'url': 'http://my.mail.ru/corp/hitech/video/news_hi-tech_mail_ru/1263.html', | |
31 | 'md5': '00a91a58c3402204dcced523777b475f', | |
32 | 'info_dict': { | |
00d9ef0b | 33 | 'id': '46843144_1263', |
ceb7a17f S |
34 | 'ext': 'mp4', |
35 | 'title': 'Samsung Galaxy S5 Hammer Smash Fail Battery Explosion', | |
36 | 'timestamp': 1397217632, | |
37 | 'upload_date': '20140411', | |
38 | 'uploader': 'hitech', | |
39 | 'uploader_id': 'hitech@corp.mail.ru', | |
40 | 'duration': 245, | |
41 | }, | |
42 | }, | |
43 | ] | |
69bb54eb S |
44 | |
45 | def _real_extract(self, url): | |
46 | mobj = re.match(self._VALID_URL, url) | |
ceb7a17f S |
47 | video_id = mobj.group('idv1') |
48 | ||
49 | if not video_id: | |
50 | video_id = mobj.group('idv2prefix') + mobj.group('idv2suffix') | |
69bb54eb S |
51 | |
52 | video_data = self._download_json( | |
ceb7a17f | 53 | 'http://api.video.mail.ru/videos/%s.json?new=1' % video_id, video_id, 'Downloading video JSON') |
69bb54eb S |
54 | |
55 | author = video_data['author'] | |
56 | uploader = author['name'] | |
00d9ef0b PH |
57 | uploader_id = author.get('id') or author.get('email') |
58 | view_count = video_data.get('views_count') | |
69bb54eb | 59 | |
00d9ef0b PH |
60 | meta_data = video_data['meta'] |
61 | content_id = '%s_%s' % ( | |
62 | meta_data.get('accId', ''), meta_data['itemId']) | |
63 | title = meta_data['title'] | |
ceb7a17f S |
64 | if title.endswith('.mp4'): |
65 | title = title[:-4] | |
00d9ef0b PH |
66 | thumbnail = meta_data['poster'] |
67 | duration = meta_data['duration'] | |
68 | timestamp = meta_data['timestamp'] | |
69bb54eb S |
69 | |
70 | formats = [ | |
71 | { | |
72 | 'url': video['url'], | |
00d9ef0b PH |
73 | 'format_id': video['key'], |
74 | 'height': int(video['key'].rstrip('p')) | |
69bb54eb S |
75 | } for video in video_data['videos'] |
76 | ] | |
00d9ef0b | 77 | self._sort_formats(formats) |
69bb54eb S |
78 | |
79 | return { | |
80 | 'id': content_id, | |
81 | 'title': title, | |
82 | 'thumbnail': thumbnail, | |
00d9ef0b | 83 | 'timestamp': timestamp, |
69bb54eb S |
84 | 'uploader': uploader, |
85 | 'uploader_id': uploader_id, | |
86 | 'duration': duration, | |
87 | 'view_count': view_count, | |
88 | 'formats': formats, | |
00d9ef0b | 89 | } |