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