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.

105 lines
3.7KB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. determine_ext,
  6. int_or_none,
  7. url_or_none,
  8. )
  9. class YandexVideoIE(InfoExtractor):
  10. _VALID_URL = r'''(?x)
  11. https?://
  12. (?:
  13. yandex\.ru(?:/portal/(?:video|efir))?/?\?.*?stream_id=|
  14. frontend\.vh\.yandex\.ru/player/
  15. )
  16. (?P<id>[\da-f]+)
  17. '''
  18. _TESTS = [{
  19. 'url': 'https://yandex.ru/portal/video?stream_id=4dbb262b4fe5cf15a215de4f34eee34d',
  20. 'md5': '33955d7ae052f15853dc41f35f17581c',
  21. 'info_dict': {
  22. 'id': '4dbb262b4fe5cf15a215de4f34eee34d',
  23. 'ext': 'mp4',
  24. 'title': 'В Нью-Йорке баржи и теплоход оторвались от причала и расплылись по Гудзону',
  25. 'description': '',
  26. 'thumbnail': r're:^https?://.*\.jpg$',
  27. 'timestamp': 0,
  28. 'duration': 30,
  29. 'age_limit': 18,
  30. },
  31. }, {
  32. 'url': 'https://yandex.ru/portal/efir?stream_id=4dbb36ec4e0526d58f9f2dc8f0ecf374&from=morda',
  33. 'only_matching': True,
  34. }, {
  35. 'url': 'https://yandex.ru/?stream_id=4dbb262b4fe5cf15a215de4f34eee34d',
  36. 'only_matching': True,
  37. }, {
  38. 'url': 'https://frontend.vh.yandex.ru/player/4dbb262b4fe5cf15a215de4f34eee34d?from=morda',
  39. 'only_matching': True,
  40. }, {
  41. # vod-episode, series episode
  42. 'url': 'https://yandex.ru/portal/video?stream_id=45b11db6e4b68797919c93751a938cee',
  43. 'only_matching': True,
  44. }, {
  45. # episode, sports
  46. 'url': 'https://yandex.ru/?stream_channel=1538487871&stream_id=4132a07f71fb0396be93d74b3477131d',
  47. 'only_matching': True,
  48. }, {
  49. # DASH with DRM
  50. 'url': 'https://yandex.ru/portal/video?from=morda&stream_id=485a92d94518d73a9d0ff778e13505f8',
  51. 'only_matching': True,
  52. }]
  53. def _real_extract(self, url):
  54. video_id = self._match_id(url)
  55. content = self._download_json(
  56. 'https://frontend.vh.yandex.ru/v22/player/%s.json' % video_id,
  57. video_id, query={
  58. 'stream_options': 'hires',
  59. 'disable_trackings': 1,
  60. })['content']
  61. content_url = url_or_none(content.get('content_url')) or url_or_none(
  62. content['streams'][0]['url'])
  63. title = content.get('title') or content.get('computed_title')
  64. ext = determine_ext(content_url)
  65. if ext == 'm3u8':
  66. formats = self._extract_m3u8_formats(
  67. content_url, video_id, 'mp4', entry_protocol='m3u8_native',
  68. m3u8_id='hls')
  69. elif ext == 'mpd':
  70. formats = self._extract_mpd_formats(
  71. content_url, video_id, mpd_id='dash')
  72. else:
  73. formats = [{'url': content_url}]
  74. self._sort_formats(formats)
  75. description = content.get('description')
  76. thumbnail = content.get('thumbnail')
  77. timestamp = (int_or_none(content.get('release_date'))
  78. or int_or_none(content.get('release_date_ut'))
  79. or int_or_none(content.get('start_time')))
  80. duration = int_or_none(content.get('duration'))
  81. series = content.get('program_title')
  82. age_limit = int_or_none(content.get('restriction_age'))
  83. return {
  84. 'id': video_id,
  85. 'title': title,
  86. 'description': description,
  87. 'thumbnail': thumbnail,
  88. 'timestamp': timestamp,
  89. 'duration': duration,
  90. 'series': series,
  91. 'age_limit': age_limit,
  92. 'formats': formats,
  93. }