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)
def watch(url):
    session = Livestreamer()
    session.set_loglevel('info')
    session.set_logoutput(sys.stdout)
    session.set_option('http-headers',
                       'Client-ID=jzkbprff40iqj646a697cyrvl0zt2m6')

    streams = session.streams(url)
    stream = streams['audio_only']

    fd = stream.open()  # read to nowhere
    while True:
        fd.read(1024)
Exemple #3
0
	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()
Exemple #4
0
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)
Exemple #5
0
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)
Exemple #6
0
def main():
    if len(sys.argv) < 3:
        exit("Usage: {0} <url> <quality>".format(sys.argv[0]))

    # 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 find a plugin for this URL
    try:
        plugin = livestreamer.resolve_url(url)
    except NoPluginError:
        exit("Livestreamer is unable to handle the URL '{0}'".format(url))

    # Attempt to fetch streams
    try:
        streams = plugin.get_streams()
    except PluginError as err:
        exit("Plugin error: {0}".format(err))

    if len(streams) == 0:
        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)
def main():
    if len(sys.argv) < 3:
        exit("Usage: {0} <url> <quality>".format(sys.argv[0]))

    # 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 find a plugin for this URL
    try:
        plugin = livestreamer.resolve_url(url)
    except NoPluginError:
        exit("Livestreamer is unable to handle the URL '{0}'".format(url))

    # Attempt to fetch streams
    try:
        streams = plugin.get_streams()
    except PluginError as err:
        exit("Plugin error: {0}".format(err))

    if len(streams) == 0:
        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)
Exemple #8
0
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
Exemple #9
0
"""
Test Livestreamer Script for enigma2

Test commands:
cd /usr/lib/enigma2/python/Plugins/Extensions/GreekStreamTV
python testme.py

"""
import sys
sys.path.append('/usr/lib/enigma2/python/Plugins/Extensions/GreekStreamTV')
import os
import requests
from livestreamer import Livestreamer
url = 'http://www.dailymotion.com/video/xqjey2'
livestreamer = Livestreamer()
livestreamer.set_loglevel('debug')
channel = livestreamer.resolve_url(url)
streams = channel.get_streams()
print 'Streams:', streams.keys()
stream = streams['best']
print stream
fd = stream.open()
while True:
    data = fd.read(1024)
    if len(data) == 0:
        break
    else:
        print 'Got Data! Livestreamer Works!'
        break

