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.

77 lines
2.8 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. parse_duration,
  7. parse_iso8601,
  8. int_or_none,
  9. )
  10. class SportBoxIE(InfoExtractor):
  11. _VALID_URL = r'https?://news\.sportbox\.ru/Vidy_sporta/(?:[^/]+/)+spbvideo_NI\d+_(?P<display_id>.+)'
  12. _TESTS = [
  13. {
  14. 'url': 'http://news.sportbox.ru/Vidy_sporta/Avtosport/Rossijskij/spbvideo_NI483529_Gonka-2-zaezd-Obyedinenniy-2000-klassi-Turing-i-S',
  15. 'md5': 'ff56a598c2cf411a9a38a69709e97079',
  16. 'info_dict': {
  17. 'id': '80822',
  18. 'ext': 'mp4',
  19. 'title': 'Гонка 2 заезд ««Объединенный 2000»: классы Туринг и Супер-продакшн',
  20. 'description': 'md5:81715fa9c4ea3d9e7915dc8180c778ed',
  21. 'thumbnail': 're:^https?://.*\.jpg$',
  22. 'timestamp': 1411896237,
  23. 'upload_date': '20140928',
  24. 'duration': 4846,
  25. },
  26. 'params': {
  27. # m3u8 download
  28. 'skip_download': True,
  29. },
  30. }, {
  31. 'url': 'http://news.sportbox.ru/Vidy_sporta/billiard/spbvideo_NI486287_CHempionat-mira-po-dinamichnoy-piramide-4',
  32. 'only_matching': True,
  33. }
  34. ]
  35. def _real_extract(self, url):
  36. mobj = re.match(self._VALID_URL, url)
  37. display_id = mobj.group('display_id')
  38. webpage = self._download_webpage(url, display_id)
  39. video_id = self._search_regex(
  40. r'src="/vdl/player/media/(\d+)"', webpage, 'video id')
  41. player = self._download_webpage(
  42. 'http://news.sportbox.ru/vdl/player/media/%s' % video_id,
  43. display_id, 'Downloading player webpage')
  44. hls = self._search_regex(
  45. r"var\s+original_hls_file\s*=\s*'([^']+)'", player, 'hls file')
  46. formats = self._extract_m3u8_formats(hls, display_id, 'mp4')
  47. title = self._html_search_regex(
  48. r'<h1 itemprop="name">([^<]+)</h1>', webpage, 'title')
  49. description = self._html_search_regex(
  50. r'(?s)<div itemprop="description">(.+?)</div>', webpage, 'description', fatal=False)
  51. thumbnail = self._og_search_thumbnail(webpage)
  52. timestamp = parse_iso8601(self._search_regex(
  53. r'<span itemprop="uploadDate">([^<]+)</span>', webpage, 'timestamp', fatal=False))
  54. duration = parse_duration(self._html_search_regex(
  55. r'<meta itemprop="duration" content="PT([^"]+)">', webpage, 'duration', fatal=False))
  56. return {
  57. 'id': video_id,
  58. 'display_id': display_id,
  59. 'title': title,
  60. 'description': description,
  61. 'thumbnail': thumbnail,
  62. 'timestamp': timestamp,
  63. 'duration': duration,
  64. 'formats': formats,
  65. }