2 from __future__ import unicode_literals
4 from .common import InfoExtractor
5 from ..utils import qualities
6 from ..compat import compat_urllib_request
9 _QUALITY = qualities(('low', 'high'))
12 class FilmOnIE(InfoExtractor):
13 _VALID_URL = r'https?://(?:www\.)?filmon\.com/(?:tv|channel)/(?P<id>[a-z0-9-]+)'
15 'url': 'https://www.filmon.com/channel/filmon-sports',
16 'only_matching': True,
18 'url': 'https://www.filmon.com/tv/2894',
19 'only_matching': True,
22 def _real_extract(self, url):
23 channel_id = self._match_id(url)
25 request = compat_urllib_request.Request('https://www.filmon.com/channel/%s' % (channel_id))
26 request.add_header('X-Requested-With', 'XMLHttpRequest')
27 channel_info = self._download_json(request, channel_id)
28 now_playing = channel_info['now_playing']
31 for thumb in now_playing.get('images', ()):
32 if thumb['type'] != '2':
36 'width': int(thumb['width']),
37 'height': int(thumb['height']),
42 for stream in channel_info['streams']:
44 'format_id': str(stream['id']),
45 # this is an m3u8 stream, but we are deliberately not using _extract_m3u8_formats
46 # because 0) it doesn't have bitrate variants anyway, and 1) the ids generated
47 # by that method are highly unstable (because the bitrate is variable)
49 'resolution': stream['name'],
50 'format_note': 'expires after %u seconds' % int(stream['watch-timeout']),
52 'quality': _QUALITY(stream['quality']),
53 'preference': int(stream['watch-timeout']),
55 self._sort_formats(formats)
58 'id': str(channel_info['id']),
59 'display_id': channel_info['alias'],
61 # XXX: use the channel description (channel_info['description'])?
62 'uploader_id': channel_info['alias'],
63 'uploader': channel_info['title'], # XXX: kinda stretching it...
64 'title': now_playing.get('programme_name') or channel_info['title'],
65 'description': now_playing.get('programme_description'),
66 'thumbnails': thumbnails,
71 class FilmOnVODIE(InfoExtractor):
72 _VALID_URL = r'https?://(?:www\.)?filmon\.com/vod/view/(?P<id>\d+)'
74 'url': 'https://www.filmon.com/vod/view/24869-0-plan-9-from-outer-space',
78 'title': 'Plan 9 From Outer Space',
79 'description': 'Dead human, zombies and vampires',
82 'url': 'https://www.filmon.com/vod/view/2825-1-popeye-series-1',
85 'title': 'Popeye Series 1',
90 def _real_extract(self, url):
91 video_id = self._match_id(url)
93 result = self._download_json('https://www.filmon.com/api/vod/movie?id=%s' % (video_id), video_id)
94 if result['code'] != 200:
95 raise ExtractorError('FilmOn said: %s' % (result['reason']), expected=True)
97 response = result['response']
99 if response.get('episodes'):
103 'title': response['title'],
106 'url': 'https://www.filmon.com/vod/view/%s' % (ep),
107 } for ep in response['episodes']]
111 for (id, stream) in response['streams'].items():
114 'url': stream['url'],
115 'resolution': stream['name'],
116 'format_note': 'expires after %u seconds' % int(stream['watch-timeout']),
118 'quality': _QUALITY(stream['quality']),
119 'preference': int(stream['watch-timeout']),
121 self._sort_formats(formats)
123 poster = response['poster']
126 'url': poster['url'],
127 'width': poster['width'],
128 'height': poster['height'],
130 for (id, thumb) in poster['thumbs'].items():
134 'width': thumb['width'],
135 'height': thumb['height'],
140 'title': response['title'],
142 'description': response['description'],
143 'thumbnails': thumbnails,