logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

sportbox.py (3421B)


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