Skip to content

Commit

Permalink
[PATCH] plugins.vkplay: new plugin (streamlink#5054)
Browse files Browse the repository at this point in the history
Co-Authored-By: bastimeyer <mail@bastimeyer.de>
  • Loading branch information
2 people authored and Billy2011 committed Jan 6, 2023
1 parent cb7a1db commit 769e5c6
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
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("Channel name: {0}".format(self.author))

data = self.session.http.get(
"{0}/blog/{1}/public_video_stream".format(self.API_URL, self.author),
headers={"Referer": self.url},
acceptable_status=(200, 404),
schema=validate.Schema(
validate.parse_json(),
validate.any(
validate.all(
{"error": validate.text, "error_description": validate.text},
validate.get("error_description"),
),
validate.all(
{
"category": {
"title": validate.text,
},
"title": validate.text,
"data": validate.any(
[
validate.all(
{
"vid": validate.text,
"playerUrls": [
validate.all(
{
"type": validate.text,
"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 validate.text:
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
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",
]

0 comments on commit 769e5c6

Please sign in to comment.