Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugins.vkplay: new plugin #5054

Merged
merged 3 commits into from
Dec 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions src/streamlink/plugins/vkplay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
"""
$description Russian live-streaming platform for gaming and esports, owned by VKontakte.
$url vkplay.live
$type live
"""

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?://vkplay\.live/(?P<channel_name>\w+)/?$",
))
class VKplay(Plugin):
API_URL = "https://api.vkplay.live/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(
{
"category": {
"title": str,
},
"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"),
"title",
("data", 0),
),
),
),
),
)
if type(data) is 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)
bastimeyer marked this conversation as resolved.
Show resolved Hide resolved


__plugin__ = VKplay
17 changes: 17 additions & 0 deletions tests/plugins/test_vkplay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from streamlink.plugins.vkplay import VKplay
from tests.plugins import PluginCanHandleUrl


class TestPluginCanHandleUrlVKplay(PluginCanHandleUrl):
__plugin__ = VKplay

should_match = [
"https://vkplay.live/Channel_Name_123",
]

should_not_match = [
"https://vkplay.live/",
"https://support.vkplay.ru/vkp_live",
"https://vkplay.live/app/settings/edit",
"https://vkplay.live/app/settings/external-apps",
]