1
0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2024-12-15 17:21:24 +01:00
youtube-dl/youtube_dl/extractor/fczenit.py

57 lines
1.7 KiB
Python
Raw Normal View History

2015-10-12 07:25:57 +02:00
# coding: utf-8
from __future__ import unicode_literals
from .common import InfoExtractor
2017-11-25 19:28:26 +01:00
from ..utils import (
int_or_none,
float_or_none,
)
2015-10-12 07:25:57 +02:00
class FczenitIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?fc-zenit\.ru/video/(?P<id>[0-9]+)'
2015-10-12 07:25:57 +02:00
_TEST = {
'url': 'http://fc-zenit.ru/video/41044/',
'md5': '0e3fab421b455e970fa1aa3891e57df0',
2015-10-12 07:25:57 +02:00
'info_dict': {
'id': '41044',
2015-10-12 07:25:57 +02:00
'ext': 'mp4',
'title': 'Так пишется история: казанский разгром ЦСКА на «Зенит-ТВ»',
2017-11-25 19:28:26 +01:00
'timestamp': 1462283735,
'upload_date': '20160503',
2015-10-12 07:25:57 +02:00
},
}
def _real_extract(self, url):
video_id = self._match_id(url)
webpage = self._download_webpage(url, video_id)
2017-11-25 19:28:26 +01:00
msi_id = self._search_regex(
r"(?s)config\s*=\s*{.+?video_id\s*:\s*'([^']+)'", webpage, 'msi id')
2017-11-25 19:28:26 +01:00
msi_data = self._download_json(
'http://player.fc-zenit.ru/msi/video', msi_id, query={
'video': msi_id,
})['data']
title = msi_data['name']
2015-10-12 07:25:57 +02:00
formats = [{
2017-11-25 19:28:26 +01:00
'format_id': q.get('label'),
'url': q['url'],
'height': int_or_none(q.get('label')),
} for q in msi_data['qualities'] if q.get('url')]
2015-10-12 07:25:57 +02:00
self._sort_formats(formats)
2017-11-25 19:28:26 +01:00
tags = [tag['label'] for tag in msi_data.get('tags', []) if tag.get('label')]
2015-10-12 07:25:57 +02:00
return {
'id': video_id,
2017-11-25 19:28:26 +01:00
'title': title,
'thumbnail': msi_data.get('preview'),
2015-10-12 07:25:57 +02:00
'formats': formats,
2017-11-25 19:28:26 +01:00
'duration': float_or_none(msi_data.get('duration')),
'timestamp': int_or_none(msi_data.get('date')),
'tags': tags,
2015-10-12 07:25:57 +02:00
}