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.

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