[rentv] Add new extractor(closes #10620)
[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 .jwplatform import JWPlatformBaseIE
6 from ..compat import compat_str
7
8
9 class RENTVIE(JWPlatformBaseIE):
10     _VALID_URL = r'(?:rentv:|https?://(?:www\.)?ren\.tv/(?:player|video/epizod)/)(?P<id>\d+)'
11     _TEST = {
12         'url': 'http://ren.tv/video/epizod/118577',
13         'md5': 'd91851bf9af73c0ad9b2cdf76c127fbb',
14         'info_dict': {
15             'id': '118577',
16             'ext': 'mp4',
17             'title': 'Документальный спецпроект: "Промывка мозгов. Технологии XXI века"'
18         }
19     }
20
21     def _real_extract(self, url):
22         video_id = self._match_id(url)
23         webpage = self._download_webpage('http://ren.tv/player/' + video_id, video_id)
24         jw_config = self._parse_json(self._search_regex(
25             r'config\s*=\s*({.+});', webpage, 'jw config'), video_id)
26         return self._parse_jwplayer_data(jw_config, video_id, m3u8_id='hls')
27
28
29 class RENTVArticleIE(InfoExtractor):
30     _VALID_URL = r'https?://(?:www\.)?ren\.tv/novosti/\d{4}-\d{2}-\d{2}/(?P<id>[^/?#]+)'
31     _TEST = {
32         'url': 'http://ren.tv/novosti/2016-10-26/video-mikroavtobus-popavshiy-v-dtp-s-gruzovikami-v-podmoskove-prevratilsya-v',
33         'md5': 'ebd63c4680b167693745ab91343df1d6',
34         'info_dict': {
35             'id': '136472',
36             'ext': 'mp4',
37             'title': 'Видео: микроавтобус, попавший в ДТП с грузовиками в Подмосковье, превратился в груду металла',
38             'description': 'Жертвами столкновения двух фур и микроавтобуса, по последним данным, стали семь человек.',
39         }
40     }
41
42     def _real_extract(self, url):
43         display_id = self._match_id(url)
44         webpage = self._download_webpage(url, display_id)
45         drupal_settings = self._parse_json(self._search_regex(
46             r'jQuery\.extend\(Drupal\.settings\s*,\s*({.+?})\);',
47             webpage, 'drupal settings'), display_id)
48
49         entries = []
50         for config_profile in drupal_settings.get('ren_jwplayer', {}).values():
51             media_id = config_profile.get('mediaid')
52             if not media_id:
53                 continue
54             media_id = compat_str(media_id)
55             entries.append(self.url_result('rentv:' + media_id, 'RENTV', media_id))
56         return self.playlist_result(entries, display_id)