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.

98 lines
3.4 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': '0b7994faa2bd5c0f69a3db6db28d078d',
  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': '6c2ebeab03b739597ce8d86339d5a905',
  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. }]
  45. def _handle_error(self, response):
  46. status = int_or_none(response.get('status', 200))
  47. if status != 200:
  48. raise ExtractorError(' '.join(response['errors']), expected=True)
  49. def _download_json(self, url_or_request, video_id, note='Downloading JSON metadata'):
  50. response = super(EaglePlatformIE, self)._download_json(url_or_request, video_id, note)
  51. self._handle_error(response)
  52. return response
  53. def _real_extract(self, url):
  54. mobj = re.match(self._VALID_URL, url)
  55. host, video_id = mobj.group('custom_host') or mobj.group('host'), mobj.group('id')
  56. player_data = self._download_json(
  57. 'http://%s/api/player_data?id=%s' % (host, video_id), video_id)
  58. media = player_data['data']['playlist']['viewports'][0]['medialist'][0]
  59. title = media['title']
  60. description = media.get('description')
  61. thumbnail = media.get('snapshot')
  62. duration = int_or_none(media.get('duration'))
  63. view_count = int_or_none(media.get('views'))
  64. age_restriction = media.get('age_restriction')
  65. age_limit = None
  66. if age_restriction:
  67. age_limit = 0 if age_restriction == 'allow_all' else 18
  68. m3u8_data = self._download_json(
  69. media['sources']['secure_m3u8']['auto'],
  70. video_id, 'Downloading m3u8 JSON')
  71. formats = self._extract_m3u8_formats(
  72. m3u8_data['data'][0], video_id,
  73. 'mp4', entry_protocol='m3u8_native')
  74. self._sort_formats(formats)
  75. return {
  76. 'id': video_id,
  77. 'title': title,
  78. 'description': description,
  79. 'thumbnail': thumbnail,
  80. 'duration': duration,
  81. 'view_count': view_count,
  82. 'age_limit': age_limit,
  83. 'formats': formats,
  84. }