plugins.piaulizaportal: new plugin

Co-authored-by: bastimeyer <mail@bastimeyer.de>
This commit is contained in:
Mozi 2023-08-22 06:17:45 +08:00 committed by GitHub
parent 5a69669013
commit 9d5e2bfc17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 99 additions and 0 deletions

View File

@ -0,0 +1,76 @@
"""
$description Japanese live-streaming and video hosting platform owned by PIA Corporation.
$url ulizaportal.jp
$type live, vod
$account Purchased tickets are required.
$notes Tickets purchased at "PIA LIVE STREAM" are used for this platform.
"""
import logging
import re
import time
from urllib.parse import parse_qsl, urlparse
from streamlink.plugin import Plugin, pluginmatcher
from streamlink.plugin.api import validate
from streamlink.stream.hls import HLSStream
log = logging.getLogger(__name__)
@pluginmatcher(re.compile(
r"https://ulizaportal\.jp/pages/(?P<id>[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})",
))
class PIAULIZAPortal(Plugin):
_URL_PLAYER_DATA = "https://player-api.p.uliza.jp/v1/players/"
_URL_PLAYLIST = "https://vms-api.p.uliza.jp/v1/prog-index.m3u8"
def _get_streams(self):
self.id = self.match.group("id")
try:
expires = int(dict(parse_qsl(urlparse(self.url).query)).get("expires", 0))
except ValueError:
expires = 0
if 0 < expires <= time.time():
log.error("The URL has expired")
return None
self.title, player_data_url = self.session.http.get(
self.url,
schema=validate.Schema(
validate.parse_html(),
validate.union((
validate.xml_xpath_string(".//head/title[1]/text()"),
validate.xml_xpath_string(
f".//script[@type='text/javascript'][contains(@src,'{self._URL_PLAYER_DATA}')][1]/@src",
),
)),
),
)
if not player_data_url:
log.error("Player data URL not found")
return None
m3u8_url = self.session.http.get(
player_data_url,
headers={
"Referer": self.url,
},
schema=validate.Schema(
re.compile(rf"""{re.escape(self._URL_PLAYLIST)}[^"']+"""),
validate.none_or_all(
validate.get(0),
validate.url(),
),
),
)
if not m3u8_url:
log.error("Playlist URL not found")
return None
return HLSStream.parse_variant_playlist(self.session, m3u8_url)
__plugin__ = PIAULIZAPortal

View File

@ -0,0 +1,23 @@
from streamlink.plugins.piaulizaportal import PIAULIZAPortal
from tests.plugins import PluginCanHandleUrl
class TestPluginCanHandleUrlPIAULIZAPortal(PluginCanHandleUrl):
__plugin__ = PIAULIZAPortal
should_match_groups = [
(
"https://ulizaportal.jp/pages/005f18b7-e810-5618-cb82-0987c5755d44",
{"id": "005f18b7-e810-5618-cb82-0987c5755d44"},
),
(
"https://ulizaportal.jp/pages/005e1b23-fe93-5780-19a0-98e917cc4b7d"
+ "?expires=4102412400&signature=f422a993b683e1068f946caf406d211c17d1ef17da8bef3df4a519502155aa91&version=1",
{"id": "005e1b23-fe93-5780-19a0-98e917cc4b7d"},
),
]
should_not_match = [
"https://ulizaportal.jp/pages/",
"https://ulizaportal.jp/pages/invalid-id",
]