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.

130 lines
4.4 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. js_to_json,
  8. unified_strdate,
  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:3d72dc4a006ab6805d82f037fdc637ad',
  20. 'thumbnail': 're:^https?://.*\.jpg$',
  21. 'upload_date': '20140928',
  22. },
  23. 'params': {
  24. # m3u8 download
  25. 'skip_download': True,
  26. },
  27. }, {
  28. 'url': 'http://news.sportbox.ru/Vidy_sporta/billiard/spbvideo_NI486287_CHempionat-mira-po-dinamichnoy-piramide-4',
  29. 'only_matching': True,
  30. }, {
  31. 'url': 'http://news.sportbox.ru/video/no_ads/spbvideo_NI536574_V_Novorossijske_proshel_detskij_turnir_Pole_slavy_bojevoj?ci=211355',
  32. 'only_matching': True,
  33. }]
  34. def _real_extract(self, url):
  35. mobj = re.match(self._VALID_URL, url)
  36. display_id = mobj.group('display_id')
  37. webpage = self._download_webpage(url, display_id)
  38. player = self._search_regex(
  39. r'src="/?(vdl/player/[^"]+)"', webpage, 'player')
  40. title = self._html_search_regex(
  41. [r'"nodetitle"\s*:\s*"([^"]+)"', r'class="node-header_{1,2}title">([^<]+)'],
  42. webpage, 'title')
  43. description = self._og_search_description(webpage) or self._html_search_meta(
  44. 'description', webpage, 'description')
  45. thumbnail = self._og_search_thumbnail(webpage)
  46. upload_date = unified_strdate(self._html_search_meta(
  47. 'dateCreated', webpage, 'upload date'))
  48. return {
  49. '_type': 'url_transparent',
  50. 'url': compat_urlparse.urljoin(url, '/%s' % player),
  51. 'display_id': display_id,
  52. 'title': title,
  53. 'description': description,
  54. 'thumbnail': thumbnail,
  55. 'upload_date': upload_date,
  56. }
  57. class SportBoxEmbedIE(InfoExtractor):
  58. _VALID_URL = r'https?://news\.sportbox\.ru/vdl/player(?:/[^/]+/|\?.*?\bn?id=)(?P<id>\d+)'
  59. _TESTS = [{
  60. 'url': 'http://news.sportbox.ru/vdl/player/ci/211355',
  61. 'info_dict': {
  62. 'id': '211355',
  63. 'ext': 'mp4',
  64. 'title': 'В Новороссийске прошел детский турнир «Поле славы боевой»',
  65. 'thumbnail': 're:^https?://.*\.jpg$',
  66. },
  67. 'params': {
  68. # m3u8 download
  69. 'skip_download': True,
  70. },
  71. }, {
  72. 'url': 'http://news.sportbox.ru/vdl/player?nid=370908&only_player=1&autostart=false&playeri=2&height=340&width=580',
  73. 'only_matching': True,
  74. }]
  75. @staticmethod
  76. def _extract_urls(webpage):
  77. return re.findall(
  78. r'<iframe[^>]+src="(https?://news\.sportbox\.ru/vdl/player[^"]+)"',
  79. webpage)
  80. def _real_extract(self, url):
  81. video_id = self._match_id(url)
  82. webpage = self._download_webpage(url, video_id)
  83. formats = []
  84. def cleanup_js(code):
  85. # desktop_advert_config contains complex Javascripts and we don't need it
  86. return js_to_json(re.sub(r'desktop_advert_config.*', '', code))
  87. jwplayer_data = self._parse_json(self._search_regex(
  88. r'(?s)player\.setup\(({.+?})\);', webpage, 'jwplayer settings'), video_id,
  89. transform_source=cleanup_js)
  90. hls_url = jwplayer_data.get('hls_url')
  91. if hls_url:
  92. formats.extend(self._extract_m3u8_formats(
  93. hls_url, video_id, ext='mp4', m3u8_id='hls'))
  94. rtsp_url = jwplayer_data.get('rtsp_url')
  95. if rtsp_url:
  96. formats.append({
  97. 'url': rtsp_url,
  98. 'format_id': 'rtsp',
  99. })
  100. self._sort_formats(formats)
  101. title = jwplayer_data['node_title']
  102. thumbnail = jwplayer_data.get('image_url')
  103. return {
  104. 'id': video_id,
  105. 'title': title,
  106. 'thumbnail': thumbnail,
  107. 'formats': formats,
  108. }