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.

102 lines
3.7 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. determine_ext,
  7. xpath_text,
  8. )
  9. class WebcasterIE(InfoExtractor):
  10. _VALID_URL = r'https?://bl\.webcaster\.pro/(?:quote|media)/start/free_(?P<id>[^/]+)'
  11. _TESTS = [{
  12. # http://video.khl.ru/quotes/393859
  13. 'url': 'http://bl.webcaster.pro/quote/start/free_c8cefd240aa593681c8d068cff59f407_hd/q393859/eb173f99dd5f558674dae55f4ba6806d/1480289104?sr%3D105%26fa%3D1%26type_id%3D18',
  14. 'md5': '0c162f67443f30916ff1c89425dcd4cd',
  15. 'info_dict': {
  16. 'id': 'c8cefd240aa593681c8d068cff59f407_hd',
  17. 'ext': 'mp4',
  18. 'title': 'Сибирь - Нефтехимик. Лучшие моменты первого периода',
  19. 'thumbnail': r're:^https?://.*\.jpg$',
  20. },
  21. }, {
  22. 'url': 'http://bl.webcaster.pro/media/start/free_6246c7a4453ac4c42b4398f840d13100_hd/2_2991109016/e8d0d82587ef435480118f9f9c41db41/4635726126',
  23. 'only_matching': True,
  24. }]
  25. def _real_extract(self, url):
  26. video_id = self._match_id(url)
  27. video = self._download_xml(url, video_id)
  28. title = xpath_text(video, './/event_name', 'event name', fatal=True)
  29. def make_id(parts, separator):
  30. return separator.join(filter(None, parts))
  31. formats = []
  32. for format_id in (None, 'noise'):
  33. track_tag = make_id(('track', format_id), '_')
  34. for track in video.findall('.//iphone/%s' % track_tag):
  35. track_url = track.text
  36. if not track_url:
  37. continue
  38. if determine_ext(track_url) == 'm3u8':
  39. m3u8_formats = self._extract_m3u8_formats(
  40. track_url, video_id, 'mp4',
  41. entry_protocol='m3u8_native',
  42. m3u8_id=make_id(('hls', format_id), '-'), fatal=False)
  43. for f in m3u8_formats:
  44. f.update({
  45. 'source_preference': 0 if format_id == 'noise' else 1,
  46. 'format_note': track.get('title'),
  47. })
  48. formats.extend(m3u8_formats)
  49. self._sort_formats(formats)
  50. thumbnail = xpath_text(video, './/image', 'thumbnail')
  51. return {
  52. 'id': video_id,
  53. 'title': title,
  54. 'thumbnail': thumbnail,
  55. 'formats': formats,
  56. }
  57. class WebcasterFeedIE(InfoExtractor):
  58. _VALID_URL = r'https?://bl\.webcaster\.pro/feed/start/free_(?P<id>[^/]+)'
  59. _TEST = {
  60. 'url': 'http://bl.webcaster.pro/feed/start/free_c8cefd240aa593681c8d068cff59f407_hd/q393859/eb173f99dd5f558674dae55f4ba6806d/1480289104',
  61. 'only_matching': True,
  62. }
  63. @staticmethod
  64. def _extract_url(ie, webpage):
  65. mobj = re.search(
  66. r'<(?:object|a[^>]+class=["\']webcaster-player["\'])[^>]+data(?:-config)?=(["\']).*?config=(?P<url>https?://bl\.webcaster\.pro/feed/start/free_.*?)(?:[?&]|\1)',
  67. webpage)
  68. if mobj:
  69. return mobj.group('url')
  70. for secure in (True, False):
  71. video_url = ie._og_search_video_url(
  72. webpage, secure=secure, default=None)
  73. if video_url:
  74. mobj = re.search(
  75. r'config=(?P<url>https?://bl\.webcaster\.pro/feed/start/free_[^?&=]+)',
  76. video_url)
  77. if mobj:
  78. return mobj.group('url')
  79. def _real_extract(self, url):
  80. video_id = self._match_id(url)
  81. feed = self._download_xml(url, video_id)
  82. video_url = xpath_text(
  83. feed, ('video_hd', 'video'), 'video url', fatal=True)
  84. return self.url_result(video_url, WebcasterIE.ie_key())