mirror of
https://github.com/streamlink/streamlink
synced 2024-11-01 01:19:33 +01:00
Add ok.ru/live plugin
This commit is contained in:
parent
b839cfd76b
commit
dc3230ca32
41
src/streamlink/plugins/ok_live.py
Normal file
41
src/streamlink/plugins/ok_live.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import urllib3
|
||||||
|
import re
|
||||||
|
|
||||||
|
from streamlink.plugin import Plugin
|
||||||
|
from streamlink.plugin.api import http, validate
|
||||||
|
from streamlink.plugin.api import useragents
|
||||||
|
from streamlink.stream import HLSStream
|
||||||
|
|
||||||
|
_url_re = re.compile(r"https?://(www\.)?ok\.ru/live/\d+")
|
||||||
|
_vod_re = re.compile(r";(?P<hlsurl>[^;]+video\.m3u8)")
|
||||||
|
|
||||||
|
_schema = validate.Schema(
|
||||||
|
validate.transform(_vod_re.search),
|
||||||
|
validate.any(
|
||||||
|
None,
|
||||||
|
validate.all(
|
||||||
|
validate.get("hlsurl"),
|
||||||
|
validate.url()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
class OK_live(Plugin):
|
||||||
|
"""
|
||||||
|
Support for ok.ru live stream: http://www.ok.ru/live/
|
||||||
|
"""
|
||||||
|
@classmethod
|
||||||
|
def can_handle_url(cls, url):
|
||||||
|
return _url_re.match(url) is not None
|
||||||
|
|
||||||
|
def _get_streams(self):
|
||||||
|
headers = {
|
||||||
|
'User-Agent': useragents.CHROME,
|
||||||
|
'Referer': self.url
|
||||||
|
}
|
||||||
|
|
||||||
|
hls = http.get(self.url, headers=headers, schema=_schema)
|
||||||
|
return HLSStream.parse_variant_playlist(self.session, hls, headers=headers)
|
||||||
|
|
||||||
|
|
||||||
|
__plugin__ = OK_live
|
15
tests/test_plugin_ok_live.py
Normal file
15
tests/test_plugin_ok_live.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import unittest
|
||||||
|
|
||||||
|
from streamlink.plugins.ok_live import OK_live
|
||||||
|
|
||||||
|
|
||||||
|
class TestPluginOK_live(unittest.TestCase):
|
||||||
|
def test_can_handle_url(self):
|
||||||
|
# should match
|
||||||
|
self.assertTrue(OK_live.can_handle_url("https://ok.ru/live/12345"))
|
||||||
|
self.assertTrue(OK_live.can_handle_url("http://ok.ru/live/12345"))
|
||||||
|
self.assertTrue(OK_live.can_handle_url("http://www.ok.ru/live/12345"))
|
||||||
|
|
||||||
|
# shouldn't match
|
||||||
|
self.assertFalse(OK_live.can_handle_url("http://www.tvcatchup.com/"))
|
||||||
|
self.assertFalse(OK_live.can_handle_url("http://www.youtube.com/"))
|
Loading…
Reference in New Issue
Block a user