def test_dict_keys(self):
     assert validate({text: int}, {"a": 1, "b": 2}) == {"a": 1, "b": 2}
     assert validate({transform(text): transform(int)}, {
                          1: 3.14,
                          3.14: 1
                      }) == {
                          "1": 3,
                          "3.14": 1
                      }
    def test_basic(self):
        assert validate(1, 1) == 1

        assert validate(int, 1) == 1

        assert validate(transform(int), "1") == 1

        assert validate(text, "abc") == "abc"
        assert validate(text, u"日本語") == u"日本語"
        assert validate(transform(text), 1) == "1"

        assert validate(list, ["a", 1]) == ["a", 1]
        assert validate(dict, {"a": 1}) == {"a": 1}

        assert validate(lambda n: 0 < n < 5, 3) == 3
    def test_basic(self):
        assert validate(1, 1) == 1

        assert validate(int, 1) == 1

        assert validate(transform(int), "1") == 1

        assert validate(text, "abc") == "abc"
        assert validate(text, u"日本語") == u"日本語"
        assert validate(transform(text), 1) == "1"

        assert validate(list, ["a", 1]) == ["a", 1]
        assert validate(dict, {"a": 1}) == {"a": 1}

        assert validate(lambda n: 0 < n < 5, 3) == 3
Example #4
0
_url_re = re.compile("""
    http(s)?://(\w+\.)?aliez.tv
    (?:
        /live/[^/]+
    )?
    (?:
        /video/\d+/[^/]+
    )?
""", re.VERBOSE)
_file_re = re.compile("\"?file\"?:\s+['\"]([^'\"]+)['\"]")
_swf_url_re = re.compile("swfobject.embedSWF\(\"([^\"]+)\",")

