]>
Commit | Line | Data |
---|---|---|
777d90dc RA |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | from .common import InfoExtractor | |
777d90dc | 5 | from ..compat import compat_str |
a693386d S |
6 | from ..utils import ( |
7 | determine_ext, | |
8 | int_or_none, | |
3052a30d | 9 | url_or_none, |
a693386d | 10 | ) |
777d90dc RA |
11 | |
12 | ||
a4a554a7 | 13 | class RENTVIE(InfoExtractor): |
777d90dc | 14 | _VALID_URL = r'(?:rentv:|https?://(?:www\.)?ren\.tv/(?:player|video/epizod)/)(?P<id>\d+)' |
773017c6 | 15 | _TESTS = [{ |
777d90dc RA |
16 | 'url': 'http://ren.tv/video/epizod/118577', |
17 | 'md5': 'd91851bf9af73c0ad9b2cdf76c127fbb', | |
18 | 'info_dict': { | |
19 | 'id': '118577', | |
20 | 'ext': 'mp4', | |
a693386d S |
21 | 'title': 'Документальный спецпроект: "Промывка мозгов. Технологии XXI века"', |
22 | 'timestamp': 1472230800, | |
23 | 'upload_date': '20160826', | |
777d90dc | 24 | } |
773017c6 S |
25 | }, { |
26 | 'url': 'http://ren.tv/player/118577', | |
27 | 'only_matching': True, | |
28 | }, { | |
29 | 'url': 'rentv:118577', | |
30 | 'only_matching': True, | |
31 | }] | |
777d90dc RA |
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) | |
4b8588fe | 36 | config = self._parse_json(self._search_regex( |
a693386d S |
37 | r'config\s*=\s*({.+})\s*;', webpage, 'config'), video_id) |
38 | title = config['title'] | |
4b8588fe | 39 | formats = [] |
a693386d | 40 | for video in config['src']: |
3052a30d S |
41 | src = url_or_none(video.get('src')) |
42 | if not src: | |
a693386d S |
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 | }) | |
4b8588fe | 53 | self._sort_formats(formats) |
54 | return { | |
55 | 'id': video_id, | |
a693386d S |
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')), | |
4b8588fe | 61 | 'formats': formats, |
4b8588fe | 62 | } |
777d90dc RA |
63 | |
64 | ||
65 | class RENTVArticleIE(InfoExtractor): | |
66 | _VALID_URL = r'https?://(?:www\.)?ren\.tv/novosti/\d{4}-\d{2}-\d{2}/(?P<id>[^/?#]+)' | |
773017c6 | 67 | _TESTS = [{ |
777d90dc RA |
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 | } | |
773017c6 S |
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 | }] | |
777d90dc RA |
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) |