How to use the streamlink.plugin.api.validate.url function in streamlink

To help you get started, we’ve selected a few streamlink examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github streamlink / streamlink / src / streamlink / plugins / youtube.py View on Github external
_config_schema = validate.Schema(
    {
        validate.optional("fmt_list"): validate.all(
            validate.text,
            validate.transform(parse_fmt_list)
        ),
        validate.optional("url_encoded_fmt_stream_map"): validate.all(
            validate.text,
            validate.transform(parse_stream_map),
            [{
                "itag": validate.all(
                    validate.text,
                    validate.transform(int)
                ),
                "quality": validate.text,
                "url": validate.url(scheme="http"),
                validate.optional("s"): validate.text,
                validate.optional("stereo3d"): validate.all(
                    validate.text,
                    validate.transform(int),
                    validate.transform(bool)
                ),
            }]
        ),
        validate.optional("adaptive_fmts"): validate.all(
            validate.text,
            validate.transform(parse_stream_map),
            [{
                validate.optional("s"): validate.text,
                "type": validate.all(
                    validate.text,
                    validate.transform(lambda t: t.split(";")[0].split("/")),
github streamlink / streamlink / src / streamlink / plugins / gulli.py View on Github external
class Gulli(Plugin):
    LIVE_PLAYER_URL = 'http://replay.gulli.fr/jwplayer/embedstreamtv'
    VOD_PLAYER_URL = 'http://replay.gulli.fr/jwplayer/embed/{0}'

    _url_re = re.compile(r'http://replay\.gulli\.fr/(?:Direct|.+/(?PVOD[0-9]+))')
    _playlist_re = re.compile(r'sources: (\[.+?\])', re.DOTALL)
    _vod_video_index_re = re.compile(r'jwplayer\(idplayer\).playlistItem\((?P[0-9]+)\)')
    _mp4_bitrate_re = re.compile(r'.*_(?P[0-9]+)\.mp4')

    _video_schema = validate.Schema(
        validate.all(
            validate.transform(lambda x: re.sub(r'"?file"?:\s*[\'"](.+?)[\'"]', r'"file": "\1"', x, flags=re.DOTALL)),
            validate.transform(parse_json),
            [
                validate.Schema({
                    'file': validate.url()
                })
            ]
        )
    )

    @classmethod
    def can_handle_url(cls, url):
        return Gulli._url_re.match(url)

    def _get_streams(self):
        match = self._url_re.match(self.url)
        video_id = match.group('video_id')
        if video_id is not None:
            # VOD
            live = False
            player_url = self.VOD_PLAYER_URL.format(video_id)
github streamlink / streamlink / src / streamlink / plugins / cam4.py View on Github external
from streamlink.stream import HLSStream, RTMPStream
from streamlink.utils import parse_json


class Cam4(Plugin):
    _url_re = re.compile(r'https?://([a-z]+\.)?cam4.com/.+')
    _video_data_re = re.compile(r"flashData: (?P{.*}), hlsUrl: '(?P.+?)'")

    _flash_data_schema = validate.Schema(
        validate.all(
            validate.transform(parse_json),
            validate.Schema({
                'playerUrl': validate.url(),
                'flashVars': validate.Schema({
                    'videoPlayUrl': validate.text,
                    'videoAppUrl': validate.url(scheme='rtmp')
                })
            })
        )
    )

    @classmethod
    def can_handle_url(cls, url):
        return Cam4._url_re.match(url)

    def _get_streams(self):
        res = self.session.http.get(self.url, headers={'User-Agent': useragents.ANDROID})
        match = self._video_data_re.search(res.text)
        if match is None:
            return

        hls_streams = HLSStream.parse_variant_playlist(
github streamlink / streamlink / src / streamlink / plugins / bilibili.py View on Github external
""", re.VERBOSE)

_room_id_schema = validate.Schema(
    {
        "data": validate.any(None, {
            "room_id": int,
            "live_status": int
        })
    },
    validate.get("data")
)

_room_stream_list_schema = validate.Schema(
    {
        "data": validate.any(None, {
            "durl": [{"url": validate.url()}]
        })
    },
    validate.get("data")
)


class Bilibili(Plugin):
    @classmethod
    def can_handle_url(self, url):
        return _url_re.match(url)

    @classmethod
    def stream_weight(cls, stream):
        if stream in STREAM_WEIGHTS:
            return STREAM_WEIGHTS[stream], "Bilibili"
github streamlink / streamlink / src / streamlink / plugins / itvplayer.py View on Github external
swf_url = "https://mediaplayer.itv.com/2.19.5%2Bbuild.a23aa62b1e/ITVMediaPlayer.swf"
    _video_info_schema = validate.Schema({
        "StatusCode": 200,
        "AdditionalInfo": {
            "Message": validate.any(None, validate.text)
        },
        "Playlist": {
            "VideoType": validate.text,
            "Video": {
                "Subtitles": validate.any(None, [{
                    "Href": validate.url(),
                }]),
                "Base": validate.url(),
                "MediaFiles": [
                    {"Href": validate.text,
                     "KeyServiceUrl": validate.any(None, validate.url())}
                ]
            }
        }
    })

    @classmethod
    def can_handle_url(cls, url):
        return cls._url_re.match(url) is not None

    @property
    def device_info(self):
        return {"user": {},
                "device": {"manufacturer": "Chrome", "model": "66",
                           "os": {"name": "Windows", "version": "10", "type": "desktop"}},
                "client": {"version": "4.1", "id": "browser"},
                "variantAvailability": {"featureset": {"min": ["hls", "aes"],
github streamlink / streamlink / src / streamlink / plugins / furstream.py View on Github external
import re

from streamlink.plugin import Plugin
from streamlink.plugin.api import http, validate
from streamlink.stream import RTMPStream

_url_re = re.compile(r"^http(s)?://(\w+\.)?furstre\.am/stream/.+")
_stream_url_re = re.compile(r"
github streamlink / streamlink / src / streamlink / plugins / brightcove.py View on Github external
class BrightcovePlayer(object):
    player_page = "http://players.brightcove.net/{account_id}/{player_id}/index.html"
    api_url = "https://edge.api.brightcove.com/playback/v1/"
    amf_broker = "http://c.brightcove.com/services/messagebroker/amf"

    policy_key_re = re.compile(r'''policyKey\s*:\s*(?P<q>['"])(?P.*?)(?P=q)''')

    schema = validate.Schema({
        "sources": [{
            validate.optional("height"): validate.any(int, None),
            validate.optional("avg_bitrate"): validate.any(int, None),
            validate.optional("src"): validate.url(),
            validate.optional("app_name"): validate.any(
                validate.url(scheme="rtmp"),
                validate.url(scheme="rtmpe")
            ),
            validate.optional("stream_name"): validate.text,
            validate.optional("type"): validate.text
        }]
    })

    def __init__(self, session, account_id, player_id="default_default"):
        self.session = session
        self.logger = logging.getLogger("streamlink.plugins.brightcove")
        self.logger.debug("Creating player for account {0} (player_id={1})", account_id, player_id)
        self.account_id = account_id
        self.player_id = player_id

    def player_url(self, video_id):
        return self.player_page.format(account_id=self.account_id,
                                       player_id=self.player_id,</q>
github streamlink / streamlink / src / streamlink / plugins / seetv.py View on Github external
from streamlink.compat import urlparse, parse_qsl


class SeeTV(Plugin):
    _url_re = re.compile(r"""(http://seetv.tv/vse-tv-online/.*?)(#|$)""")
    _api_url = "http://seetv.tv/get/player/{0}"
    _main_source_re = re.compile(r'stream-active-main" rel="(\d+)"')
    api_schema = validate.Schema(validate.any(
        {
            "status": False,
            "text": validate.text
        },
        {
            "status": True,
            "file": validate.any(
                validate.all(validate.url(), validate.transform(lambda x: x.replace("%3F", "?"))),
                validate.all(validate.text, validate.startswith("&lt;"))
            ),
            "height": validate.text,
        }
    ))

    @classmethod
    def can_handle_url(cls, url):
        return cls._url_re.match(url) is not None

    @property
    def referer(self):
        return self._url_re.match(self.url).group(1)

    def _get_tv_link(self):
        res = self.session.http.get(self.url)
github streamlink / streamlink / src / streamlink / plugins / cubetv.py View on Github external
_channel_info_schema = validate.Schema({
        u"code" : 1,
        u"msg": u"success",
        u"data": {
            u"gid": validate.text,
            u"cube_id": validate.text
        }
    })

    _stream_data_schema = validate.Schema({
        u"code" : 1,
        u"msg": u"success",
        u"data": {
            u"video": u"hls",
            u"video_src": validate.url()
        }
    })

    @classmethod
    def can_handle_url(cls, url):
        return cls._url_re.match(url) is not None

    def _get_api_res(self, user_id):
        try:
            res = self.session.http.get(self._channel_info_api_url_base.format(channel=user_id))
            return res
        except Exception as e:
            raise NoStreamsError(self.url)

    def _get_streams(self):
        user_id = self._url_re.match(self.url).group(2)
github streamlink / streamlink / src / streamlink / plugins / liveme.py View on Github external
from streamlink.plugin import Plugin
from streamlink.plugin.api import validate
from streamlink.compat import urlparse, parse_qsl
from streamlink.stream import HLSStream
from streamlink.stream import HTTPStream


class LiveMe(Plugin):
    url_re = re.compile(r"https?://(www.)?liveme\.com/live\.html\?videoid=(\d+)")
    api_url = "https://live.ksmobile.net/live/queryinfo"
    api_schema = validate.Schema(validate.all({
        "status": "200",
        "data": {
            "video_info": {
                "videosource": validate.any('', validate.url()),
                "hlsvideosource": validate.any('', validate.url()),
            }
        }
    }, validate.get("data")))

    @classmethod
    def can_handle_url(cls, url):
        return cls.url_re.match(url) is not None

    def _random_t(self, t):
        return "".join(random.choice("ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678") for _ in range(t))

    def _make_stream(self, url):
        if url and url.endswith("flv"):
            return HTTPStream(self.session, url)
        elif url and url.endswith("m3u8"):