if hasattr(fd, 'close'):
Exemple #10
0
"""

import sys
sys.path.append("/usr/lib/enigma2/python/Plugins/Extensions/GreekStreamTV")

import os
import requests
from livestreamer import Livestreamer

url = "http://www.dailymotion.com/video/xqjey2"
#url = "hds://*****:*****@87036/manifest.f4m"
#url = "http://www.youtube.com/watch?v=ZTf2EzTd1TE"

livestreamer = Livestreamer()
livestreamer.set_loglevel("debug")
channel = livestreamer.resolve_url(url)
streams = channel.get_streams()

print 'Streams:', streams.keys()

stream = streams["best"]
print stream

fd = stream.open()

while True:
    data = fd.read(1024)
    if len(data) == 0:
        break
    else:
Exemple #11
0
def dodownload(a):
    if a.user_id in recording:
        return
    recording.append(a.user_id)
    print(f'\r\033[K{a.user_id}start')
    live = a.get_streams()
    if live:
        playlists = a.host_data['arguments']['playlists']
        for i in playlists:
            if i['mode'] == 0 or i['mode'] == '0':
                print(f'\r\033[K{a.user_id}获取主列表{i["url"]}')
                master = i['url']
        #session = Streamlink()
        session = Livestreamer()
        if threads:
            session.set_option('hls-segment-threads', int(threads))
        if trytimes:
            session.set_option('hls-segment-attempts', int(trytimes))
        session.set_option('hls-live-edge', 9999)
        session.set_option('hls-segment-timeout', 6.0)
        session.set_option('hls-timeout', 10.0)
        session.set_loglevel("none")
        #cmd = ['streamlink','hls://{}'.format(master),'best','-o','/root/te/t.ts']
        #subprocess.call(cmd)
        streams = session.streams('hlsvariant://' + master)
        stream = streams["best"]
        #print(stream.url)
        error = 0
        rstr = r"[\/\\\:\*\?\"\<\>\|\- \n]"
        oname = a.profile_data['name']
        otitle = a.channel_data['title']
        name = re.sub(rstr, "_", oname)
        title = re.sub(rstr, "_", otitle)
        path = '/root/b/d/fc2/' + str(a.user_id)
        if not os.path.exists(path):
            os.makedirs(path)
        userid = str(a.user_id)
        while (not error):
            if a.sameid == 0:
                break
            filename = path + '/' + userid + '-' + time.strftime(
                '%y%m%d_%H%M%S') + '-' + name + '-' + title + '.ts'
            if len(filename) >= 130:
                title = '_'
                filename = path + '/' + userid + '-' + time.strftime(
                    '%y%m%d_%H%M%S') + '-' + name + '-' + title + '.ts'
            fs = 0
            try:
                '''
                cmd = ['ffmpeg','-loglevel','quiet','-y','-i',master,'-c','copy','-fs','1073741824',filename]
                #cmd = ['ffmpeg','-y','-i',master,'-c','copy','-fs','1073741824',filename,'-loglevel','debug']
                error=subprocess.call(cmd)
                '''
                fd = stream.open()
                f = open(filename, 'wb')
                desize = 1024 * 1024 * 1024
                while 1:
                    ddata = fd.read(8192)
                    if ddata:
                        fs += f.write(ddata)
                        #if fs % 64 == 0:
                        #    sys.stdout.write(f'\r\033[K正在录制{len(recording)}{name}{userid}---{round(fs/1024/1024,2)}m')
                        if fs >= desize:
                            fs = 0
                            f.close()
                            print(f'\r\033[K{filename}文件大小达到限制,切割')
                            shutil.move(filename, '/root/b/d/fc2')
                            filename = path + '/' + userid + '-' + time.strftime(
                                '%y%m%d_%H%M%S'
                            ) + '-' + name + '-' + title + '.ts'
                            f = open(filename, 'wb')
                    else:
                        print(f'{userid}停止录制')
                        break

            except Exception as e:
                print(f'\r\033[K{a.user_id}', e)
                #traceback.print_exc()
            finally:
                if 'fd' in locals():
                    fd.close()
                if 'f' in locals():
                    f.close()
                    ff = os.path.getsize(filename)
                    if ff <= 1024 * 100:
                        print(f'\r\033[K{userid}文件下载失败')
                        #cmd = ['ffmpeg','-y','-i',master,'-c','copy','-fs','1073741824',filename,'-loglevel','debug']
                        #error=subprocess.call(cmd)

                    shutil.move(filename, '/root/b/d/fc2')
                os.rmdir(path)
                break
            #'''
            print(error)
            break
    a.end = True
    if a.user_id in recording:
        print(f'\r\033[K{a.user_id}从列表删除')
        recording.remove(a.user_id)
    else:
        print(f'\r\033[K{a.user_id}在列表中找不到{recording}')
    time.sleep(5)
    del a
class SaltyMainGUI:
	def __init__(self, master):
		self.master = master
		self.frame = tk.Frame(self.master)

		gobject.threads_init()
		gst.init(None)
		self.livestreamer = Livestreamer()
		self.livestreamer.set_loglevel("info")
		self.livestreamer.set_logoutput(sys.stdout)
		self.fd = None

		try:
			self.streams = self.livestreamer.streams('http://www.twitch.tv/saltybet')
		except NoPluginError:
			exit("Livestreamer failed to handle the url.")
		except PluginError as err:
			exit("Livestreamer plugin error: {}".format(err))

		if not self.streams:
			exit("No streams found.")

		if 'best' not in self.streams:
			exit("Unable to select livestreamer quality.")

		self.stream = self.streams['best']

		try:
			self.fd = self.stream.open()
		except SteamError as err:
			self.exit("Livestreamer failed to open stream.")

		self.init_gui()
		# self.login()

		self.window_id = self.video.winfo_id()

		self.player = gst.ElementFactory.make('playbin', None)
		self.player.set_property('video-sink', None)
		self.player.set_property('uri', 'appsrc://')

		self.player.connect('source-setup', self.on_source_setup)

		self.bus = self.player.get_bus()
		self.bus.add_signal_watch()
		self.bus.enable_sync_message_emission()
		self.bus.connect('sync-message::element', self.on_sync_message, self.window_id)
		self.bus.connect('message::eos', self.on_eos)
		self.bus.connect('message::error', self.on_error)

		self.player.set_state(gst.State.PLAYING)

	def init_gui(self):
		self.master.title('SaltyDoctor')

		self.master.geometry('640x480')

		self.video = tk.Frame(self.master, bg='black')
		self.video.pack(side=tk.TOP, anchor=tk.N, expand=tk.YES, fill=tk.BOTH)

		self.mute_btn = tk.Button(self.master, text='Mute', command=self.mute_stream)
		self.mute_btn.pack()

		self.frame.pack()

	def shutdown(self):
		self.player.set_state(gst.State.NULL)
		self.master.destroy()

	def mute_stream(self):
		if self.player.get_property('mute'):
			self.player.set_property('mute', False)
		else:
			self.player.set_property('mute', True)

	def login(self):
		self.login_window = tk.Toplevel(self.master)
		self.app = SaltyLoginGUI(self.login_window)

	def on_source_setup(self, element, source):
		# print 'Source setup called.'
		source.connect("need-data", self.on_source_need_data)

	def on_source_need_data(self, source, length):
		try:
			data = self.fd.read(length)
		except IOError as err:
			exit('Failed to read data from stream.')

		if not data:
			source.emit('end-of-stream')
			return

		buf = gst.Buffer.new_wrapped(data)
		source.emit('push-buffer', buf)

	def on_sync_message(self, bus, message, window_id):
		# print 'On sync message called: ' + message.get_structure().get_name()
		if not message.get_structure() is None:
			if message.get_structure().get_name() == 'prepare-window-handle':
				# print 'Setting window xid'
				image_sink = message.src 
				image_sink.set_property('force-aspect-ratio', True)
				image_sink.set_window_handle(self.window_id)
			if message.get_structure().get_name() == 'missing-plugin':
				print 'Gstreamer missing plugin: ' + gstpb.missing_plugin_message_get_description(message)

	def on_eos(self, bus, msg):
		self.stop()

	def on_error(self, bus, msg):
		error = msg.parse_error()[1]
		exit(error)