- meta_data = video_data['meta']
- content_id = '%s_%s' % (
- meta_data.get('accId', ''), meta_data['itemId'])
- title = meta_data['title']
- if title.endswith('.mp4'):
- title = title[:-4]
- thumbnail = meta_data['poster']
- duration = meta_data['duration']
- timestamp = meta_data['timestamp']
-
- formats = [
- {
- 'url': video['url'],
- 'format_id': video['key'],
- 'height': int(video['key'].rstrip('p'))
- } for video in video_data['videos']
- ]
+ page_config = self._parse_json(self._search_regex(
+ r'(?s)<script[^>]+class="sp-video__page-config"[^>]*>(.+?)</script>',
+ webpage, 'page config', default='{}'), video_id, fatal=False)
+ if page_config:
+ meta_url = page_config.get('metaUrl') or page_config.get('video', {}).get('metaUrl')
+ if meta_url:
+ video_data = self._download_json(
+ meta_url, video_id, 'Downloading video meta JSON', fatal=False)
+
+ # Fallback old approach
+ if not video_data:
+ video_data = self._download_json(
+ 'http://api.video.mail.ru/videos/%s.json?new=1' % video_id,
+ video_id, 'Downloading video JSON')
+
+ formats = []
+ for f in video_data['videos']:
+ video_url = f.get('url')
+ if not video_url:
+ continue
+ 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
+ formats.append({
+ 'url': video_url,
+ 'format_id': format_id,
+ 'height': height,
+ })