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