]> jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/mailru.py
Merge pull request #2953 from codesparkle/ndr-regexes-escape-correctly
[yt-dlp.git] / youtube_dl / extractor / mailru.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7
8
9 class MailRuIE(InfoExtractor):
10 IE_NAME = 'mailru'
11 IE_DESC = 'Видео@Mail.Ru'
12 _VALID_URL = r'http://(?:www\.)?my\.mail\.ru/video/.*#video=/?(?P<id>[^/]+/[^/]+/[^/]+/\d+)'
13
14 _TEST = {
15 'url': 'http://my.mail.ru/video/top#video=/mail/sonypicturesrus/75/76',
16 'md5': 'dea205f03120046894db4ebb6159879a',
17 'info_dict': {
18 'id': '46301138',
19 'ext': 'mp4',
20 'title': 'Новый Человек-Паук. Высокое напряжение. Восстание Электро',
21 'timestamp': 1393232740,
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 view_count = video_data['views_count']
47
48 formats = [
49 {
50 'url': video['url'],
51 'format_id': video['name'],
52 } for video in video_data['videos']
53 ]
54
55 return {
56 'id': content_id,
57 'title': title,
58 'thumbnail': thumbnail,
59 'timestamp': video_data['timestamp'],
60 'uploader': uploader,
61 'uploader_id': uploader_id,
62 'duration': duration,
63 'view_count': view_count,
64 'formats': formats,
65 }