rentv.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. determine_ext,
  4. int_or_none,
  5. url_or_none,
  6. )
  7. class RENTVIE(InfoExtractor):
  8. _WORKING = False
  9. _VALID_URL = r'(?:rentv:|https?://(?:www\.)?ren\.tv/(?:player|video/epizod)/)(?P<id>\d+)'
  10. _TESTS = [{
  11. 'url': 'http://ren.tv/video/epizod/118577',
  12. 'md5': 'd91851bf9af73c0ad9b2cdf76c127fbb',
  13. 'info_dict': {
  14. 'id': '118577',
  15. 'ext': 'mp4',
  16. 'title': 'Документальный спецпроект: "Промывка мозгов. Технологии XXI века"',
  17. 'timestamp': 1472230800,
  18. 'upload_date': '20160826',
  19. },
  20. }, {
  21. 'url': 'http://ren.tv/player/118577',
  22. 'only_matching': True,
  23. }, {
  24. 'url': 'rentv:118577',
  25. 'only_matching': True,
  26. }]
  27. def _real_extract(self, url):
  28. video_id = self._match_id(url)
  29. webpage = self._download_webpage('http://ren.tv/player/' + video_id, video_id)
  30. config = self._parse_json(self._search_regex(
  31. r'config\s*=\s*({.+})\s*;', webpage, 'config'), video_id)
  32. title = config['title']
  33. formats = []
  34. for video in config['src']:
  35. src = url_or_none(video.get('src'))
  36. if not src:
  37. continue
  38. ext = determine_ext(src)
  39. if ext == 'm3u8':
  40. formats.extend(self._extract_m3u8_formats(
  41. src, video_id, 'mp4', entry_protocol='m3u8_native',
  42. m3u8_id='hls', fatal=False))
  43. else:
  44. formats.append({
  45. 'url': src,
  46. })
  47. return {
  48. 'id': video_id,
  49. 'title': title,
  50. 'description': config.get('description'),
  51. 'thumbnail': config.get('image'),
  52. 'duration': int_or_none(config.get('duration')),
  53. 'timestamp': int_or_none(config.get('date')),
  54. 'formats': formats,
  55. }
  56. class RENTVArticleIE(InfoExtractor):
  57. _WORKING = False
  58. _VALID_URL = r'https?://(?:www\.)?ren\.tv/novosti/\d{4}-\d{2}-\d{2}/(?P<id>[^/?#]+)'
  59. _TESTS = [{
  60. 'url': 'http://ren.tv/novosti/2016-10-26/video-mikroavtobus-popavshiy-v-dtp-s-gruzovikami-v-podmoskove-prevratilsya-v',
  61. 'md5': 'ebd63c4680b167693745ab91343df1d6',
  62. 'info_dict': {
  63. 'id': '136472',
  64. 'ext': 'mp4',
  65. 'title': 'Видео: микроавтобус, попавший в ДТП с грузовиками в Подмосковье, превратился в груду металла',
  66. 'description': 'Жертвами столкновения двух фур и микроавтобуса, по последним данным, стали семь человек.',
  67. },
  68. }, {
  69. # TODO: invalid m3u8
  70. 'url': 'http://ren.tv/novosti/2015-09-25/sluchaynyy-prohozhiy-poymal-avtougonshchika-v-murmanske-video',
  71. 'info_dict': {
  72. 'id': 'playlist',
  73. 'ext': 'mp4',
  74. 'title': 'Случайный прохожий поймал автоугонщика в Мурманске. ВИДЕО | РЕН ТВ',
  75. 'uploader': 'ren.tv',
  76. },
  77. 'params': {
  78. # m3u8 downloads
  79. 'skip_download': True,
  80. },
  81. 'skip': True,
  82. }]
  83. def _real_extract(self, url):
  84. display_id = self._match_id(url)
  85. webpage = self._download_webpage(url, display_id)
  86. drupal_settings = self._parse_json(self._search_regex(
  87. r'jQuery\.extend\(Drupal\.settings\s*,\s*({.+?})\);',
  88. webpage, 'drupal settings'), display_id)
  89. entries = []
  90. for config_profile in drupal_settings.get('ren_jwplayer', {}).values():
  91. media_id = config_profile.get('mediaid')
  92. if not media_id:
  93. continue
  94. media_id = str(media_id)
  95. entries.append(self.url_result('rentv:' + media_id, 'RENTV', media_id))
  96. return self.playlist_result(entries, display_id)