rentv.py 3.4 KB

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