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