[ie/wistia] Support password-protected videos (#11100)
[yt-dlp3.git] / yt_dlp / extractor / filmon.py
blobaf1de7ac83be7b0fe0866b334a75fe7e0b71ac64
1 from .common import InfoExtractor
2 from ..networking.exceptions import HTTPError
3 from ..utils import (
4 ExtractorError,
5 int_or_none,
6 qualities,
7 strip_or_none,
11 class FilmOnIE(InfoExtractor):
12 IE_NAME = 'filmon'
13 _VALID_URL = r'(?:https?://(?:www\.)?filmon\.com/vod/view/|filmon:)(?P<id>\d+)'
14 _TESTS = [{
15 'url': 'https://www.filmon.com/vod/view/24869-0-plan-9-from-outer-space',
16 'info_dict': {
17 'id': '24869',
18 'ext': 'mp4',
19 'title': 'Plan 9 From Outer Space',
20 'description': 'Dead human, zombies and vampires',
22 }, {
23 'url': 'https://www.filmon.com/vod/view/2825-1-popeye-series-1',
24 'info_dict': {
25 'id': '2825',
26 'title': 'Popeye Series 1',
27 'description': 'The original series of Popeye.',
29 'playlist_mincount': 8,
32 def _real_extract(self, url):
33 video_id = self._match_id(url)
35 try:
36 response = self._download_json(
37 f'https://www.filmon.com/api/vod/movie?id={video_id}',
38 video_id)['response']
39 except ExtractorError as e:
40 if isinstance(e.cause, HTTPError):
41 errmsg = self._parse_json(e.cause.response.read().decode(), video_id)['reason']
42 raise ExtractorError(f'{self.IE_NAME} said: {errmsg}', expected=True)
43 raise
45 title = response['title']
46 description = strip_or_none(response.get('description'))
48 if response.get('type_id') == 1:
49 entries = [self.url_result('filmon:' + episode_id) for episode_id in response.get('episodes', [])]
50 return self.playlist_result(entries, video_id, title, description)
52 QUALITY = qualities(('low', 'high'))
53 formats = []
54 for format_id, stream in response.get('streams', {}).items():
55 stream_url = stream.get('url')
56 if not stream_url:
57 continue
58 formats.append({
59 'format_id': format_id,
60 'url': stream_url,
61 'ext': 'mp4',
62 'quality': QUALITY(stream.get('quality')),
63 'protocol': 'm3u8_native',
66 thumbnails = []
67 poster = response.get('poster', {})
68 thumbs = poster.get('thumbs', {})
69 thumbs['poster'] = poster
70 for thumb_id, thumb in thumbs.items():
71 thumb_url = thumb.get('url')
72 if not thumb_url:
73 continue
74 thumbnails.append({
75 'id': thumb_id,
76 'url': thumb_url,
77 'width': int_or_none(thumb.get('width')),
78 'height': int_or_none(thumb.get('height')),
81 return {
82 'id': video_id,
83 'title': title,
84 'formats': formats,
85 'description': description,
86 'thumbnails': thumbnails,
90 class FilmOnChannelIE(InfoExtractor):
91 IE_NAME = 'filmon:channel'
92 _VALID_URL = r'https?://(?:www\.)?filmon\.com/(?:tv|channel)/(?P<id>[a-z0-9-]+)'
93 _TESTS = [{
94 # VOD
95 'url': 'http://www.filmon.com/tv/sports-haters',
96 'info_dict': {
97 'id': '4190',
98 'ext': 'mp4',
99 'title': 'Sports Haters',
100 'description': 'md5:dabcb4c1d9cfc77085612f1a85f8275d',
102 }, {
103 # LIVE
104 'url': 'https://www.filmon.com/channel/filmon-sports',
105 'only_matching': True,
106 }, {
107 'url': 'https://www.filmon.com/tv/2894',
108 'only_matching': True,
111 _THUMBNAIL_RES = [
112 ('logo', 56, 28),
113 ('big_logo', 106, 106),
114 ('extra_big_logo', 300, 300),
117 def _real_extract(self, url):
118 channel_id = self._match_id(url)
120 try:
121 channel_data = self._download_json(
122 'http://www.filmon.com/api-v2/channel/' + channel_id, channel_id)['data']
123 except ExtractorError as e:
124 if isinstance(e.cause, HTTPError):
125 errmsg = self._parse_json(e.cause.response.read().decode(), channel_id)['message']
126 raise ExtractorError(f'{self.IE_NAME} said: {errmsg}', expected=True)
127 raise
129 channel_id = str(channel_data['id'])
130 is_live = not channel_data.get('is_vod') and not channel_data.get('is_vox')
131 title = channel_data['title']
133 QUALITY = qualities(('low', 'high'))
134 formats = []
135 for stream in channel_data.get('streams', []):
136 stream_url = stream.get('url')
137 if not stream_url:
138 continue
139 if not is_live:
140 formats.extend(self._extract_wowza_formats(
141 stream_url, channel_id, skip_protocols=['dash', 'rtmp', 'rtsp']))
142 continue
143 quality = stream.get('quality')
144 formats.append({
145 'format_id': quality,
146 # this is an m3u8 stream, but we are deliberately not using _extract_m3u8_formats
147 # because it doesn't have bitrate variants anyway
148 'url': stream_url,
149 'ext': 'mp4',
150 'quality': QUALITY(quality),
153 thumbnails = []
154 for name, width, height in self._THUMBNAIL_RES:
155 thumbnails.append({
156 'id': name,
157 'url': f'http://static.filmon.com/assets/channels/{channel_id}/{name}.png',
158 'width': width,
159 'height': height,
162 return {
163 'id': channel_id,
164 'display_id': channel_data.get('alias'),
165 'title': title,
166 'description': channel_data.get('description'),
167 'thumbnails': thumbnails,
168 'formats': formats,
169 'is_live': is_live,