1
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:
Anton Tykhyy 2018-01-25 11:48:44 +02:00
parent b839cfd76b
commit dc3230ca32
2 changed files with 56 additions and 0 deletions

View 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

View 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/"))