Last active
March 28, 2024 16:35
-
-
Save oexlkinq/eef0a260dddad473c5febafd91b980d9 to your computer and use it in GitHub Desktop.
seems to be working well (https://streamlink.github.io/plugins.html#vkplay)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
$description Russian live-streaming platform for gaming and esports, owned by VKontakte. | |
$url live.vkplay.ru | |
$type live | |
$metadata id | |
$metadata author | |
$metadata category | |
$metadata title | |
""" | |
import logging | |
import re | |
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?://live\.vkplay\.ru/(?P<channel_name>\w+)/?$", | |
)) | |
class VKplay(Plugin): | |
API_URL = "https://api.live.vkplay.ru/v1" | |
def _get_streams(self): | |
self.author = self.match.group("channel_name") | |
log.debug(f"Channel name: {self.author}") | |
data = self.session.http.get( | |
f"{self.API_URL}/blog/{self.author}/public_video_stream", | |
headers={"Referer": self.url}, | |
acceptable_status=(200, 404), | |
schema=validate.Schema( | |
validate.parse_json(), | |
validate.any( | |
validate.all( | |
{"error": str, "error_description": str}, | |
validate.get("error_description"), | |
), | |
validate.all( | |
{ | |
validate.optional("category"): validate.all( | |
{ | |
"title": str, | |
}, | |
validate.get("title"), | |
), | |
"title": str, | |
"data": validate.any( | |
[ | |
validate.all( | |
{ | |
"vid": str, | |
"playerUrls": [ | |
validate.all( | |
{ | |
"type": str, | |
"url": validate.any("", validate.url()), | |
}, | |
validate.union_get("type", "url"), | |
), | |
], | |
}, | |
validate.union_get("vid", "playerUrls"), | |
), | |
], | |
[], | |
), | |
}, | |
validate.union_get( | |
"category", | |
"title", | |
("data", 0), | |
), | |
), | |
), | |
), | |
) | |
if isinstance(data, str): | |
log.error(data) | |
return | |
self.category, self.title, streamdata = data | |
if not streamdata: | |
return | |
self.id, streams = streamdata | |
for streamtype, streamurl in streams: | |
if streamurl and streamtype == "live_hls": | |
return HLSStream.parse_variant_playlist(self.session, streamurl) | |
__plugin__ = VKplay |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment