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.

81 lines
3.0 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. 'view_count': int,
  26. },
  27. 'params': {
  28. # m3u8 download
  29. 'skip_download': True,
  30. },
  31. }, {
  32. 'url': 'http://news.sportbox.ru/Vidy_sporta/billiard/spbvideo_NI486287_CHempionat-mira-po-dinamichnoy-piramide-4',
  33. 'only_matching': True,
  34. }
  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. video_id = self._search_regex(
  41. r'src="/vdl/player/media/(\d+)"', webpage, 'video id')
  42. player = self._download_webpage(
  43. 'http://news.sportbox.ru/vdl/player/media/%s' % video_id,
  44. display_id, 'Downloading player webpage')
  45. hls = self._search_regex(
  46. r"var\s+original_hls_file\s*=\s*'([^']+)'", player, 'hls file')
  47. formats = self._extract_m3u8_formats(hls, display_id, 'mp4')
  48. title = self._html_search_regex(
  49. r'<h1 itemprop="name">([^<]+)</h1>', webpage, 'title')
  50. description = self._html_search_regex(
  51. r'(?s)<div itemprop="description">(.+?)</div>', webpage, 'description', fatal=False)
  52. thumbnail = self._og_search_thumbnail(webpage)
  53. timestamp = parse_iso8601(self._search_regex(
  54. r'<span itemprop="uploadDate">([^<]+)</span>', webpage, 'timestamp', fatal=False))
  55. duration = parse_duration(self._html_search_regex(
  56. r'<meta itemprop="duration" content="PT([^"]+)">', webpage, 'duration', fatal=False))
  57. view_count = int_or_none(self._html_search_regex(
  58. r'<span>Просмотров: (\d+)</span>', player, 'view count', fatal=False))
  59. return {
  60. 'id': video_id,
  61. 'display_id': display_id,
  62. 'title': title,
  63. 'description': description,
  64. 'thumbnail': thumbnail,
  65. 'timestamp': timestamp,
  66. 'duration': duration,
  67. 'view_count': view_count,
  68. 'formats': formats,
  69. }