]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/fczenit.py
d/p/skip-style-checks-for-flake8: Add metadata to please lintian.
[youtubedl] / youtube_dl / extractor / fczenit.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6 int_or_none,
7 float_or_none,
8 )
9
10
11 class FczenitIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:www\.)?fc-zenit\.ru/video/(?P<id>[0-9]+)'
13 _TEST = {
14 'url': 'http://fc-zenit.ru/video/41044/',
15 'md5': '0e3fab421b455e970fa1aa3891e57df0',
16 'info_dict': {
17 'id': '41044',
18 'ext': 'mp4',
19 'title': 'Так пишется история: казанский разгром ЦСКА на «Зенит-ТВ»',
20 'timestamp': 1462283735,
21 'upload_date': '20160503',
22 },
23 }
24
25 def _real_extract(self, url):
26 video_id = self._match_id(url)
27 webpage = self._download_webpage(url, video_id)
28
29 msi_id = self._search_regex(
30 r"(?s)config\s*=\s*{.+?video_id\s*:\s*'([^']+)'", webpage, 'msi id')
31
32 msi_data = self._download_json(
33 'http://player.fc-zenit.ru/msi/video', msi_id, query={
34 'video': msi_id,
35 })['data']
36 title = msi_data['name']
37
38 formats = [{
39 'format_id': q.get('label'),
40 'url': q['url'],
41 'height': int_or_none(q.get('label')),
42 } for q in msi_data['qualities'] if q.get('url')]
43
44 self._sort_formats(formats)
45
46 tags = [tag['label'] for tag in msi_data.get('tags', []) if tag.get('label')]
47
48 return {
49 'id': video_id,
50 'title': title,
51 'thumbnail': msi_data.get('preview'),
52 'formats': formats,
53 'duration': float_or_none(msi_data.get('duration')),
54 'timestamp': int_or_none(msi_data.get('date')),
55 'tags': tags,
56 }