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.

76 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. )
  9. class SportBoxIE(InfoExtractor):
  10. _VALID_URL = r'https?://news\.sportbox\.ru/Vidy_sporta/(?:[^/]+/)+spbvideo_NI\d+_(?P<display_id>.+)'
  11. _TESTS = [
  12. {
  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. ]
  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. video_id = self._search_regex(
  39. r'src="/vdl/player/media/(\d+)"', webpage, 'video id')
  40. player = self._download_webpage(
  41. 'http://news.sportbox.ru/vdl/player/media/%s' % video_id,
  42. display_id, 'Downloading player webpage')
  43. hls = self._search_regex(
  44. r"var\s+original_hls_file\s*=\s*'([^']+)'", player, 'hls file')
  45. formats = self._extract_m3u8_formats(hls, display_id, 'mp4')
  46. title = self._html_search_regex(
  47. r'<h1 itemprop="name">([^<]+)</h1>', webpage, 'title')
  48. description = self._html_search_regex(
  49. r'(?s)<div itemprop="description">(.+?)</div>', webpage, 'description', fatal=False)
  50. thumbnail = self._og_search_thumbnail(webpage)
  51. timestamp = parse_iso8601(self._search_regex(
  52. r'<span itemprop="uploadDate">([^<]+)</span>', webpage, 'timestamp', fatal=False))
  53. duration = parse_duration(self._html_search_regex(
  54. r'<meta itemprop="duration" content="PT([^"]+)">', webpage, 'duration', fatal=False))
  55. return {
  56. 'id': video_id,
  57. 'display_id': display_id,
  58. 'title': title,
  59. 'description': description,
  60. 'thumbnail': thumbnail,
  61. 'timestamp': timestamp,
  62. 'duration': duration,
  63. 'formats': formats,
  64. }