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