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