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.

110 lines
4.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. ExtractorError,
  7. int_or_none,
  8. )
  9. class EaglePlatformIE(InfoExtractor):
  10. _VALID_URL = r'''(?x)
  11. (?:
  12. eagleplatform:(?P<custom_host>[^/]+):|
  13. https?://(?P<host>.+?\.media\.eagleplatform\.com)/index/player\?.*\brecord_id=
  14. )
  15. (?P<id>\d+)
  16. '''
  17. _TESTS = [{
  18. # http://lenta.ru/news/2015/03/06/navalny/
  19. 'url': 'http://lentaru.media.eagleplatform.com/index/player?player=new&record_id=227304&player_template_id=5201',
  20. 'md5': '70f5187fb620f2c1d503b3b22fd4efe3',
  21. 'info_dict': {
  22. 'id': '227304',
  23. 'ext': 'mp4',
  24. 'title': 'Навальный вышел на свободу',
  25. 'description': 'md5:d97861ac9ae77377f3f20eaf9d04b4f5',
  26. 'thumbnail': 're:^https?://.*\.jpg$',
  27. 'duration': 87,
  28. 'view_count': int,
  29. 'age_limit': 0,
  30. },
  31. }, {
  32. # http://muz-tv.ru/play/7129/
  33. # http://media.clipyou.ru/index/player?record_id=12820&width=730&height=415&autoplay=true
  34. 'url': 'eagleplatform:media.clipyou.ru:12820',
  35. 'md5': '90b26344ba442c8e44aa4cf8f301164a',
  36. 'info_dict': {
  37. 'id': '12820',
  38. 'ext': 'mp4',
  39. 'title': "'O Sole Mio",
  40. 'thumbnail': 're:^https?://.*\.jpg$',
  41. 'duration': 216,
  42. 'view_count': int,
  43. },
  44. 'skip': 'Georestricted',
  45. }]
  46. @staticmethod
  47. def _handle_error(response):
  48. status = int_or_none(response.get('status', 200))
  49. if status != 200:
  50. raise ExtractorError(' '.join(response['errors']), expected=True)
  51. def _download_json(self, url_or_request, video_id, note='Downloading JSON metadata'):
  52. response = super(EaglePlatformIE, self)._download_json(url_or_request, video_id, note)
  53. self._handle_error(response)
  54. return response
  55. def _get_video_url(self, url_or_request, video_id, note='Downloading JSON metadata'):
  56. return self._download_json(url_or_request, video_id, note)['data'][0]
  57. def _real_extract(self, url):
  58. mobj = re.match(self._VALID_URL, url)
  59. host, video_id = mobj.group('custom_host') or mobj.group('host'), mobj.group('id')
  60. player_data = self._download_json(
  61. 'http://%s/api/player_data?id=%s' % (host, video_id), video_id)
  62. media = player_data['data']['playlist']['viewports'][0]['medialist'][0]
  63. title = media['title']
  64. description = media.get('description')
  65. thumbnail = self._proto_relative_url(media.get('snapshot'), 'http:')
  66. duration = int_or_none(media.get('duration'))
  67. view_count = int_or_none(media.get('views'))
  68. age_restriction = media.get('age_restriction')
  69. age_limit = None
  70. if age_restriction:
  71. age_limit = 0 if age_restriction == 'allow_all' else 18
  72. secure_m3u8 = self._proto_relative_url(media['sources']['secure_m3u8']['auto'], 'http:')
  73. m3u8_url = self._get_video_url(secure_m3u8, video_id, 'Downloading m3u8 JSON')
  74. formats = self._extract_m3u8_formats(
  75. m3u8_url, video_id,
  76. 'mp4', entry_protocol='m3u8_native')
  77. mp4_url = self._get_video_url(
  78. # Secure mp4 URL is constructed according to Player.prototype.mp4 from
  79. # http://lentaru.media.eagleplatform.com/player/player.js
  80. re.sub(r'm3u8|hlsvod|hls|f4m', 'mp4', secure_m3u8),
  81. video_id, 'Downloading mp4 JSON')
  82. formats.append({'url': mp4_url, 'format_id': 'mp4'})
  83. self._sort_formats(formats)
  84. return {
  85. 'id': video_id,
  86. 'title': title,
  87. 'description': description,
  88. 'thumbnail': thumbnail,
  89. 'duration': duration,
  90. 'view_count': view_count,
  91. 'age_limit': age_limit,
  92. 'formats': formats,
  93. }