本文整理汇总了Python中livestreamer.stream.RTMPStream类的典型用法代码示例。如果您正苦于以下问题:Python RTMPStream类的具体用法?Python RTMPStream怎么用?Python RTMPStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RTMPStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_rtmp_streams
def _get_rtmp_streams(self):
def clean_tag(tag):
if tag[0] == "_":
return tag[1:]
else:
return tag
chansub = self._authenticate()
url = self.StreamInfoURL.format(self.channelname)
params = dict(b_id="true", group="", private_code="null",
p=int(random.random() * 999999),
channel_subscription=chansub, type="any")
self.logger.debug("Fetching stream info")
res = urlget(url, params=params)
data = res.text
# fix invalid xml
data = re.sub("<(\d+)", "<_\g<1>", data)
data = re.sub("</(\d+)", "</_\g<1>", data)
streams = {}
try:
dom = xml.dom.minidom.parseString(data)
except Exception as err:
raise PluginError(("Unable to parse config XML: {0})").format(err))
nodes = dom.getElementsByTagName("nodes")[0]
if len(nodes.childNodes) == 0:
return streams
swfurl = urlresolve(self.SWFURL)
for node in nodes.childNodes:
info = {}
for child in node.childNodes:
info[child.tagName] = self._get_node_text(child)
if not ("connect" in info and "play" in info):
continue
stream = RTMPStream(self.session, {
"rtmp": ("{0}/{1}").format(info["connect"], info["play"]),
"swfVfy": swfurl,
"live": True
})
sname = clean_tag(node.tagName)
if "token" in info:
stream.params["jtv"] = info["token"]
else:
self.logger.warning("No token found for stream {0}, this stream may fail to play", sname)
streams[sname] = stream
return streams
示例2: _get_rtmp_streams
def _get_rtmp_streams(self):
chansub = self._authenticate()
url = self.StreamInfoURL.format(self.channelname)
params = dict(
b_id="true",
group="",
private_code="null",
p=int(random.random() * 999999),
channel_subscription=chansub,
type="any",
)
self.logger.debug("Fetching stream info")
res = urlget(url, params=params)
json = res_json(res, "stream info JSON")
if not isinstance(json, list):
raise PluginError("Invalid JSON response")
if len(json) == 0:
raise NoStreamsError(self.url)
streams = {}
swfurl, swfhash, swfsize = self._verify_swf()
for info in json:
if not ("connect" in info and "play" in info and "type" in info):
continue
stream = RTMPStream(
self.session,
{
"rtmp": ("{0}/{1}").format(info["connect"], info["play"]),
"swfUrl": swfurl,
"swfhash": swfhash,
"swfsize": swfsize,
"live": True,
},
)
if "display" in info:
sname = info["display"]
else:
sname = info["type"]
if "token" in info:
stream.params["jtv"] = info["token"]
else:
self.logger.warning("No token found for stream {0}, this stream may fail to play", sname)
streams[sname] = stream
return streams
示例3: _get_streaminfo
def _get_streaminfo(self, channelname):
def clean_tag(tag):
if tag[0] == "_":
return tag[1:]
else:
return tag
metadata = self._get_metadata(channelname)
randomp = int(random.random() * 999999)
if "chansub_guid" in metadata:
url = self.StreamInfoURLSub.format(channelname, randomp, metadata["chansub_guid"])
else:
url = self.StreamInfoURL.format(channelname, randomp)
data = urlget(url)
# fix invalid xml
data = re.sub(b"<(\d+)", b"<_\g<1>", data)
data = re.sub(b"</(\d+)", b"</_\g<1>", data)
streams = {}
try:
dom = xml.dom.minidom.parseString(data)
except Exception as err:
raise PluginError(("Unable to parse config XML: {0})").format(err))
nodes = dom.getElementsByTagName("nodes")[0]
swfhash, swfsize = swfverify(self.SWFURL)
for node in nodes.childNodes:
info = {}
for child in node.childNodes:
info[child.tagName] = self._get_node_text(child)
stream = RTMPStream({
"rtmp": ("{0}/{1}").format(info["connect"], info["play"]),
"swfUrl": self.SWFURL,
"swfhash": swfhash,
"swfsize": swfsize,
"live": 1
})
if "token" in info:
stream.params["jtv"] = info["token"]
sname = clean_tag(node.tagName)
streams[sname] = stream
return streams
示例4: _get_live_streams
def _get_live_streams(self):
streams = defaultdict(list)
if RTMPStream.is_usable(self.session):
try:
for name, stream in self._get_desktop_streams().items():
streams[name].append(stream)
except PluginError as err:
self.logger.error("Error when fetching desktop streams: {0}",
err)
except NoStreamsError:
pass
else:
self.logger.warning("rtmpdump is not usable, "
"only mobile streams may be available")
try:
for name, stream in self._get_mobile_streams().items():
# Justin.tv streams have a iphone prefix, so let's
# strip it to keep it consistent with Twitch.
name = name.replace("iphone", "")
streams[name].append(stream)
except PluginError as err:
self.logger.error("Error when fetching mobile streams: {0}",
err)
except NoStreamsError:
pass
return streams
示例5: _get_streams
def _get_streams(self):
if not RTMPStream.is_usable(self.session):
self.logger.warning("rtmpdump is not usable, only HDS streams will be available")
self.logger.debug("Fetching stream info")
match = re.search("/\w*/(live|video)*/(\d+)", self.url)
if not match:
return
stream_id = match.group(2)
res = http.get(API_URL, params=dict(ak="web", id=stream_id))
root = parse_xml(res.text.encode("utf8"))
streams = {}
for formitaet in root.iter('formitaet'):
url = formitaet.find('url').text
quality = formitaet.find('quality').text
if formitaet.get('basetype') == "h264_aac_f4f_http_f4m_http":
hds_streams = HDSStream.parse_manifest(self.session, url)
streams.update(hds_streams)
elif formitaet.get('basetype') == 'h264_aac_mp4_rtmp_zdfmeta_http':
streams[quality] = RTMPStream(self.session, {
"rtmp": self._get_stream(url),
"pageUrl": self.url,
})
return streams
示例6: _get_streams
def _get_streams(self):
if not RTMPStream.is_usable(self.session):
raise PluginError("rtmpdump is not usable and required by Filmon plugin")
self.logger.debug("Fetching stream info")
self.rsession = requests.session()
res = urlget(self.url, session=self.rsession)
match = re.search("movie_id=(\d+)", res.text)
if match:
return self._get_vod_stream(match.group(1))
match = re.search("/channels/(\d+)/extra_big_logo.png", res.text)
if not match:
return
channel_id = match.group(1)
streams = {}
for quality in ("low", "high"):
try:
streams[quality] = self._get_stream(channel_id, quality)
except NoStreamsError:
pass
return streams
示例7: _get_rtmp_streams
def _get_rtmp_streams(self, swfurl):
if not RTMPStream.is_usable(self.session):
raise NoStreamsError(self.url)
self.logger.debug("Fetching RTMP stream info")
res = http.get(swfurl)
swf = swfdecompress(res.content)
match = re.search("customURL[^h]+(https://.*?)\\\\", swf)
if not match:
raise NoStreamsError(self.url)
res = http.get(match.group(1))
rtmp, playpath = rtmpparse(res.text)
params = {
"rtmp": rtmp,
"pageUrl": self.url,
"playpath": playpath,
"live": True
}
match = re.search("file[^h]+(https?://.*?.swf)", swf)
if match:
params["swfUrl"] = match.group(1)
return RTMPStream(self.session, params)
示例8: _get_streams
def _get_streams(self, type):
self.channelname = self._get_channel_name(self.url)
if not self.channelname:
raise NoStreamsError(self.url)
streams = {}
if type in (None, StreamType.RTMP):
if RTMPStream.is_usable(self.session):
try:
rtmpstreams = self._get_rtmp_streams()
streams.update(rtmpstreams)
except PluginError as err:
self.logger.error("Error when fetching RTMP stream info: {0}", str(err))
else:
self.logger.warning("rtmpdump is not usable, only HLS streams will be available")
if type in (None, StreamType.HLS):
try:
hlsstreams = self._get_hls_streams()
if len(streams) > 0:
hlssuffix = "_hls"
else:
hlssuffix = ""
for name, stream in hlsstreams.items():
streams[name + hlssuffix] = stream
except PluginError as err:
self.logger.error("Error when fetching HLS stream info: {0}", str(err))
return streams
示例9: _get_live_streams
def _get_live_streams(self, *args, **kwargs):
streams = defaultdict(list)
if RTMPStream.is_usable(self.session):
try:
for name, stream in self._get_desktop_streams(*args, **kwargs).items():
streams[name].append(stream)
except PluginError as err:
self.logger.error("Error when fetching desktop streams: {0}",
err)
except NoStreamsError:
pass
else:
self.logger.warning("rtmpdump is required to access the desktop "
"streams, but it could not be found")
try:
for name, stream in self._get_mobile_streams(*args, **kwargs).items():
# Justin.tv streams have a iphone prefix, so let's
# strip it to keep it consistent with Twitch.
name = name.replace("iphone", "")
streams[name].append(stream)
except PluginError as err:
self.logger.error("Error when fetching mobile streams: {0}",
err)
except NoStreamsError:
pass
return streams
示例10: _get_streams
def _get_streams(self):
channelid = urlparse(self.url).path.rstrip("/").rpartition("/")[-1].lower()
self.logger.debug("Fetching stream info")
headers = {"Referer": self.url}
options = dict(id=channelid)
res = urlget(self.StreamInfoURL, headers=headers, params=options)
json = res_json(res, "stream info JSON")
if not isinstance(json, dict):
raise PluginError("Invalid JSON response")
if not ("rtmp" in json and "streamname" in json):
raise NoStreamsError(self.url)
if not RTMPStream.is_usable(self.session):
raise PluginError("rtmpdump is not usable and required by Owncast plugin")
rtmp = json["rtmp"]
playpath = json["streamname"]
streams = {}
streams["live"] = RTMPStream(
self.session, {"rtmp": rtmp, "pageUrl": self.url, "swfUrl": self.SWFURL, "playpath": playpath, "live": True}
)
return streams
示例11: _get_streams
def _get_streams(self):
self.channelname = self._get_channel_name(self.url)
if not self.channelname:
raise NoStreamsError(self.url)
streams = {}
if RTMPStream.is_usable(self.session):
try:
rtmpstreams = self._get_rtmp_streams()
streams.update(rtmpstreams)
except PluginError as err:
self.logger.error("Error when fetching RTMP stream info: {0}", str(err))
else:
self.logger.warning("rtmpdump is not usable, only HLS streams will be available")
try:
hlsstreams = self._get_hls_streams()
for name, stream in hlsstreams.items():
if name in streams:
streams[name] = [streams[name], stream]
else:
streams[name] = stream
except PluginError as err:
self.logger.error("Error when fetching HLS stream info: {0}", str(err))
return streams
示例12: _get_streams_from_rtmp
def _get_streams_from_rtmp(self):
password = self.options.get("password")
module_info = self._get_module_info("channel", self.channel_id,
password)
if not module_info:
raise NoStreamsError(self.url)
providers = module_info.get("stream")
if providers == "offline":
raise NoStreamsError(self.url)
elif not isinstance(providers, list):
raise PluginError("Invalid stream info: {0}".format(providers))
streams = {}
for provider in filter(valid_provider, providers):
provider_url = provider.get("url")
provider_name = provider.get("name")
provider_streams = provider.get("streams")
for stream_index, stream_info in enumerate(provider_streams):
stream = None
stream_height = int(stream_info.get("height", 0))
stream_name = stream_info.get("description")
if not stream_name:
if stream_height:
if not stream_info.get("isTranscoded"):
stream_name = "{0}p+".format(stream_height)
else:
stream_name = "{0}p".format(stream_height)
else:
stream_name = "live"
if stream_name in streams:
provider_name_clean = provider_name.replace("uhs_", "")
stream_name += "_alt_{0}".format(provider_name_clean)
if provider_name.startswith("uhs_"):
stream = UHSStream(self.session, self.channel_id,
self.url, provider_name,
stream_index, password)
elif (provider_url.startswith("rtmp") and
RTMPStream.is_usable(self.session)):
playpath = stream_info.get("streamName")
stream = self._create_rtmp_stream(provider_url,
playpath)
if stream:
streams[stream_name] = stream
return streams
示例13: _get_streams
def _get_streams(self):
self.logger.debug("Fetching stream info")
res = urlget(self.url)
match = re.search("var current_channel = (.*);", res.text)
if match:
json = parse_json(match.group(1))
else:
raise NoStreamsError(self.url)
if not isinstance(json, dict):
raise PluginError("Invalid JSON response")
elif not "streams" in json:
raise NoStreamsError(self.url)
if not RTMPStream.is_usable(self.session):
raise PluginError("rtmpdump is not usable and required by Filmon plugin")
match = re.search("var flash_config = (.*);", res.text)
if match:
config = parse_json(match.group(1))
if "streamer" in config:
self.SWFURL = urljoin(self.SWFURL, config["streamer"])
streams = {}
for stream in json["streams"]:
if not ("url" in stream and "name" in stream):
continue
parsed = urlparse(stream["url"])
if not parsed.scheme.startswith("rtmp"):
continue
if parsed.query:
app = "{0}?{1}".format(parsed.path[1:], parsed.query)
else:
app = parsed.path[1:]
name = stream["quality"]
streams[name] = RTMPStream(self.session, {
"rtmp": stream["url"],
"pageUrl": self.url,
"swfUrl": self.SWFURL,
"playpath": stream["name"],
"app": app,
"live": True
})
return streams
示例14: _get_streams
def _get_streams(self):
# If email option given, try to login
if self.options.get("email"):
res = http.get(self.LOGINPAGEURL)
match = re.search('<meta content="([^"]+)" name="csrf-token"', res.text)
if not match:
raise PluginError("Missing CSRF Token: " + self.LOGINPAGEURL)
csrf_token = match.group(1)
email = self.options.get("email")
password = self.options.get("password")
res = http.post(
self.LOGINPOSTURL,
data={
"authenticity_token": csrf_token,
"channel_id": "",
"commit": "Login",
"plan_id": "",
"session[email]": email,
"session[password]": password,
"utf8": "\xE2\x9C\x93", # Check Mark Character
},
)
self.logger.debug("Login account info: {0}", res.text)
result = http.json(res)
if result.get("email", "no-mail") != email:
raise PluginError("Invalid account")
res = http.get(self.url)
streams = {}
if RTMPStream.is_usable(self.session):
try:
rtmpstreams = self._get_rtmp_streams(res.text)
streams.update(rtmpstreams)
except PluginError as err:
self.logger.error("Error when fetching RTMP stream info: {0}", str(err))
else:
self.logger.warning("rtmpdump is not usable, only HLS streams will be available")
try:
hlsstreams = self._get_hls_streams(res.text)
streams.update(hlsstreams)
except PluginError as err:
self.logger.error("Error when fetching HLS stream info: {0}", str(err))
return streams
示例15: _get_streams
def _get_streams(self):
params = parse_qsd(urlparse(self.url).query)
if not 'watch' in params:
raise NoStreamsError(self.url)
channel = params['watch']
if not RTMPStream.is_usable(self.session):
raise PluginError("rtmpdump is not usable but required by Picarto plugin")
streams = {}
streams["live"] = RTMPStream(self.session, {
"rtmp": "rtmp://199.189.86.17/dsapp/{0}.flv".format(channel),
"pageUrl": self.url,
"live": True
})
return streams