]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/tvplayer.py
2 from __future__
import unicode_literals
4 from .common
import InfoExtractor
5 from ..compat
import compat_HTTPError
13 class TVPlayerIE(InfoExtractor
):
14 _VALID_URL
= r
'https?://(?:www\.)?tvplayer\.com/watch/(?P<id>[^/?#]+)'
16 'url': 'http://tvplayer.com/watch/bbcone',
20 'title': r
're:^BBC One [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
24 'skip_download': True,
28 def _real_extract(self
, url
):
29 display_id
= self
._match
_id
(url
)
30 webpage
= self
._download
_webpage
(url
, display_id
)
32 current_channel
= extract_attributes(self
._search
_regex
(
33 r
'(<div[^>]+class="[^"]*current-channel[^"]*"[^>]*>)',
34 webpage
, 'channel element'))
35 title
= current_channel
['data-name']
37 resource_id
= self
._search
_regex
(
38 r
'resourceId\s*=\s*"(\d+)"', webpage
, 'resource id')
39 platform
= self
._search
_regex
(
40 r
'platform\s*=\s*"([^"]+)"', webpage
, 'platform')
41 token
= self
._search
_regex
(
42 r
'token\s*=\s*"([^"]+)"', webpage
, 'token', default
='null')
43 validate
= self
._search
_regex
(
44 r
'validate\s*=\s*"([^"]+)"', webpage
, 'validate', default
='null')
47 response
= self
._download
_json
(
48 'http://api.tvplayer.com/api/v2/stream/live',
49 resource_id
, headers
={
50 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
51 }, data
=urlencode_postdata({
57 }))['tvplayer']['response']
58 except ExtractorError
as e
:
59 if isinstance(e
.cause
, compat_HTTPError
):
60 response
= self
._parse
_json
(
61 e
.cause
.read().decode(), resource_id
)['tvplayer']['response']
63 '%s said: %s' % (self
.IE_NAME
, response
['error']), expected
=True)
66 formats
= self
._extract
_m
3u8_formats
(response
['stream'], resource_id
, 'mp4')
67 self
._sort
_formats
(formats
)
71 'display_id': display_id
,
72 'title': self
._live
_title
(title
),