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.

90 lines
3.3 KiB

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