forked from streamlink/streamlink
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PATCH] plugins.vkplay: new plugin (streamlink#5054)
Co-Authored-By: bastimeyer <mail@bastimeyer.de>
- Loading branch information
Showing
2 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
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
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 |
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
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", | ||
] |