fczenit.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. float_or_none,
  4. int_or_none,
  5. )
  6. class FczenitIE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:www\.)?fc-zenit\.ru/video/(?P<id>[0-9]+)'
  8. _TEST = {
  9. 'url': 'http://fc-zenit.ru/video/41044/',
  10. 'md5': '0e3fab421b455e970fa1aa3891e57df0',
  11. 'info_dict': {
  12. 'id': '41044',
  13. 'ext': 'mp4',
  14. 'title': 'Так пишется история: казанский разгром ЦСКА на «Зенит-ТВ»',
  15. 'timestamp': 1462283735,
  16. 'upload_date': '20160503',
  17. },
  18. }
  19. def _real_extract(self, url):
  20. video_id = self._match_id(url)
  21. webpage = self._download_webpage(url, video_id)
  22. msi_id = self._search_regex(
  23. r"(?s)config\s*=\s*{.+?video_id\s*:\s*'([^']+)'", webpage, 'msi id')
  24. msi_data = self._download_json(
  25. 'http://player.fc-zenit.ru/msi/video', msi_id, query={
  26. 'video': msi_id,
  27. })['data']
  28. title = msi_data['name']
  29. formats = [{
  30. 'format_id': q.get('label'),
  31. 'url': q['url'],
  32. 'height': int_or_none(q.get('label')),
  33. } for q in msi_data['qualities'] if q.get('url')]
  34. tags = [tag['label'] for tag in msi_data.get('tags', []) if tag.get('label')]
  35. return {
  36. 'id': video_id,
  37. 'title': title,
  38. 'thumbnail': msi_data.get('preview'),
  39. 'formats': formats,
  40. 'duration': float_or_none(msi_data.get('duration')),
  41. 'timestamp': int_or_none(msi_data.get('date')),
  42. 'tags': tags,
  43. }