_schema = validate.Schema(
    validate.union({
        "urls": validate.all(
            validate.transform(_file_re.findall),
            validate.map(unquote),
            [validate.url()]
        ),
        "swf": validate.all(
            validate.transform(_swf_url_re.search),
            validate.any(
                None,
                validate.all(
                    validate.get(1),
                    validate.url(
                        scheme="http",
                        path=validate.endswith("swf")
                    )
                )
            )
Example #5
0
from functools import partial

from livestreamer.plugin import Plugin
from livestreamer.plugin.api import http, validate
from livestreamer.plugin.api.utils import parse_json
from livestreamer.stream import HTTPStream, RTMPStream

BASE_VOD_URL = "https://www.connectcast.tv"
SWF_URL = "https://www.connectcast.tv/jwplayer/jwplayer.flash.swf"

_url_re = re.compile("http(s)?://(\w+\.)?connectcast.tv/")
_playlist_re = re.compile("playlist: (\[.+\]),", re.DOTALL)
_js_to_json = partial(re.compile("(\w+):\s").sub, r'"\1":')

_playlist_schema = validate.Schema(
    validate.transform(_playlist_re.search),
    validate.any(
        None,
        validate.all(
            validate.get(1),
            validate.transform(_js_to_json),
            validate.transform(parse_json),
            [{
                "sources": [{
                    "file": validate.text,
                    validate.optional("label"): validate.text
                }]
            }]
        )
    )
)
from livestreamer.plugin.api import http, validate
from livestreamer.stream import RTMPStream

RTMP_URL = "rtmp://{0}/app/{1}"
CHANNEL_DETAILS_URI = "https://api.streamup.com/1.0/channels/{0}?access_token={1}"
REDIRECT_SERVICE_URI = "https://lancer.streamup.com/api/redirect/{0}"

_url_re = re.compile("http(s)?://(\w+\.)?streamup.com/(?P<channel>[^/?]+)")
_flashvars_re = re.compile("flashvars\.(?P<var>\w+)\s?=\s?'(?P<value>[^']+)';")
_swf_url_re = re.compile('swfobject.embedSWF\(\s*"(?P<player_url>[^"]+)",')

_schema = validate.Schema(
    validate.union(
        {
            "vars": validate.all(
                validate.transform(_flashvars_re.findall),
                validate.transform(dict),
                {"owner": validate.text, validate.optional("token"): validate.text},
            ),
            "swf": validate.all(
                validate.transform(_swf_url_re.search), validate.get("player_url"), validate.endswith(".swf")
            ),
        }
    )
)

_channel_details_schema = validate.Schema({"channel": {"live": bool, "slug": validate.text}})


class StreamupCom(Plugin):
    @classmethod
Example #7
0
_quality_re = re.compile("(\d+p)$")
_url_re = re.compile(
    """
    http(s)?://(www\.)?hitbox.tv
    /(?P<channel>[^/]+)
    (?:
        /(?P<media_id>[^/]+)
    )?
""", re.VERBOSE)

_live_schema = validate.Schema(
    {
        "livestream": [{
            "media_is_live":
            validate.all(validate.text, validate.transform(int),
                         validate.transform(bool)),
            "media_id":
            validate.text
        }],
    }, validate.get("livestream"), validate.length(1), validate.get(0))
_player_schema = validate.Schema({
    "clip": {
        "baseUrl":
        validate.any(None, validate.text),
        "bitrates":
        validate.all(
            validate.filter(lambda b: b.get("url") and b.get("label")),
            [{
                "label": validate.text,
                "url": validate.text,
Example #8
0
import re

from livestreamer.plugin import Plugin
from livestreamer.plugin.api import http, validate
from livestreamer.plugin.api.utils import parse_query
from livestreamer.stream import RTMPStream


VIEW_LIVE_API_URL = "http://api.afreeca.tv/live/view_live.php"

_url_re = re.compile("http(s)?://(\w+\.)?afreeca.tv/(?P<channel>[\w\-_]+)")
_flashvars_re = re.compile('<param name="flashvars" value="([^"]+)" />')

_flashvars_schema = validate.Schema(
    validate.transform(_flashvars_re.findall),
    validate.get(0),
    validate.transform(parse_query),
    validate.any(
        {
            "s": validate.text,
            "id": validate.text
        },
        {}
    )
)
_view_live_schema = validate.Schema(
    {
        "channel": {
            "strm": [{
                "brt": validate.text,
                "bps": validate.text,
Example #9
0
from livestreamer.compat import urlparse
from livestreamer.plugin import Plugin
from livestreamer.plugin.api import http, validate
from livestreamer.stream import HLSStream

_url_re = re.compile("http(s)?://(\w+\.)?ssh101\.com/")

_live_re = re.compile("""
\s*jwplayer\(\"player\"\)\.setup\({.*?
\s*primary:\s+"([^"]+)".*?
\s*file:\s+"([^"]+)"
""", re.DOTALL)

_live_schema = validate.Schema(
    validate.transform(_live_re.search),
    validate.any(
        None,
        validate.union({
            "type": validate.get(1),
            "url": validate.all(
                validate.get(2),
                validate.url(scheme="http"),
            ),
        })
    )
)

class SSH101(Plugin):
    @classmethod
    def can_handle_url(self, url):
Example #10
0
from livestreamer.plugin import Plugin
from livestreamer.plugin.api import http, validate
from livestreamer.stream import RTMPStream, HLSStream

CHANNEL_INFO_URL = "http://live.afreecatv.com:8057/afreeca/player_live_api.php"
ASSIGN_PATH = "/broad_stream_assign.html"
CHANNEL_RESULT_ERROR = 0
CHANNEL_RESULT_OK = 1
# original, hd, sd
quality = "original"
_url_re = re.compile(r"http(s)?://afreeca.com/(?P<bid>\w+)(/\d+)?")

_channel_schema = validate.Schema(
    {
        "CHANNEL": {
            "RESULT": validate.transform(int),
            "BNO": validate.text,
            "CDN": validate.text,
            "RMD": validate.text,
        }
    }, validate.get("CHANNEL"))
_channel_aid_schema = validate.Schema(
    {"CHANNEL": {
        "RESULT": validate.transform(int),
        "AID": validate.text,
    }}, validate.get("CHANNEL"))
_stream_schema = validate.Schema({
    validate.optional("view_url"):
    validate.url(scheme=validate.any("rtmp", "http"))
})
Example #11
0
import re

from itertools import chain

from livestreamer.compat import urlparse
from livestreamer.plugin import Plugin
from livestreamer.plugin.api import http, validate
from livestreamer.stream import HLSStream, HTTPStream, RTMPStream

SWF_URL = "http://www.arte.tv/player/v2/jwplayer6/mediaplayer.6.6.swf"

_url_re = re.compile("http(s)?://(\w+\.)?arte.tv/")
_json_re = re.compile("arte_vp_(?:live-)?url=(['\"])(.+?)\\1")

_schema = validate.Schema(
    validate.transform(_json_re.search),
    validate.any(
        None,
        validate.all(
            validate.get(2),
            validate.url(scheme="http")
        )
    )
)
_video_schema = validate.Schema({
    "videoJsonPlayer": {
        "VSR": validate.any(
            [],
            {
                validate.text: {
                    "height": int,
Example #12
0
SHOW_STATUS_OFFLINE = 2
STREAM_WEIGHTS = {"middle": 540, "source": 1080}

_url_re = re.compile(
    """
    http(s)?://(www\.)?douyutv.com
    /(?P<channel>[^/]+)
""", re.VERBOSE)

_room_schema = validate.Schema(
    {
        "data":
        validate.any(
            None, {
                "show_status":
                validate.all(validate.text, validate.transform(int)),
                "rtmp_url":
                validate.text,
                "rtmp_live":
                validate.text,
                "rtmp_multi_bitrate":
                validate.all(validate.any([], {validate.text: validate.text}),
                             validate.transform(dict))
            })
    }, validate.get("data"))


class Douyutv(Plugin):
    @classmethod
    def can_handle_url(self, url):
        return _url_re.match(url)
Example #13
0
)
RECORDED_URL = "http://tcdn.ustream.tv/video/{0}"
RTMP_URL = "rtmp://r{0}-1-{1}-channel-live.ums.ustream.tv:1935/ustream"
SWF_URL = "http://static-cdn1.ustream.tv/swf/live/viewer.rsl:505.swf"

_module_info_schema = validate.Schema(
    list,
    validate.length(1),
    validate.get(0),
    dict
)
_amf3_array = validate.Schema(
    validate.any(
        validate.all(
            {int: object},
            validate.transform(lambda a: list(a.values())),
        ),
        list
    )
)
_recorded_schema = validate.Schema({
    validate.optional("stream"): validate.all(
        _amf3_array,
        [{
            "name": validate.text,
            "streams": validate.all(
                _amf3_array,
                [{
                    "streamName": validate.text,
                    "bitrate": float,
                }],
Example #14
0
""", re.VERBOSE)
_channel_not_found_re = re.compile("<title>Channel Not Found")


def decode_token(token):
    def decode_part(part):
        part = int(part.replace("0m0", ""))
        part /= DEBUG_PORT_ID
        part /= SET_GEO_CODE
        return chr(int(part))

    return "".join(decode_part(part) for part in token.split(":"))


_schema = validate.Schema(
    validate.transform(lambda s: s.split(";")),
    validate.length(3),
    validate.union({
        "server": validate.all(
            validate.get(0),
            validate.text
        ),
        "token": validate.all(
            validate.get(2),
            validate.text,
            validate.transform(decode_token)
        )
    })
)

Example #15
0
import re

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

_url_re = re.compile("^http(s)?://(\w+\.)?furstre\.am/stream/.+")
_stream_url_re = re.compile("<source src=\"([^\"]+)\"")
_schema = validate.Schema(
    validate.transform(_stream_url_re.search),
    validate.any(None,
                 validate.all(validate.get(1), validate.url(scheme="rtmp"))))


class Furstream(Plugin):
    @classmethod
    def can_handle_url(cls, url):
        return _url_re.match(url)

    def _get_streams(self):
        stream_url = http.get(self.url, schema=_schema)
        if not stream_url:
            return

        stream = RTMPStream(self.session, {
            "rtmp": stream_url,
            "pageUrl": self.url,
            "live": True
        })

        return dict(live=stream)
Example #16
0
from livestreamer.plugin.api.support_plugin import justintv_common

JustinTVPluginBase = justintv_common.PluginBase
JustinTVAPIBase = justintv_common.APIBase

_url_re = re.compile(r"http(s)?://([\w\.]+)?justin.tv/[^/]+(/[bc]/\d+)?")

_video_schema = validate.Schema(
    validate.union({
        "archives":
        validate.all(validate.xml_findall("archive"), [
            validate.union({
                "length":
                validate.all(
                    validate.xml_findtext("length"),
                    validate.transform(int),
                ),
                "transcodes":
                validate.all(
                    validate.xml_find("transcode_file_urls"),
                    validate.xml_findall("*"),
                    validate.map(lambda e:
                                 (e.tag.replace("transcode_", ""), e.text)),
                    validate.transform(dict),
                ),
                "url":
                validate.xml_findtext("video_file_url")
            }),
        ]),
        validate.optional("restrictions"):
        validate.xml_findtext("archive_restrictions/restriction"),
Example #17
0
def parse_fmt_list(formatsmap):
    formats = {}
    if not formatsmap:
        return formats

    for format in formatsmap.split(","):
        s = format.split("/")
        (w, h) = s[1].split("x")
        formats[int(s[0])] = "{0}p".format(h)

    return formats


_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.text,
        validate.optional("s"):
        validate.text,
        validate.optional("stereo3d"):
        validate.all(validate.text, validate.transform(int),
                     validate.transform(bool)),
    }]),
    validate.optional("hlsvp"):
Example #18
0
_live_schema = validate.Schema({
    validate.any("primary", "secondary"): {
        validate.text: {
            "rtmp_flash": {
                validate.text: {
                    "name": validate.text,
                    "server": validate.url(scheme="rtmp")
                }
            }
        }
    }
})
_schema = validate.Schema(
    validate.union({
        "lang": validate.all(
            validate.transform(_lang_re.search),
            validate.get(1)
        ),
        "live": validate.all(
            validate.transform(_live_check_re.search),
            validate.transform(bool)
        ),
        "videos": validate.all(
            validate.transform(_video_re.findall),
            [(validate.url(scheme="http"), validate.text)]
        )
    })
)


class Euronews(Plugin):
Example #19
0
    "73": "token"
}
BLOCKED_MSG_FORMAT = (
    "You have crossed the free viewing limit. You have been blocked for "
    "{0} minutes. Try again in {1} minutes"
)
BLOCK_TYPE_VIEWING_LIMIT = 1
BLOCK_TYPE_NO_SLOTS = 11

_url_re = re.compile("http(s)?://(\w+\.)?weeb.tv/channel/(?P<channel>[^/&?]+)")
_schema = validate.Schema(
    dict,
    validate.map(lambda k, v: (PARAMS_KEY_MAP.get(k, k), v)),
    validate.any(
        {
            "status": validate.transform(int),
            "rtmp": validate.url(scheme="rtmp"),
            "playpath": validate.text,
            "multibitrate": validate.all(
                validate.transform(int),
                validate.transform(bool)
            ),
            "block_type": validate.transform(int),
            validate.optional("token"): validate.text,
            validate.optional("block_time"): validate.text,
            validate.optional("reconnect_time"): validate.text,
        },
        {
            "status": validate.transform(int),
        },
    )
Example #20
0
def parse_fmt_list(formatsmap):
    formats = {}
    if not formatsmap:
        return formats

    for format in formatsmap.split(","):
        s = format.split("/")
        (w, h) = s[1].split("x")
        formats[int(s[0])] = "{0}p".format(h)

    return formats


_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"):
Example #21
0
from livestreamer.compat import urlparse
from livestreamer.plugin import Plugin
from livestreamer.plugin.api import http, validate
from livestreamer.stream import HLSStream

_url_re = re.compile("http(s)?://(\w+\.)?ssh101\.com/")

_live_re = re.compile(
    """
\s*jwplayer\(\"player\"\)\.setup\({.*?
\s*primary:\s+"([^"]+)".*?
\s*file:\s+"([^"]+)"
""", re.DOTALL)

_live_schema = validate.Schema(
    validate.transform(_live_re.search),
    validate.any(
        None,
        validate.union({
            "type":
            validate.get(1),
            "url":
            validate.all(
                validate.get(2),
                validate.url(scheme="http"),
            ),
        })))


class SSH101(Plugin):
    @classmethod
Example #22
0
_live_schema = validate.Schema({
    validate.any("primary", "secondary"): {
        validate.text: {
            "rtmp_flash": {
                validate.text: {
                    "name": validate.text,
                    "server": validate.url(scheme="rtmp")
                }
            }
        }
    }
})
_schema = validate.Schema(
    validate.union({
        "lang":
        validate.all(validate.transform(_lang_re.search), validate.get(1)),
        "live":
        validate.all(validate.transform(_live_check_re.search),
                     validate.transform(bool)),
        "videos":
        validate.all(validate.transform(_video_re.findall),
                     [(validate.url(scheme="http"), validate.text)])
    }))


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

    def _get_live_streams(self, lang):
Example #23
0
STREAM_WEIGHTS = {
    "middle": 540,
    "source": 1080
}

_url_re = re.compile("""
    http(s)?://(www\.)?douyutv.com
    /(?P<channel>[^/]+)
""", re.VERBOSE)

_room_schema = validate.Schema(
    {
        "data": validate.any(None, {
            "show_status": validate.all(
                validate.text,
                validate.transform(int)
            ),
            "rtmp_url": validate.text,
            "rtmp_live": validate.text,
            "rtmp_multi_bitrate": validate.all(
                validate.any([], {
                    validate.text: validate.text
                }),
                validate.transform(dict)
            )
        })
    },
    validate.get("data")
)

Example #24
0
            validate.xml_find("./head/meta"),
            validate.get("base"),
            validate.url(scheme="rtmp")
        ),
        "videos": validate.all(
            validate.xml_findall(".//video"),
            [
                validate.union({
                    "src": validate.all(
                        validate.get("src"),
                        validate.text
                    ),
                    "height": validate.all(
                        validate.get("height"),
                        validate.text,
                        validate.transform(int)
                    )
                })
            ]
        )
    })
)

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

    def _get_streams(self):
        match = _url_re.match(self.url)
        channel = match.group("channel")
Example #25
0
                            scheme="http",
                            path=validate.endswith(".m3u8")
                        )
                    }],
                    validate.filter(lambda s: s["quality"] != "adaptive")
                )
            }
        )
    },
    validate.get("stream_data")
)
_login_schema = validate.Schema({
    "auth": validate.text,
    "expires": validate.all(
        validate.text,
        validate.transform(parse_timestamp)
    ),
    "user": {
        "username": validate.text
    }
})
_session_schema = validate.Schema(
    {
        "session_id": validate.text
    },
    validate.get("session_id")
)


class CrunchyrollAPIError(Exception):
    """Exception thrown by the Crunchyroll API when an error occurs"""
Example #26
0
        validate.xml_element(attrib={
            "content": validate.text
        }),
        validate.get("content")
    ),
    "videos": validate.all(
        validate.xml_findall("{http://www.w3.org/2001/SMIL20/Language}body/"
                             "{http://www.w3.org/2001/SMIL20/Language}switch/"
                             "{http://www.w3.org/2001/SMIL20/Language}video"),
        [
            validate.all(
                validate.xml_element(attrib={
                    "src": validate.text,
                    "system-bitrate": validate.all(
                        validate.text,
                        validate.transform(int)
                    )
                }),
                validate.transform(
                    lambda e: (e.attrib["src"], e.attrib["system-bitrate"])
                )
            )
        ],
    )
}))


class Livestream(Plugin):
    @classmethod
    def default_stream_types(cls, streams):
        return ["akamaihd", "hls"]
Example #27
0
LAPI_SECRET = "A12Svb&%1UUmf@hC"
SHOW_STATUS_ONLINE = 1
SHOW_STATUS_OFFLINE = 2
STREAM_WEIGHTS = {"low": 540, "middle": 720, "source": 1080}

_url_re = re.compile(
    """
    http(s)?://(www\.)?douyu.com
    /(?P<channel>[^/]+)
""", re.VERBOSE)

_json_re = re.compile(r"var\s*\$ROOM\s*=\s*({.+?});")

_room_id_schema = validate.Schema(
    validate.all(
        validate.transform(_json_re.search),
        validate.any(
            None,
            validate.all(validate.get(1), validate.transform(parse_json), {
                "room_id":
                validate.any(validate.text, validate.transform(int))
            }))))

_room_schema = validate.Schema(
    {
        "data":
        validate.any(None, {
            "show_status":
            validate.all(validate.text, validate.transform(int))
        })
    }, validate.get("data"))
Example #28
0
_url_re = re.compile("http(s)?://(\w+\.)?ilive.to/")
_rtmp_re = re.compile("""
    \$.getJSON\("(?P<token_url>[^"]+)".*
    flashplayer:\s+"(?P<swf_url>[^"]+)".*
    streamer:\s+"(?P<rtmp_url>[^"]+)".*
    file:\s+"(?P<rtmp_playpath>[^"]+)\.flv"
""", re.VERBOSE | re.DOTALL)

_token_schema = validate.Schema(
    {
        "token": validate.text
    },
    validate.get("token")
)
_schema = validate.Schema(
    validate.transform(_rtmp_re.search),
    validate.any(
        None,
        validate.all(
            validate.transform(methodcaller("groupdict")),
            {
                "rtmp_playpath": validate.text,
                "rtmp_url": validate.all(
                    validate.transform(methodcaller("replace", "\\/", "/")),
                    validate.url(scheme="rtmp"),
                ),
                "swf_url": validate.url(scheme="http"),
                "token_url": validate.url(scheme="http")
            }
        )
    )
    def test_all(self):
        assert validate(all(int, lambda n: 0 < n < 5), 3) == 3

        assert validate(all(transform(int), lambda n: 0 < n < 5), 3.33) == 3
Example #30
0
    """
    http(s)?://(\w+\.)?aliez.tv
    (?:
        /live/[^/]+
    )?
    (?:
        /video/\d+/[^/]+
    )?
""", re.VERBOSE)
_file_re = re.compile("\"?file\"?:\s+['\"]([^'\"]+)['\"]")
_swf_url_re = re.compile("swfobject.embedSWF\(\"([^\"]+)\",")

_schema = validate.Schema(
    validate.union({
        "urls":
        validate.all(validate.transform(_file_re.findall),
                     validate.map(unquote), [validate.url()]),
        "swf":
        validate.all(
            validate.transform(_swf_url_re.search),
            validate.any(
                None,
                validate.all(
                    validate.get(1),
                    validate.url(scheme="http",
                                 path=validate.endswith("swf")))))
    }))


class Aliez(Plugin):
    @classmethod
Example #31
0
STREAM_INFO_URL = "http://live.daserste.de/{0}/livestream.xml"
SWF_URL = "http://live.daserste.de/lib/br-player/swf/main.swf"
STREAMING_TYPES = {
    "streamingUrlLive": ("HDS", partial(HDSStream.parse_manifest,
                                        pvswf=SWF_URL)),
    "streamingUrlIPhone": ("HLS", HLSStream.parse_variant_playlist)
}

_url_re = re.compile("http(s)?://live.daserste.de/(?P<channel>[^/?]+)?")

_livestream_schema = validate.Schema(
    validate.xml_findall("video/*"),
    validate.filter(lambda e: e.tag in STREAMING_TYPES),
    validate.map(lambda e: (STREAMING_TYPES.get(e.tag), e.text)),
    validate.transform(dict),
)


class ard_live(Plugin):
    @classmethod
    def can_handle_url(cls, url):
        return _url_re.match(url)

    def _get_streams(self):
        match = _url_re.match(self.url)
        channel = match.group("channel")
        res = http.get(STREAM_INFO_URL.format(channel))
        urls = http.xml(res, schema=_livestream_schema)

        streams = {}
Example #32
0
""", re.VERBOSE)
_channel_id_re = re.compile("\"channelId\":(\d+)")

HLS_PLAYLIST_URL = ("http://iphone-streaming.ustream.tv"
                    "/uhls/{0}/streams/live/iphone/playlist.m3u8")
RECORDED_URL = "http://tcdn.ustream.tv/video/{0}"
RTMP_URL = "rtmp://r{0}-1-{1}-channel-live.ums.ustream.tv:1935/ustream"
SWF_URL = "http://static-cdn1.ustream.tv/swf/live/viewer.rsl:505.swf"

_module_info_schema = validate.Schema(list, validate.length(1),
                                      validate.get(0), dict)
_amf3_array = validate.Schema(
    validate.any(
        validate.all(
            {int: object},
            validate.transform(lambda a: list(a.values())),
        ), list))
_recorded_schema = validate.Schema({
    validate.optional("stream"):
    validate.all(_amf3_array, [{
        "name":
        validate.text,
        "streams":
        validate.all(
            _amf3_array,
            [{
                "streamName": validate.text,
                "bitrate": float,
            }],
        ),
        validate.optional("url"):
Example #33
0
from livestreamer.plugin import Plugin
from livestreamer.plugin.api import http, validate
from livestreamer.stream import RTMPStream

API_URL = "http://www.kanal{0}play.se/api/getVideo?videoId={1}&format=FLASH"

_url_re = re.compile ("""
    (http(s)?://)?www.kanal(?P<channel>5|9|11)play.se/(play/)?
    program/\d+/video/(?P<video_id>\d+)
    """, re.VERBOSE)

_schema = validate.Schema (
    {
        "streams": validate.all (
            [{
                "bitrate": validate.transform (int),
                "source": validate.text
            }]),
        "streamBaseUrl": validate.text
    }
)

class Kanal5_9_11 (Plugin):
    @classmethod
    def can_handle_url (cls, url):
        return _url_re.match (url)

    def _get_streams (self):
        match = _url_re.match (self.url)
        channel = match.group ("channel")
        video_id = match.group ("video_id")
Example #34
0
import re

from functools import partial

from livestreamer.plugin.api import validate
from livestreamer.plugin.api.utils import parse_json

__all__ = ["parse_playlist"]

_playlist_re = re.compile("\(?\{.*playlist: (\[.*\]),.*?\}\)?;", re.DOTALL)
_js_to_json = partial(re.compile("(\w+):\s").sub, r'"\1":')

_playlist_schema = validate.Schema(
    validate.transform(_playlist_re.search),
    validate.any(
        None,
        validate.all(
            validate.get(1),
            validate.transform(_js_to_json),
            validate.transform(parse_json),
            [{
                "sources": [{
                    "file": validate.text,
                    validate.optional("label"): validate.text
                }]
            }]
        )
    )
)

Example #35
0
_rtmp_re = re.compile("/(?P<app>[^/]+)/(?P<playpath>.+)")


def _parse_server_ip(values):
    octets = [
        values["a"] / values["f"],
        values["b"] / values["f"],
        values["c"] / values["f"],
        values["d"] / values["f"],
    ]

    return ".".join(str(int(octet)) for octet in octets)


_schema = validate.Schema(
    validate.transform(_js_var_re.findall),
    validate.transform(dict),
    {
        "a": validate.transform(int),
        "b": validate.transform(int),
        "c": validate.transform(int),
        "d": validate.transform(int),
        "f": validate.transform(int),
        "v_part": validate.text,
    },
    validate.union({
        "server_ip": validate.transform(_parse_server_ip),
        "path": validate.all(
            validate.get("v_part"),
            validate.transform(_rtmp_re.findall),
            validate.get(0)
Example #36
0
import re

from livestreamer.compat import urlparse
from livestreamer.plugin import Plugin
from livestreamer.plugin.api import StreamMapper, http, validate
from livestreamer.stream import HLSStream, RTMPStream

CHANNEL_URL = "http://www.mobileonline.tv/channel.php"

_url_re = re.compile("http(s)?://(\w+\.)?(ilive.to|streamlive.to)/view/(?P<channel>\d+)")
_link_re = re.compile("<p style=\"font-size:30px;\"><a href=(\S+) target=")
_schema = validate.Schema(
    validate.transform(_link_re.findall),
)


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

    def _create_hls_streams(self, url):
        try:
            streams = HLSStream.parse_variant_playlist(self.session, url)
            return streams.items()
        except IOError as err:
            self.logger.warning("Failed to extract HLS streams: {0}", err)

    def _create_rtmp_stream(self, url):
        parsed = urlparse(url)
        if parsed.query:
Example #37
0
from livestreamer.plugin import Plugin
from livestreamer.plugin.api import http, validate
from livestreamer.plugin.api.utils import parse_query
from livestreamer.stream import RTMPStream

BALANCER_URL = "http://www.mips.tv:1935/loadbalancer"
PLAYER_URL = "http://mips.tv/embedplayer/{0}/1/500/400"
SWF_URL = "http://mips.tv/content/scripts/eplayer.swf"

_url_re = re.compile("http(s)?://(\w+.)?mips.tv/(?P<channel>[^/&?]+)")
_flashvars_re = re.compile("'FlashVars', '([^']+)'")
_rtmp_re = re.compile("redirect=(.+)")

_schema = validate.Schema(
    validate.transform(_flashvars_re.search),
    validate.any(
        None,
        validate.all(
            validate.get(1),
            validate.transform(parse_query),
            {
                "id": validate.transform(int),
                validate.optional("s"): validate.text
            }
        )
    )
)
_rtmp_schema = validate.Schema(
    validate.transform(_rtmp_re.search),
    validate.get(1),
Example #38
0
                            scheme="http",
                            path=validate.endswith(".m3u8")
                        )
                    }],
                    validate.filter(lambda s: s["quality"] != "adaptive")
                )
            }
        )
    },
    validate.get("stream_data")
)
_login_schema = validate.Schema({
    "auth": validate.text,
    "expires": validate.all(
        validate.text,
        validate.transform(parse_timestamp)
    ),
    "user": {
        "username": validate.text
    }
})
_session_schema = validate.Schema(
    {
        "session_id": validate.text
    },
    validate.get("session_id")
)


class CrunchyrollAPIError(Exception):
    """Exception thrown by the Crunchyroll API when an error occurs"""
Example #39
0
from livestreamer.plugin import Plugin
from livestreamer.plugin.api import http, validate
from livestreamer.stream import RTMPStream

RTMP_URL = "rtmp://{0}/app/{1}"
CHANNEL_DETAILS_URI = "https://api.streamup.com/1.0/channels/{0}?access_token={1}"
REDIRECT_SERVICE_URI = "https://lancer.streamup.com/api/redirect/{0}"

_url_re = re.compile("http(s)?://(\w+\.)?streamup.com/(?P<channel>[^/?]+)")
_flashvars_re = re.compile("flashvars\.(?P<var>\w+)\s?=\s?'(?P<value>[^']+)';")
_swf_url_re = re.compile("swfobject.embedSWF\(\s*\"(?P<player_url>[^\"]+)\",")

_schema = validate.Schema(
    validate.union({
        "vars":
        validate.all(validate.transform(_flashvars_re.findall),
                     validate.transform(dict), {
                         "owner": validate.text,
                         validate.optional("token"): validate.text
                     }),
        "swf":
        validate.all(validate.transform(_swf_url_re.search),
                     validate.get("player_url"), validate.endswith(".swf"))
    }))

_channel_details_schema = validate.Schema(
    {"channel": {
        "live": bool,
        "slug": validate.text
    }})
Example #40
0
    if not formatsmap:
        return formats

    for format in formatsmap.split(","):
        s = format.split("/")
        (w, h) = s[1].split("x")
        formats[int(s[0])] = "{0}p".format(h)

    return formats


_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.text,
                validate.optional("s"): validate.text,
                validate.optional("stereo3d"): validate.all(
                    validate.text,
                    validate.transform(int),
Example #41
0
from livestreamer.plugin import Plugin
from livestreamer.plugin.api import http, validate
from livestreamer.plugin.api.utils import parse_query
from livestreamer.stream import RTMPStream

BALANCER_URL = "http://www.mips.tv:1935/loadbalancer"
PLAYER_URL = "http://mips.tv/embedplayer/{0}/1/500/400"
SWF_URL = "http://mips.tv/content/scripts/eplayer.swf"

_url_re = re.compile("http(s)?://(\w+.)?mips.tv/(?P<channel>[^/&?]+)")
_flashvars_re = re.compile("'FlashVars', '([^']+)'")
_rtmp_re = re.compile("redirect=(.+)")

_schema = validate.Schema(
    validate.transform(_flashvars_re.search),
    validate.any(
        None,
        validate.all(validate.get(1), validate.transform(parse_query), {
            "id": validate.transform(int),
            validate.optional("s"): validate.text
        })))
_rtmp_schema = validate.Schema(
    validate.transform(_rtmp_re.search),
    validate.get(1),
)


class Mips(Plugin):
    @classmethod
    def can_handle_url(self, url):
Example #42
0
_channel_schema = validate.Schema(
    {
        validate.optional("state"): {
            "stream": {
                "qualities": [validate.text],
                "rootUrl": validate.url(scheme="rtmp")
            }
        }
    }, validate.get("state"))

_vod_schema = validate.Schema(
    {
        "name": validate.text,
        "channel_slug": validate.text,
        "title": validate.text,
        "created_at": validate.transform(int)
    }, )


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

    @classmethod
    def stream_weight(cls, key):
        weight = QUALITY_WEIGHTS.get(key)
        if weight:
            return weight, "gaminglive"

        return Plugin.stream_weight(key)
Example #43
0
)
_video_flashvars_re = re.compile(
    "<embed width=\"486\" height=\"326\" flashvars=\"([^\"]+)\""
)

_live_schema = validate.Schema({
    "streams": [{
        "name": validate.text,
        "quality": validate.text,
        "url": validate.url(scheme="rtmp")
    }]
})
_schema = validate.Schema(
    validate.union({
        "export_url": validate.all(
            validate.transform(_live_export_re.search),
            validate.any(
                None,
                validate.get(1),
            )
        ),
        "video_flashvars": validate.all(
            validate.transform(_video_flashvars_re.search),
            validate.any(
                None,
                validate.all(
                    validate.get(1),
                    validate.transform(parse_query),
                    {
                        "_111pix_serverURL": validate.url(scheme="rtmp"),
                        "en_flash_providerName": validate.text
Example #44
0
_quality_re = re.compile("(\d+p)$")
_url_re = re.compile("""
    http(s)?://(www\.)?hitbox.tv
    /(?P<channel>[^/]+)
    (?:
        /(?P<media_id>[^/]+)
    )?
""", re.VERBOSE)

_live_schema = validate.Schema(
    {
        "livestream": [{
            "media_is_live": validate.all(
                validate.text,
                validate.transform(int),
                validate.transform(bool)
            ),
            "media_id": validate.text
        }],
    },
    validate.get("livestream"),
    validate.length(1),
    validate.get(0)
)
_player_schema = validate.Schema(
    {
        "clip": {
            "baseUrl": validate.any(None, validate.text),
            "bitrates": validate.all(
                validate.filter(lambda b: b.get("url") and b.get("label")),
    def test_all(self):
        assert validate(all(int, lambda n: 0 < n < 5), 3) == 3

        assert validate(all(transform(int), lambda n: 0 < n < 5), 3.33) == 3
from livestreamer.stream import RTMPStream, HLSStream

SWF_URL = "http://play.streamingvideoprovider.com/player2.swf"
API_URL = "http://player.webvideocore.net/index.php"

_url_re = re.compile(
    "http(s)?://(\w+\.)?streamingvideoprovider.co.uk/(?P<channel>[^/&?]+)"
)
_hls_re = re.compile("'(http://.+\.m3u8)'")

_rtmp_schema = validate.Schema(
    validate.xml_findtext("./info/url"),
    validate.url(scheme="rtmp")
)
_hls_schema = validate.Schema(
    validate.transform(_hls_re.search),
    validate.any(
        None,
        validate.all(
            validate.get(1),
            validate.url(
                scheme="http",
                path=validate.endswith("m3u8")
            )
        )
    )
)


class Streamingvideoprovider(Plugin):
    @classmethod
 def test_dict_keys(self):
     assert validate({text: int},
                     {"a": 1, "b": 2}) == {"a": 1, "b": 2}
     assert validate({transform(text): transform(int)},
                     {1: 3.14, 3.14: 1}) == {"1": 3, "3.14": 1}
Example #48
0
    if not formatsmap:
        return formats

    for format in formatsmap.split(","):
        s = format.split("/")
        (w, h) = s[1].split("x")
        formats[int(s[0])] = "{0}p".format(h)

    return formats


_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),
Example #49
0
import re

from itertools import chain

from livestreamer.compat import urlparse
from livestreamer.plugin import Plugin
from livestreamer.plugin.api import http, validate
from livestreamer.stream import HLSStream, HTTPStream, RTMPStream

SWF_URL = "http://www.arte.tv/player/v2/jwplayer6/mediaplayer.6.6.swf"

_url_re = re.compile("http(s)?://(\w+\.)?arte.tv/")
_json_re = re.compile('arte_vp_(?:live-)?url="([^"]+)"')

_schema = validate.Schema(
    validate.transform(_json_re.search), validate.any(None, validate.all(validate.get(1), validate.url(scheme="http")))
)
_video_schema = validate.Schema(
    {
        "videoJsonPlayer": {
            "VSR": validate.any(
                [],
                {
                    validate.text: {
                        "height": int,
                        "mediaType": validate.text,
                        "url": validate.text,
                        validate.optional("streamer"): validate.text,
                    }
                },
            ),
Example #50
0
    (?:
        tv4play.se/program/[^\?/]+
    )?
    (?:
        fotbollskanalen.se/video
    )?
    .+(video_id|videoid)=(?P<video_id>\d+)
""", re.VERBOSE)

_asset_schema = validate.Schema(
    validate.xml_findall("items/item"),
    [
        validate.all(
            validate.xml_findall("*"),
            validate.map(lambda e: (e.tag, e.text)),
            validate.transform(dict),
            {
                "base": validate.text,
                "bitrate": validate.all(
                    validate.text, validate.transform(int)
                ),
                "url": validate.text
            }
        )
    ]
)


class TV4Play(Plugin):
    @classmethod
    def can_handle_url(cls, url):
Example #51
0
            validate.xml_element(attrib={"content": validate.text}),
            validate.get("content")),
        "videos":
        validate.all(
            validate.xml_findall(
                "{http://www.w3.org/2001/SMIL20/Language}body/"
                "{http://www.w3.org/2001/SMIL20/Language}switch/"
                "{http://www.w3.org/2001/SMIL20/Language}video"),
            [
                validate.all(
                    validate.xml_element(
                        attrib={
                            "src":
                            validate.text,
                            "system-bitrate":
                            validate.all(validate.text, validate.transform(
                                int))
                        }),
                    validate.transform(lambda e: (e.attrib["src"], e.attrib[
                        "system-bitrate"])))
            ],
        )
    }))


class Livestream(Plugin):
    @classmethod
    def default_stream_types(cls, streams):
        return ["akamaihd", "hls"]

    @classmethod
    def can_handle_url(self, url):
Example #52
0
    "vaughnlive": "live",
}

_url_re = re.compile("""
    http(s)?://(\w+\.)?
    (?P<domain>vaughnlive|breakers|instagib|vapers).tv
    /(?P<channel>[^/&?]+)
""", re.VERBOSE)
_channel_not_found_re = re.compile("<title>Channel Not Found")


def decode_token(token):
    return token.replace("0m0", "")

_schema = validate.Schema(
    validate.transform(lambda s: s.split(";:mvnkey-")),
    validate.length(2),
    validate.union({
        "server": validate.all(
            validate.get(0),
            validate.text
        ),
        "token": validate.all(
            validate.get(1),
            validate.text,
            validate.transform(decode_token)
        )
    })
)

Example #53
0
STREAMING_TYPES = {
    "streamingUrlLive": (
        "HDS", partial(HDSStream.parse_manifest, pvswf=SWF_URL)
    ),
    "streamingUrlIPhone": (
        "HLS", HLSStream.parse_variant_playlist
    )
}

_url_re = re.compile("http(s)?://live.daserste.de/(?P<channel>[^/?]+)?")

_livestream_schema = validate.Schema(
    validate.xml_findall("video/*"),
    validate.filter(lambda e: e.tag in STREAMING_TYPES),
    validate.map(lambda e: (STREAMING_TYPES.get(e.tag), e.text)),
    validate.transform(dict),
)

class ard_live(Plugin):
    @classmethod
    def can_handle_url(cls, url):
        return _url_re.match(url)

    def _get_streams(self):
        match = _url_re.match(self.url)
        channel = match.group("channel")
        res = http.get(STREAM_INFO_URL.format(channel))
        urls = http.xml(res, schema=_livestream_schema)

        streams = {}
        for (name, parser), url in urls.items():
Example #54
0
import re

from livestreamer.plugin import Plugin
from livestreamer.plugin.api import http, validate
from livestreamer.stream import HLSStream

_url_re = re.compile("http(s)?://chaturbate.com/[^/?&]+")
_playlist_url_re = re.compile("html \+= \"src='(?P<url>[^']+)'\";")
_schema = validate.Schema(
    validate.transform(_playlist_url_re.search),
    validate.any(
        None,
        validate.all(
            validate.get("url"),
            validate.url(
                scheme="http",
                path=validate.endswith(".m3u8")
            )
        )
    )
)


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

    def _get_streams(self):
        playlist_url = http.get(self.url, schema=_schema)
        if not playlist_url:
Example #55
0
_url_re = re.compile(
    """
    http(s)?://(\w+\.)?
    (?P<domain>vaughnlive|breakers|instagib|vapers).tv
    /(?P<channel>[^/&?]+)
""", re.VERBOSE)
_channel_not_found_re = re.compile("<title>Channel Not Found")


def decode_token(token):
    return token.replace("0m0", "")


_schema = validate.Schema(
    validate.transform(lambda s: s.split(";:mvnkey%")), validate.length(2),
    validate.union({
        "server":
        validate.all(validate.get(0), validate.text),
        "token":
        validate.all(validate.get(1), validate.text,
                     validate.transform(decode_token))
    }))


class VaughnLive(Plugin):
    @classmethod
    def can_handle_url(cls, url):
        return _url_re.match(url)

    def _get_streams(self):
Example #56
0
import re

from itertools import chain

from livestreamer.compat import urlparse
from livestreamer.plugin import Plugin
from livestreamer.plugin.api import http, validate
from livestreamer.stream import HLSStream, HTTPStream, RTMPStream

SWF_URL = "http://www.arte.tv/player/v2/jwplayer6/mediaplayer.6.6.swf"

_url_re = re.compile("http(s)?://(\w+\.)?arte.tv/")
_json_re = re.compile("arte_vp_(?:live-)?url=(['\"])(.+?)\\1")

_schema = validate.Schema(
    validate.transform(_json_re.search),
    validate.any(None,
                 validate.all(validate.get(2), validate.url(scheme="http"))))
_video_schema = validate.Schema({
    "videoJsonPlayer": {
        "VSR":
        validate.any(
            [],
            {
                validate.text: {
                    "height": int,
                    "mediaType": validate.text,
                    "url": validate.text,
                    validate.optional("streamer"): validate.text
                },
            },
Example #57
0
import re

from livestreamer.compat import urlparse
from livestreamer.plugin import Plugin
from livestreamer.plugin.api import http, validate
from livestreamer.stream import HLSStream, HTTPStream

_url_re = re.compile("http(s)?://(\w+\.)?seemeplay.ru/")
_player_re = re.compile(
    """
    SMP.(channel|video).player.init\({
    \s+file:\s+"([^"]+)"
""", re.VERBOSE)

_schema = validate.Schema(
    validate.transform(_player_re.search),
    validate.any(
        None,
        validate.union({
            "type":
            validate.get(1),
            "url":
            validate.all(
                validate.get(2),
                validate.url(scheme="http"),
            ),
        })))


class SeeMePlay(Plugin):
    @classmethod