rtlnow is now hosted at nowtv.de
[youtube-dl] / youtube_dl / extractor / nowtv.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8     ExtractorError,
9     qualities,
10     unified_strdate,
11     int_or_none,
12 )
13
14 class NowTvIE(InfoExtractor):
15     """Information Extractor for RTL NOW, RTL2 NOW, RTL NITRO, SUPER RTL NOW, VOX NOW and n-tv NOW"""
16     _VALID_URL = r'''(?x)
17                         (?:https?://)?
18                         (
19                             (?:www\.)?nowtv\.de
20                             /(rtl|rtl2|rtlnitro||superrtl|ntv|vox)(?P<path>/.*?)/player
21                         )'''
22
23     _TESTS = [
24         {
25             'url': 'http://www.nowtv.de/vox/der-hundeprofi/buero-fall-chihuahua-joel/player',
26             'info_dict': {
27                 'id': '128953',
28                 'ext': 'mp4',
29                 'title': 'B\u00fcro-Fall \/ Chihuahua \'Joel\'',
30                 'description': 'md5:ce843b6b5901d9a7f7d04d1bbcdb12de',
31                 'upload_date': '2015-05-23 19:10:00',
32                 'duration': '00:51:32',
33             },
34             'params': {
35                 'skip_download': True,
36             },
37             'skip': 'Only works from Germany',
38         },
39     ]
40
41     def _real_extract(self, url):
42         mobj = re.match(self._VALID_URL, url)
43         info_url = 'https://api.nowtv.de/v3/movies' + mobj.group('path') + '?fields=*,format,files,breakpoints,paymentPaytypes,trailers'
44         info = self._download_json(info_url, None)
45
46         video_id = info['id']
47         title = info['title']
48         description = info['articleShort']
49         duration = info['duration']
50         upload_date = unified_strdate(info['broadcastStartDate'])
51         free = info['free']
52         station = info['format']['station']
53         thumbnail = info['format']['defaultImage169Logo']
54
55         if station == 'rtl':
56             base_url = 'http://hls.fra.rtlnow.de/hls-vod-enc/'
57         elif station == 'rtl2':
58             base_url = 'http://hls.fra.rtl2now.de/hls-vod-enc/'
59         elif station == 'vox':
60             base_url = 'http://hls.fra.voxnow.de/hls-vod-enc/'
61         elif station == 'nitro':
62             base_url = 'http://hls.fra.rtlnitronow.de/hls-vod-enc/'
63         elif station == 'ntv':
64             base_url = 'http://hls.fra.n-tvnow.de/hls-vod-enc/'
65         elif station == 'superrtl':
66             base_url = 'http://hls.fra.superrtlnow.de/hls-vod-enc/'
67
68         formats = []
69         for item in info['files']['items']:
70             if item['type'] != 'video/x-abr':
71                 continue
72
73             fmt = {
74                 'url': base_url + item['path'] + '.m3u8',
75                 'tbr': int_or_none(item['bitrate']),
76                 'ext': 'mp4',
77                 'format_id': int_or_none(item['id']),
78             }
79             formats.append(fmt)
80         self._sort_formats(formats)
81
82         return {
83             'id': video_id,
84             'title': title,
85             'description': description,
86             'thumbnail': thumbnail,
87             'upload_date': upload_date,
88             'duration': duration,
89             'formats': formats,
90         }