]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/tvplayer.py
2 from __future__
import unicode_literals
4 from .common
import InfoExtractor
17 class TVPlayerIE(InfoExtractor
):
18 _VALID_URL
= r
'https?://(?:www\.)?tvplayer\.com/watch/(?P<id>[^/?#]+)'
20 'url': 'http://tvplayer.com/watch/bbcone',
24 'title': r
're:^BBC One [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
28 'skip_download': True,
32 def _real_extract(self
, url
):
33 display_id
= self
._match
_id
(url
)
34 webpage
= self
._download
_webpage
(url
, display_id
)
36 current_channel
= extract_attributes(self
._search
_regex
(
37 r
'(<div[^>]+class="[^"]*current-channel[^"]*"[^>]*>)',
38 webpage
, 'channel element'))
39 title
= current_channel
['data-name']
41 resource_id
= current_channel
['data-id']
43 token
= self
._search
_regex
(
44 r
'data-token=(["\'])(?P
<token
>(?
!\
1).+)\
1', webpage,
45 'token
', group='token
')
47 context = self._download_json(
48 'https
://tvplayer
.com
/watch
/context
', display_id,
49 'Downloading JSON context
', query={
50 'resource
': resource_id,
54 validate = context['validate
']
56 context, lambda x: x['platform
']['key
'], compat_str) or 'firefox
'
59 response = self._download_json(
60 'http
://api
.tvplayer
.com
/api
/v2
/stream
/live
',
61 display_id, 'Downloading JSON stream
', headers={
62 'Content
-Type
': 'application
/x
-www
-form
-urlencoded
; charset
=UTF
-8',
63 }, data=urlencode_postdata({
68 }))['tvplayer
']['response
']
69 except ExtractorError as e:
70 if isinstance(e.cause, compat_HTTPError):
71 response = self._parse_json(
72 e.cause.read().decode(), resource_id)['tvplayer
']['response
']
74 '%s said
: %s' % (self.IE_NAME, response['error
']), expected=True)
77 formats = self._extract_m3u8_formats(response['stream
'], display_id, 'mp4
')
78 self._sort_formats(formats)
82 'display_id
': display_id,
83 'title
': self._live_title(title),