]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/mailru.py
Merge pull request #8061 from dstftw/introduce-chapter-and-series-fields
[yt-dlp.git] / youtube_dl / extractor / mailru.py
CommitLineData
69bb54eb
S
1# encoding: utf-8
2from __future__ import unicode_literals
3
4import re
69bb54eb
S
5
6from .common import InfoExtractor
7
8
9class 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 },
95e431e9 28 'skip': 'Not accessible from Travis CI server',
ceb7a17f
S
29 },
30 {
31 'url': 'http://my.mail.ru/corp/hitech/video/news_hi-tech_mail_ru/1263.html',
32 'md5': '00a91a58c3402204dcced523777b475f',
33 'info_dict': {
00d9ef0b 34 'id': '46843144_1263',
ceb7a17f
S
35 'ext': 'mp4',
36 'title': 'Samsung Galaxy S5 Hammer Smash Fail Battery Explosion',
37 'timestamp': 1397217632,
38 'upload_date': '20140411',
39 'uploader': 'hitech',
40 'uploader_id': 'hitech@corp.mail.ru',
41 'duration': 245,
42 },
95e431e9 43 'skip': 'Not accessible from Travis CI server',
ceb7a17f
S
44 },
45 ]
69bb54eb
S
46
47 def _real_extract(self, url):
48 mobj = re.match(self._VALID_URL, url)
ceb7a17f
S
49 video_id = mobj.group('idv1')
50
51 if not video_id:
52 video_id = mobj.group('idv2prefix') + mobj.group('idv2suffix')
69bb54eb
S
53
54 video_data = self._download_json(
ceb7a17f 55 'http://api.video.mail.ru/videos/%s.json?new=1' % video_id, video_id, 'Downloading video JSON')
69bb54eb
S
56
57 author = video_data['author']
58 uploader = author['name']
00d9ef0b
PH
59 uploader_id = author.get('id') or author.get('email')
60 view_count = video_data.get('views_count')
69bb54eb 61
00d9ef0b
PH
62 meta_data = video_data['meta']
63 content_id = '%s_%s' % (
64 meta_data.get('accId', ''), meta_data['itemId'])
65 title = meta_data['title']
ceb7a17f
S
66 if title.endswith('.mp4'):
67 title = title[:-4]
00d9ef0b
PH
68 thumbnail = meta_data['poster']
69 duration = meta_data['duration']
70 timestamp = meta_data['timestamp']
69bb54eb
S
71
72 formats = [
73 {
74 'url': video['url'],
00d9ef0b
PH
75 'format_id': video['key'],
76 'height': int(video['key'].rstrip('p'))
69bb54eb
S
77 } for video in video_data['videos']
78 ]
00d9ef0b 79 self._sort_formats(formats)
69bb54eb
S
80
81 return {
82 'id': content_id,
83 'title': title,
84 'thumbnail': thumbnail,
00d9ef0b 85 'timestamp': timestamp,
69bb54eb
S
86 'uploader': uploader,
87 'uploader_id': uploader_id,
88 'duration': duration,
89 'view_count': view_count,
90 'formats': formats,
00d9ef0b 91 }