sportbox.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. determine_ext,
  4. int_or_none,
  5. js_to_json,
  6. merge_dicts,
  7. )
  8. class SportBoxIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:news\.sportbox|matchtv)\.ru/vdl/player(?:/[^/]+/|\?.*?\bn?id=)(?P<id>\d+)'
  10. _EMBED_REGEX = [r'<iframe[^>]+src="(?P<url>https?://(?:news\.sportbox|matchtv)\.ru/vdl/player[^"]+)"']
  11. _TESTS = [{
  12. 'url': 'http://news.sportbox.ru/vdl/player/ci/211355',
  13. 'info_dict': {
  14. 'id': '109158',
  15. 'ext': 'mp4',
  16. 'title': 'В Новороссийске прошел детский турнир «Поле славы боевой»',
  17. 'description': 'В Новороссийске прошел детский турнир «Поле славы боевой»',
  18. 'thumbnail': r're:^https?://.*\.jpg$',
  19. 'duration': 292,
  20. 'view_count': int,
  21. 'timestamp': 1426237001,
  22. 'upload_date': '20150313',
  23. },
  24. 'params': {
  25. # m3u8 download
  26. 'skip_download': True,
  27. },
  28. }, {
  29. 'url': 'http://news.sportbox.ru/vdl/player?nid=370908&only_player=1&autostart=false&playeri=2&height=340&width=580',
  30. 'only_matching': True,
  31. }, {
  32. 'url': 'https://news.sportbox.ru/vdl/player/media/193095',
  33. 'only_matching': True,
  34. }, {
  35. 'url': 'https://news.sportbox.ru/vdl/player/media/109158',
  36. 'only_matching': True,
  37. }, {
  38. 'url': 'https://matchtv.ru/vdl/player/media/109158',
  39. 'only_matching': True,
  40. }]
  41. def _real_extract(self, url):
  42. video_id = self._match_id(url)
  43. webpage = self._download_webpage(url, video_id)
  44. sources = self._parse_json(
  45. self._search_regex(
  46. r'(?s)playerOptions\.sources(?:WithRes)?\s*=\s*(\[.+?\])\s*;\s*\n',
  47. webpage, 'sources'),
  48. video_id, transform_source=js_to_json)
  49. formats = []
  50. for source in sources:
  51. src = source.get('src')
  52. if not src:
  53. continue
  54. if determine_ext(src) == 'm3u8':
  55. formats.extend(self._extract_m3u8_formats(
  56. src, video_id, 'mp4', entry_protocol='m3u8_native',
  57. m3u8_id='hls', fatal=False))
  58. else:
  59. formats.append({
  60. 'url': src,
  61. })
  62. player = self._parse_json(
  63. self._search_regex(
  64. r'(?s)playerOptions\s*=\s*({.+?})\s*;\s*\n', webpage,
  65. 'player options', default='{}'),
  66. video_id, transform_source=js_to_json)
  67. media_id = player['mediaId']
  68. info = self._search_json_ld(webpage, media_id, default={})
  69. view_count = int_or_none(self._search_regex(
  70. r'Просмотров\s*:\s*(\d+)', webpage, 'view count', default=None))
  71. return merge_dicts(info, {
  72. 'id': media_id,
  73. 'title': self._og_search_title(webpage, default=None) or media_id,
  74. 'thumbnail': player.get('poster'),
  75. 'duration': int_or_none(player.get('duration')),
  76. 'view_count': view_count,
  77. 'formats': formats,
  78. })