本文整理汇总了Python中livestreamer.Livestreamer.streams方法的典型用法代码示例。如果您正苦于以下问题:Python Livestreamer.streams方法的具体用法?Python Livestreamer.streams怎么用?Python Livestreamer.streams使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类livestreamer.Livestreamer
的用法示例。
在下文中一共展示了Livestreamer.streams方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from livestreamer import Livestreamer [as 别名]
# 或者: from livestreamer.Livestreamer import streams [as 别名]
def main():
if len(sys.argv) < 3:
exit("Usage: {0} <url> <quality>".format(sys.argv[0]))
gi.require_version("Gst", "1.0")
gobject.threads_init()
gst.init(None)
url = sys.argv[1]
quality = sys.argv[2]
livestreamer = Livestreamer()
livestreamer.set_loglevel("info")
livestreamer.set_logoutput(sys.stdout)
try:
streams = livestreamer.streams(url)
except NoPluginError:
exit("Livestreamer is unable to handle the URL '{0}'".format(url))
except PluginError as err:
exit("Plugin error: {0}.".format(err))
if not streams:
exit("No streams found on URL '{0}'.".format(url))
if quality not in streams:
exit("Unable to find '{0}' stream on URL '{1}'".format(quality, url))
stream = streams[quality]
player = LivestreamerPlayer()
player.play(stream)
示例2: _getLiveUrl
# 需要导入模块: from livestreamer import Livestreamer [as 别名]
# 或者: from livestreamer.Livestreamer import streams [as 别名]
def _getLiveUrl(target):
livestreamer = Livestreamer()
streams = livestreamer.streams("http://www.twitch.tv/" + target)
print(streams)
if streams:
# default
# xx = streams.popitem()
# return xx[1].url
xx = streams.get('high')
return xx.url
return None
示例3: __init__
# 需要导入模块: from livestreamer import Livestreamer [as 别名]
# 或者: from livestreamer.Livestreamer import streams [as 别名]
class Application:
def __init__(self, window, stream_list):
self.window = window
self.stream_list = stream_list
self.livestreamer = Livestreamer()
def refresh_key(self):
self.stream_list.update_streamers()
self.refresh_screen()
def refresh_screen(self):
self.window.screen.erase()
self.window.draw_borders()
self.window.draw_help()
self.stream_list.draw_streamers()
self.window.screen.refresh()
def up_key(self, distance=1):
self.stream_list.move_up(distance)
self.refresh_screen()
def down_key(self, distance=1):
self.stream_list.move_down(distance)
self.refresh_screen()
def sort_key(self):
self.stream_list.toggle_sort()
self.refresh_screen()
def sort_order_key(self):
self.stream_list.toggle_sort_order()
self.refresh_screen()
def resize_event(self):
self.window.resize_term()
self.refresh_screen()
def play_stream(self, livestreamer_config=None, quality="best"):
url = self.stream_list.get_twitch_url()
streams = self.livestreamer.streams(url)
stream = streams[quality]
call = []
call.append('livestreamer')
call.append('--quiet')
if livestreamer_config is not None:
call.append('--config')
call.append(livestreamer_config)
call.append(url)
call.append(quality)
subprocess.Popen(call)
示例4: serveFile
# 需要导入模块: from livestreamer import Livestreamer [as 别名]
# 或者: from livestreamer.Livestreamer import streams [as 别名]
def serveFile(self, fURL, sendData):
from livestreamer import Livestreamer, StreamError, PluginError, NoPluginError
session = Livestreamer()
if '|' in fURL:
sp = fURL.split('|')
fURL = sp[0]
headers = dict(urlparse.parse_qsl(sp[1]))
session.set_option("http-headers", headers)
cookies = dict(urlparse.parse_qsl(sp[2]))
session.set_option("http-cookie", cookies)
streams = session.streams(fURL)
except:
示例5: stream_recording
# 需要导入模块: from livestreamer import Livestreamer [as 别名]
# 或者: from livestreamer.Livestreamer import streams [as 别名]
def stream_recording():
print("STARTING TO RECORD STREAM")
session = Livestreamer()
stream = session.streams('http://www.twitch.tv/' + channel)
print("CONNECTED TO STREAM")
stream = stream['source']
fd = stream.open()
print("CONNECTED!")
f = open("stream.dat", 'wb')
while True:
data = fd.read(1024)
f.write(data)
示例6: serveFile
# 需要导入模块: from livestreamer import Livestreamer [as 别名]
# 或者: from livestreamer.Livestreamer import streams [as 别名]
def serveFile(self, fURL, sendData):
session = Livestreamer()
if '|' in fURL:
sp = fURL.split('|')
fURL = sp[0]
headers = dict(urlparse.parse_qsl(sp[1]))
if 'cdn.sstream.pw' in fURL:
fURL = fURL.replace('cdn.sstream.pw',random.choice(s))
headers['Host'] = '6b6473616a6b6c647361646a7361643737353637647361393973616768647368686464732e736974656e6f772e6d65'.decode('hex')
session.set_option("http-headers", headers)
session.set_option("http-ssl-verify",False)
session.set_option("hls-segment-threads",3)
try:
streams = session.streams(fURL)
except:
traceback.print_exc(file=sys.stdout)
self.send_response(403)
self.send_response(200)
#print "XBMCLocalProxy: Sending headers..."
self.end_headers()
if (sendData):
#print "XBMCLocalProxy: Sending data..."
fileout = self.wfile
try:
stream = streams["best"]
try:
response = stream.open()
buf = 'INIT'
while (buf != None and len(buf) > 0):
buf = response.read(200 * 1024)
fileout.write(buf)
fileout.flush()
response.close()
fileout.close()
#print time.asctime(), "Closing connection"
except socket.error, e:
#print time.asctime(), "Client Closed the connection."
try:
response.close()
fileout.close()
except Exception, e:
return
except Exception, e:
traceback.print_exc(file=sys.stdout)
response.close()
fileout.close()
示例7: init_gstream
# 需要导入模块: from livestreamer import Livestreamer [as 别名]
# 或者: from livestreamer.Livestreamer import streams [as 别名]
def init_gstream(self):
# if len(sys.argv) < 3:
# exit("Usage: {0} <url> <quality>".format(sys.argv[0]))
# Initialize and check GStreamer version
gi.require_version("Gst", "1.0")
gobject.threads_init()
gst.init(None)
# Collect arguments
url = "twitch.tv/" + self.stream_textbox.get_text()
# Create the Livestreamer session
livestreamer = Livestreamer()
# Enable logging
livestreamer.set_loglevel("info")
livestreamer.set_logoutput(sys.stdout)
# Attempt to fetch streams
try:
streams = livestreamer.streams(url)
except NoPluginError:
print("Livestreamer is unable to handle the URL '{0}'".format(url))
except PluginError as err:
print("Plugin error: {0}".format(err))
if not streams:
print("No streams found on URL '{0}'".format(url))
# Look for specified stream
elif self.quality not in streams:
print("Unable to find '{0}' stream on URL '{1}'".format(self.quality, url))
# We found the stream
else:
stream = streams[self.quality]
# Create the player and start playback
# player = LivestreamerPlayer()
win = PI()
win.play(stream)
win.connect("delete-event", gtk.main_quit)
win.show_all()
win.main()
示例8: serveFile
# 需要导入模块: from livestreamer import Livestreamer [as 别名]
# 或者: from livestreamer.Livestreamer import streams [as 别名]
def serveFile(self, fURL, sendData):
session = Livestreamer()
if '|' in fURL:
sp = fURL.split('|')
fURL = sp[0]
headers = dict(urlparse.parse_qsl(sp[1]))
session.set_option("http-headers", headers)
session.set_option("http-ssl-verify",False)
session.set_option("hls-segment-threads",2)
try:
streams = session.streams(fURL)
except:
traceback.print_exc(file=sys.stdout)
self.send_response(403)
self.send_response(200)
#print "XBMCLocalProxy: Sending headers..."
self.end_headers()
if (sendData):
#print "XBMCLocalProxy: Sending data..."
fileout = self.wfile
try:
stream = streams["best"]
try:
response = stream.open()
buf = 'INIT'
while (buf != None and len(buf) > 0):
buf = response.read(200 * 1024)
fileout.write(buf)
fileout.flush()
response.close()
fileout.close()
#print time.asctime(), "Closing connection"
except socket.error, e:
#print time.asctime(), "Client Closed the connection."
try:
response.close()
fileout.close()
except Exception, e:
return
except Exception, e:
traceback.print_exc(file=sys.stdout)
response.close()
fileout.close()
示例9: main
# 需要导入模块: from livestreamer import Livestreamer [as 别名]
# 或者: from livestreamer.Livestreamer import streams [as 别名]
def main():
if len(sys.argv) < 3:
exit("Usage: {0} <url> <quality>".format(sys.argv[0]))
# Initialize and check GStreamer version
gi.require_version("Gst", "1.0")
gobject.threads_init()
gst.init(None)
# Collect arguments
url = sys.argv[1]
quality = sys.argv[2]
# Create the Livestreamer session
livestreamer = Livestreamer()
# Enable logging
livestreamer.set_loglevel("info")
livestreamer.set_logoutput(sys.stdout)
# Attempt to fetch streams
try:
streams = livestreamer.streams(url)
except NoPluginError:
exit("Livestreamer is unable to handle the URL '{0}'".format(url))
except PluginError as err:
exit("Plugin error: {0}".format(err))
if not streams:
exit("No streams found on URL '{0}'".format(url))
# Look for specified stream
if quality not in streams:
exit("Unable to find '{0}' stream on URL '{1}'".format(quality, url))
# We found the stream
stream = streams[quality]
# Create the player and start playback
player = LivestreamerPlayer()
# Blocks until playback is done
player.play(stream)
示例10: stream_recording
# 需要导入模块: from livestreamer import Livestreamer [as 别名]
# 或者: from livestreamer.Livestreamer import streams [as 别名]
def stream_recording():
from livestreamer import Livestreamer
print(": Starting to record stream")
session = Livestreamer()
stream = session.streams('http://www.twitch.tv/' + channel)
print("Connecting to stream")
stream = stream['source']
fd = stream.open()
print("Connected!")
#lock = threading.Lock()
f = open("stream.dat", 'wb')# with open("stream.dat", 'wb') as f:
global front
while True:
data = fd.read(1024)
f.write(data)
front += len(data)
示例11: openStream
# 需要导入模块: from livestreamer import Livestreamer [as 别名]
# 或者: from livestreamer.Livestreamer import streams [as 别名]
def openStream(url, quality):
"""Open a livestreamer URL and return the stream"""
livestreamer = Livestreamer()
setOptions(livestreamer)
try:
streams = livestreamer.streams(url)
except NoPluginError:
print("Unable to Find Plugin")
abort(404)
except PluginError as err:
print("Plugin error: {0}".format(err))
abort(404)
if quality not in streams:
print("Quality {0} not available in {1}".format(quality, url))
abort(404)
return streams[quality]
示例12: serveFile
# 需要导入模块: from livestreamer import Livestreamer [as 别名]
# 或者: from livestreamer.Livestreamer import streams [as 别名]
def serveFile(self, fURL, sendData):
session = Livestreamer()
if '|' in fURL:
sp = fURL.split('|')
fURL = sp[0]
headers = dict(urlparse.parse_qsl(sp[1]))
session.set_option("http-headers", headers)
session.set_option("http-ssl-verify", False)
try:
streams = session.streams(fURL)
self.send_response(200)
except:
self.send_response(403)
finally:
self.end_headers()
if (sendData):
with streams["best"].open() as stream:
buf = 'INIT'
while (len(buf) > 0):
buf = stream.read(500 * 1024)
self.wfile.write(buf)
示例13: check_online
# 需要导入模块: from livestreamer import Livestreamer [as 别名]
# 或者: from livestreamer.Livestreamer import streams [as 别名]
def check_online(stream_name):
# Collect arguments
url = "twitch.tv/" + stream_name
# Create the Livestreamer session
livestreamer = Livestreamer()
# Enable logging
livestreamer.set_loglevel("info")
livestreamer.set_logoutput(sys.stdout)
# Attempt to fetch streams
try:
streams = livestreamer.streams(url)
except NoPluginError:
print("Livestreamer is unable to handle the URL '{0}'".format(url))
except PluginError as err:
print("Plugin error: {0}".format(err))
if not streams:
print("No streams found on URL '{0}'".format(url))
return False
else:
return True
示例14: get_classifier
# 需要导入模块: from livestreamer import Livestreamer [as 别名]
# 或者: from livestreamer.Livestreamer import streams [as 别名]
else:
print "Randomly selecting a streamer..."
streamer = random.choice((
"tsm_doublelift",
"grossie_gore",
"wingsofdeath"
))
classifier = get_classifier()
is_in_lol = False
print "Waiting for streamer %s to join a game..." % streamer
while True:
session = Livestreamer()
streams = session.streams('http://www.twitch.tv/%s' % streamer)
if streams:
stream = streams['source']
container = av.open(stream.url)
video_stream = next(s for s in container.streams if s.type == b'video')
image = None
for packet in container.demux(video_stream):
for frame in packet.decode():
image = frame.to_image()
features = process_image(image)
# save our old state before checking new state, only show message when state changes
old_is_in_lol = is_in_lol
示例15: Livestreamer
# 需要导入模块: from livestreamer import Livestreamer [as 别名]
# 或者: from livestreamer.Livestreamer import streams [as 别名]
from livestreamer import Livestreamer
session = Livestreamer()
stream = session.streams("http://www.twitch.tv/starladder_cs_en")
print("connected")
stream = stream["source"]
fd = stream.open()
print("done")
front = 0
rear = 0
with open("stream.dat", "wb") as f:
while front < 1024 * 6000:
data = fd.read(1024)
f.write(data)
front += 1024
print("writing")
while True:
if front == 1024 * 12000:
f.seek(0)
front = 0
if rear == 1024 * 12000:
rear = 0
data = fd.read(1024)
f.write(data)
front += 1024
rear += 1024
print("writing")