]> jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/mailru.py
f819c09b348550c878616151ace346ac1a7ab3a4
[yt-dlp.git] / youtube_dl / extractor / mailru.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5 import datetime
6
7 from .common import InfoExtractor
8
9
10 class MailRuIE(InfoExtractor):
11 IE_NAME = 'mailru'
12 IE_DESC = 'Видео@Mail.Ru'
13 _VALID_URL = r'http://(?:www\.)?my\.mail\.ru/video/.*#video=/?(?P<id>[^/]+/[^/]+/[^/]+/\d+)'
14
15 _TEST = {
16 'url': 'http://my.mail.ru/video/top#video=/mail/sonypicturesrus/75/76',
17 'md5': 'dea205f03120046894db4ebb6159879a',
18 'info_dict': {
19 'id': '46301138',
20 'ext': 'mp4',
21 'title': 'Новый Человек-Паук. Высокое напряжение. Восстание Электро',
22 'upload_date': '20140224',
23 'uploader': 'sonypicturesrus',
24 'uploader_id': 'sonypicturesrus@mail.ru',
25 'duration': 184,
26 }
27 }
28
29 def _real_extract(self, url):
30 mobj = re.match(self._VALID_URL, url)
31 video_id = mobj.group('id')
32
33 video_data = self._download_json(
34 'http://videoapi.my.mail.ru/videos/%s.json?new=1' % video_id, video_id, 'Downloading video JSON')
35
36 author = video_data['author']
37 uploader = author['name']
38 uploader_id = author['id']
39
40 movie = video_data['movie']
41 content_id = str(movie['contentId'])
42 title = movie['title']
43 thumbnail = movie['poster']
44 duration = movie['duration']
45
46 upload_date = datetime.datetime.fromtimestamp(video_data['timestamp']).strftime('%Y%m%d')
47 view_count = video_data['views_count']
48
49 formats = [
50 {
51 'url': video['url'],
52 'format_id': video['name'],
53 } for video in video_data['videos']
54 ]
55
56 return {
57 'id': content_id,
58 'title': title,
59 'thumbnail': thumbnail,
60 'upload_date': upload_date,
61 'uploader': uploader,
62 'uploader_id': uploader_id,
63 'duration': duration,
64 'view_count': view_count,
65 'formats': formats,
66 }