[extractor/tvp] Support `stream.tvp.pl` (#6139)

Authored by: selfisekai
pull/6030/merge
lauren n. liberda 2 years ago committed by GitHub
parent cc2389c8ac
commit a31d0fa6c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -268,8 +268,11 @@ class TVPIE(InfoExtractor):
class TVPStreamIE(InfoExtractor): class TVPStreamIE(InfoExtractor):
IE_NAME = 'tvp:stream' IE_NAME = 'tvp:stream'
_VALID_URL = r'(?:tvpstream:|https?://tvpstream\.vod\.tvp\.pl/(?:\?(?:[^&]+[&;])*channel_id=)?)(?P<id>\d*)' _VALID_URL = r'(?:tvpstream:|https?://(?:tvpstream\.vod|stream)\.tvp\.pl/(?:\?(?:[^&]+[&;])*channel_id=)?)(?P<id>\d*)'
_TESTS = [{ _TESTS = [{
'url': 'https://stream.tvp.pl/?channel_id=56969941',
'only_matching': True,
}, {
# untestable as "video" id changes many times across a day # untestable as "video" id changes many times across a day
'url': 'https://tvpstream.vod.tvp.pl/?channel_id=1455', 'url': 'https://tvpstream.vod.tvp.pl/?channel_id=1455',
'only_matching': True, 'only_matching': True,
@ -285,28 +288,21 @@ class TVPStreamIE(InfoExtractor):
'only_matching': True, 'only_matching': True,
}] }]
_PLAYER_BOX_RE = r'<div\s[^>]*id\s*=\s*["\']?tvp_player_box["\']?[^>]+data-%s-id\s*=\s*["\']?(\d+)'
_BUTTON_RE = r'<div\s[^>]*data-channel-id=["\']?%s["\']?[^>]*\sdata-title=(?:"([^"]*)"|\'([^\']*)\')[^>]*\sdata-stationname=(?:"([^"]*)"|\'([^\']*)\')'
def _real_extract(self, url): def _real_extract(self, url):
channel_id = self._match_id(url) channel_id = self._match_id(url)
channel_url = self._proto_relative_url('//tvpstream.vod.tvp.pl/?channel_id=%s' % channel_id or 'default') channel_url = self._proto_relative_url('//stream.tvp.pl/?channel_id=%s' % channel_id or 'default')
webpage = self._download_webpage(channel_url, channel_id, 'Downloading channel webpage') webpage = self._download_webpage(channel_url, channel_id or 'default', 'Downloading channel webpage')
if not channel_id: channels = self._search_json(
channel_id = self._search_regex(self._PLAYER_BOX_RE % 'channel', r'window\.__channels\s*=', webpage, 'channel list', channel_id,
webpage, 'default channel id') contains_pattern=r'\[\s*{(?s:.+)}\s*]')
video_id = self._search_regex(self._PLAYER_BOX_RE % 'video', channel = traverse_obj(channels, (lambda _, v: channel_id == str(v['id'])), get_all=False) if channel_id else channels[0]
webpage, 'video id') audition = traverse_obj(channel, ('items', lambda _, v: v['is_live'] is True), get_all=False)
audition_title, station_name = self._search_regex(
self._BUTTON_RE % (re.escape(channel_id)), webpage,
'audition title and station name',
group=(1, 2))
return { return {
'_type': 'url_transparent', '_type': 'url_transparent',
'id': channel_id, 'id': channel_id or channel['id'],
'url': 'tvp:%s' % video_id, 'url': 'tvp:%s' % audition['video_id'],
'title': audition_title, 'title': audition.get('title'),
'alt_title': station_name, 'alt_title': channel.get('title'),
'is_live': True, 'is_live': True,
'ie_key': 'TVPEmbed', 'ie_key': 'TVPEmbed',
} }

Loading…
Cancel
Save