1 from .common
import InfoExtractor
2 from ..networking
.exceptions
import HTTPError
11 class TVPlayerIE(InfoExtractor
):
12 _VALID_URL
= r
'https?://(?:www\.)?tvplayer\.com/watch/(?P<id>[^/?#]+)'
14 'url': 'http://tvplayer.com/watch/bbcone',
18 'title': r
're:^BBC One [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
22 'skip_download': True,
26 def _real_extract(self
, url
):
27 display_id
= self
._match
_id
(url
)
28 webpage
= self
._download
_webpage
(url
, display_id
)
30 current_channel
= extract_attributes(self
._search
_regex
(
31 r
'(<div[^>]+class="[^"]*current-channel[^"]*"[^>]*>)',
32 webpage
, 'channel element'))
33 title
= current_channel
['data-name']
35 resource_id
= current_channel
['data-id']
37 token
= self
._search
_regex
(
38 r
'data-token=(["\'])(?P
<token
>(?
!\
1).+)\
1', webpage,
39 'token
', group='token
')
41 context = self._download_json(
42 'https
://tvplayer
.com
/watch
/context
', display_id,
43 'Downloading JSON context
', query={
44 'resource
': resource_id,
48 validate = context['validate
']
50 context, lambda x: x['platform
']['key
'], str) or 'firefox
'
53 response = self._download_json(
54 'http
://api
.tvplayer
.com
/api
/v2
/stream
/live
',
55 display_id, 'Downloading JSON stream
', headers={
56 'Content
-Type
': 'application
/x
-www
-form
-urlencoded
; charset
=UTF
-8',
57 }, data=urlencode_postdata({
62 }))['tvplayer
']['response
']
63 except ExtractorError as e:
64 if isinstance(e.cause, HTTPError):
65 response = self._parse_json(
66 e.cause.response.read().decode(), resource_id)['tvplayer
']['response
']
68 '{} said
: {}'.format(self.IE_NAME, response['error
']), expected=True)
71 formats = self._extract_m3u8_formats(response['stream
'], display_id, 'mp4
')
75 'display_id
': display_id,