-# coding: utf-8
-from __future__ import unicode_literals
-
import itertools
import json
import re
+import urllib.parse
from .common import InfoExtractor
-from ..compat import compat_urllib_parse_unquote
from ..utils import (
int_or_none,
parse_duration,
{
'url': 'https://videoapi.my.mail.ru/videos/embed/mail/cloud-strife/Games/2009.html',
'only_matching': True,
- }
+ },
]
def _real_extract(self, url):
- mobj = re.match(self._VALID_URL, url)
+ mobj = self._match_valid_url(url)
meta_id = mobj.group('metaid')
video_id = None
if meta_id:
- meta_url = 'https://my.mail.ru/+/video/meta/%s' % meta_id
+ meta_url = f'https://my.mail.ru/+/video/meta/{meta_id}'
else:
video_id = mobj.group('idv1')
if not video_id:
# Fallback old approach
if not video_data:
video_data = self._download_json(
- 'http://api.video.mail.ru/videos/%s.json?new=1' % video_id,
+ f'http://api.video.mail.ru/videos/{video_id}.json?new=1',
video_id, 'Downloading video JSON')
- headers = {}
-
video_key = self._get_cookies('https://my.mail.ru').get('video_key')
- if video_key:
- headers['Cookie'] = 'video_key=%s' % video_key.value
formats = []
for f in video_data['videos']:
video_url = f.get('url')
if not video_url:
continue
+ if video_key:
+ self._set_cookie(urllib.parse.urlparse(video_url).hostname, 'video_key', video_key.value)
format_id = f.get('key')
height = int_or_none(self._search_regex(
r'^(\d+)[pP]$', format_id, 'height', default=None)) if format_id else None
'url': video_url,
'format_id': format_id,
'height': height,
- 'http_headers': headers,
})
- self._sort_formats(formats)
meta_data = video_data['meta']
title = remove_end(meta_data['title'], '.mp4')
acc_id = meta_data.get('accId')
item_id = meta_data.get('itemId')
- content_id = '%s_%s' % (acc_id, item_id) if acc_id and item_id else video_id
+ content_id = f'{acc_id}_{item_id}' if acc_id and item_id else video_id
thumbnail = meta_data.get('poster')
duration = int_or_none(meta_data.get('duration'))
def _search(self, query, url, audio_id, limit=100, offset=0):
search = self._download_json(
'https://my.mail.ru/cgi-bin/my/ajax', audio_id,
- 'Downloading songs JSON page %d' % (offset // limit + 1),
+ f'Downloading songs JSON page {offset // limit + 1}',
headers={
'Referer': url,
'X-Requested-With': 'XMLHttpRequest',
artist = t.get('Author') or t.get('Author_Text_HTML')
if track:
- title = '%s - %s' % (artist, track) if artist else track
+ title = f'{artist} - {track}' if artist else track
else:
title = audio_id
}]
def _real_extract(self, url):
- query = compat_urllib_parse_unquote(self._match_id(url))
+ query = urllib.parse.unquote(self._match_id(url))
entries = []