You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
4.3 KiB

10 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_urlparse
  6. from ..utils import (
  7. parse_duration,
  8. parse_iso8601,
  9. )
  10. class SportBoxIE(InfoExtractor):
  11. _VALID_URL = r'https?://news\.sportbox\.ru/(?:[^/]+/)+spbvideo_NI\d+_(?P<display_id>.+)'
  12. _TESTS = [{
  13. 'url': 'http://news.sportbox.ru/Vidy_sporta/Avtosport/Rossijskij/spbvideo_NI483529_Gonka-2-zaezd-Obyedinenniy-2000-klassi-Turing-i-S',
  14. 'md5': 'ff56a598c2cf411a9a38a69709e97079',
  15. 'info_dict': {
  16. 'id': '80822',
  17. 'ext': 'mp4',
  18. 'title': 'Гонка 2 заезд ««Объединенный 2000»: классы Туринг и Супер-продакшн',
  19. 'description': 'md5:81715fa9c4ea3d9e7915dc8180c778ed',
  20. 'thumbnail': 're:^https?://.*\.jpg$',
  21. 'timestamp': 1411896237,
  22. 'upload_date': '20140928',
  23. 'duration': 4846,
  24. },
  25. 'params': {
  26. # m3u8 download
  27. 'skip_download': True,
  28. },
  29. }, {
  30. 'url': 'http://news.sportbox.ru/Vidy_sporta/billiard/spbvideo_NI486287_CHempionat-mira-po-dinamichnoy-piramide-4',
  31. 'only_matching': True,
  32. }, {
  33. 'url': 'http://news.sportbox.ru/video/no_ads/spbvideo_NI536574_V_Novorossijske_proshel_detskij_turnir_Pole_slavy_bojevoj?ci=211355',
  34. 'only_matching': True,
  35. }]
  36. def _real_extract(self, url):
  37. mobj = re.match(self._VALID_URL, url)
  38. display_id = mobj.group('display_id')
  39. webpage = self._download_webpage(url, display_id)
  40. player = self._search_regex(
  41. r'src="/?(vdl/player/[^"]+)"', webpage, 'player')
  42. title = self._html_search_regex(
  43. r'<h1 itemprop="name">([^<]+)</h1>', webpage, 'title')
  44. description = self._html_search_regex(
  45. r'(?s)<div itemprop="description">(.+?)</div>',
  46. webpage, 'description', fatal=False)
  47. thumbnail = self._og_search_thumbnail(webpage)
  48. timestamp = parse_iso8601(self._search_regex(
  49. r'<span itemprop="uploadDate">([^<]+)</span>',
  50. webpage, 'timestamp', fatal=False))
  51. duration = parse_duration(self._html_search_regex(
  52. r'<meta itemprop="duration" content="PT([^"]+)">',
  53. webpage, 'duration', fatal=False))
  54. return {
  55. '_type': 'url_transparent',
  56. 'url': compat_urlparse.urljoin(url, '/%s' % player),
  57. 'display_id': display_id,
  58. 'title': title,
  59. 'description': description,
  60. 'thumbnail': thumbnail,
  61. 'timestamp': timestamp,
  62. 'duration': duration,
  63. }
  64. class SportBoxEmbedIE(InfoExtractor):
  65. _VALID_URL = r'https?://news\.sportbox\.ru/vdl/player(?:/[^/]+/|\?.*?\bn?id=)(?P<id>\d+)'
  66. _TESTS = [{
  67. 'url': 'http://news.sportbox.ru/vdl/player/ci/211355',
  68. 'info_dict': {
  69. 'id': '211355',
  70. 'ext': 'mp4',
  71. 'title': 'В Новороссийске прошел детский турнир «Поле славы боевой»',
  72. 'thumbnail': 're:^https?://.*\.jpg$',
  73. },
  74. 'params': {
  75. # m3u8 download
  76. 'skip_download': True,
  77. },
  78. }, {
  79. 'url': 'http://news.sportbox.ru/vdl/player?nid=370908&only_player=1&autostart=false&playeri=2&height=340&width=580',
  80. 'only_matching': True,
  81. }]
  82. @staticmethod
  83. def _extract_urls(webpage):
  84. return re.findall(
  85. r'<iframe[^>]+src="(https?://news\.sportbox\.ru/vdl/player[^"]+)"',
  86. webpage)
  87. def _real_extract(self, url):
  88. video_id = self._match_id(url)
  89. webpage = self._download_webpage(url, video_id)
  90. hls = self._search_regex(
  91. r"sportboxPlayer\.jwplayer_common_params\.file\s*=\s*['\"]([^'\"]+)['\"]",
  92. webpage, 'hls file')
  93. formats = self._extract_m3u8_formats(hls, video_id, 'mp4')
  94. title = self._search_regex(
  95. r'sportboxPlayer\.node_title\s*=\s*"([^"]+)"', webpage, 'title')
  96. thumbnail = self._search_regex(
  97. r'sportboxPlayer\.jwplayer_common_params\.image\s*=\s*"([^"]+)"',
  98. webpage, 'thumbnail', default=None)
  99. return {
  100. 'id': video_id,
  101. 'title': title,
  102. 'thumbnail': thumbnail,
  103. 'formats': formats,
  104. }