]>
Commit | Line | Data |
---|---|---|
1 | from .common import InfoExtractor | |
2 | from ..compat import compat_str | |
3 | from ..networking.exceptions import HTTPError | |
4 | from ..utils import ( | |
5 | ExtractorError, | |
6 | int_or_none, | |
7 | qualities, | |
8 | strip_or_none, | |
9 | ) | |
10 | ||
11 | ||
12 | class FilmOnIE(InfoExtractor): | |
13 | IE_NAME = 'filmon' | |
14 | _VALID_URL = r'(?:https?://(?:www\.)?filmon\.com/vod/view/|filmon:)(?P<id>\d+)' | |
15 | _TESTS = [{ | |
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 | }, | |
23 | }, { | |
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, | |
31 | }] | |
32 | ||
33 | def _real_extract(self, url): | |
34 | video_id = self._match_id(url) | |
35 | ||
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: | |
41 | if isinstance(e.cause, HTTPError): | |
42 | errmsg = self._parse_json(e.cause.response.read().decode(), video_id)['reason'] | |
43 | raise ExtractorError('%s said: %s' % (self.IE_NAME, errmsg), expected=True) | |
44 | raise | |
45 | ||
46 | title = response['title'] | |
47 | description = strip_or_none(response.get('description')) | |
48 | ||
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) | |
52 | ||
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 | |
59 | formats.append({ | |
60 | 'format_id': format_id, | |
61 | 'url': stream_url, | |
62 | 'ext': 'mp4', | |
63 | 'quality': QUALITY(stream.get('quality')), | |
64 | 'protocol': 'm3u8_native', | |
65 | }) | |
66 | ||
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 | ||
82 | return { | |
83 | 'id': video_id, | |
84 | 'title': title, | |
85 | 'formats': formats, | |
86 | 'description': description, | |
87 | 'thumbnails': thumbnails, | |
88 | } | |
89 | ||
90 | ||
91 | class FilmOnChannelIE(InfoExtractor): | |
92 | IE_NAME = 'filmon:channel' | |
93 | _VALID_URL = r'https?://(?:www\.)?filmon\.com/(?:tv|channel)/(?P<id>[a-z0-9-]+)' | |
94 | _TESTS = [{ | |
95 | # VOD | |
96 | 'url': 'http://www.filmon.com/tv/sports-haters', | |
97 | 'info_dict': { | |
98 | 'id': '4190', | |
99 | 'ext': 'mp4', | |
100 | 'title': 'Sports Haters', | |
101 | 'description': 'md5:dabcb4c1d9cfc77085612f1a85f8275d', | |
102 | }, | |
103 | }, { | |
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, | |
110 | }] | |
111 | ||
112 | _THUMBNAIL_RES = [ | |
113 | ('logo', 56, 28), | |
114 | ('big_logo', 106, 106), | |
115 | ('extra_big_logo', 300, 300), | |
116 | ] | |
117 | ||
118 | def _real_extract(self, url): | |
119 | channel_id = self._match_id(url) | |
120 | ||
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: | |
125 | if isinstance(e.cause, HTTPError): | |
126 | errmsg = self._parse_json(e.cause.response.read().decode(), channel_id)['message'] | |
127 | raise ExtractorError('%s said: %s' % (self.IE_NAME, errmsg), expected=True) | |
128 | raise | |
129 | ||
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'] | |
133 | ||
134 | QUALITY = qualities(('low', 'high')) | |
135 | formats = [] | |
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') | |
145 | formats.append({ | |
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, | |
150 | 'ext': 'mp4', | |
151 | 'quality': QUALITY(quality), | |
152 | }) | |
153 | ||
154 | thumbnails = [] | |
155 | for name, width, height in self._THUMBNAIL_RES: | |
156 | thumbnails.append({ | |
157 | 'id': name, | |
158 | 'url': 'http://static.filmon.com/assets/channels/%s/%s.png' % (channel_id, name), | |
159 | 'width': width, | |
160 | 'height': height, | |
161 | }) | |
162 | ||
163 | return { | |
164 | 'id': channel_id, | |
165 | 'display_id': channel_data.get('alias'), | |
166 | 'title': title, | |
167 | 'description': channel_data.get('description'), | |
168 | 'thumbnails': thumbnails, | |
169 | 'formats': formats, | |
170 | 'is_live': is_live, | |
171 | } |