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.

115 lines
4.0 KiB

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