当前位置: 首页>>代码示例>>Python>>正文


Python Livestreamer.set_option方法代码示例

本文整理汇总了Python中livestreamer.Livestreamer.set_option方法的典型用法代码示例。如果您正苦于以下问题:Python Livestreamer.set_option方法的具体用法?Python Livestreamer.set_option怎么用?Python Livestreamer.set_option使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在livestreamer.Livestreamer的用法示例。


在下文中一共展示了Livestreamer.set_option方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: serveFile

# 需要导入模块: from livestreamer import Livestreamer [as 别名]
# 或者: from livestreamer.Livestreamer import set_option [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:
开发者ID:msousinha,项目名称:myhome-repository,代码行数:15,代码来源:livestreamerXBMCLocalProxy.py

示例2: TestSession

# 需要导入模块: from livestreamer import Livestreamer [as 别名]
# 或者: from livestreamer.Livestreamer import set_option [as 别名]
class TestSession(unittest.TestCase):
    PluginPath = os.path.join(os.path.dirname(__file__), "plugins")

    def setUp(self):
        self.session = Livestreamer()
        self.session.load_plugins(self.PluginPath)

    def test_exceptions(self):
        try:
            self.session.resolve_url("invalid url")
            self.assertTrue(False)
        except NoPluginError:
            self.assertTrue(True)

    def test_load_plugins(self):
        plugins = self.session.get_plugins()
        self.assertTrue(plugins["testplugin"])

    def test_builtin_plugins(self):
        plugins = self.session.get_plugins()
        self.assertTrue("justintv" in plugins)

    def test_resolve_url(self):
        plugins = self.session.get_plugins()
        channel = self.session.resolve_url("http://test.se/channel")
        self.assertTrue(isinstance(channel, Plugin))
        self.assertTrue(isinstance(channel, plugins["testplugin"]))

    def test_options(self):
        self.session.set_option("test_option", "option")
        self.assertEqual(self.session.get_option("test_option"), "option")
        self.assertEqual(self.session.get_option("non_existing"), None)

        self.assertEqual(self.session.get_plugin_option("testplugin", "a_option"), "default")
        self.session.set_plugin_option("testplugin", "another_option", "test")
        self.assertEqual(self.session.get_plugin_option("testplugin", "another_option"), "test")
        self.assertEqual(self.session.get_plugin_option("non_existing", "non_existing"), None)
        self.assertEqual(self.session.get_plugin_option("testplugin", "non_existing"), None)

    def test_plugin(self):
        channel = self.session.resolve_url("http://test.se/channel")
        streams = channel.get_streams()

        self.assertTrue("best" in streams)
        self.assertTrue(streams["best"] is streams["1080p"])
        self.assertTrue(isinstance(streams["rtmp"], RTMPStream))
        self.assertTrue(isinstance(streams["http"], HTTPStream))
        self.assertTrue(isinstance(streams["hls"], HLSStream))
        self.assertTrue(isinstance(streams["akamaihd"], AkamaiHDStream))
开发者ID:buttsKramer,项目名称:livestreamer,代码行数:51,代码来源:test_session.py

示例3: serveFile

# 需要导入模块: from livestreamer import Livestreamer [as 别名]
# 或者: from livestreamer.Livestreamer import set_option [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()
开发者ID:EPiC-APOC,项目名称:repository.xvbmc,代码行数:49,代码来源:livestreamerXBMCLocalProxy.py

示例4: start

# 需要导入模块: from livestreamer import Livestreamer [as 别名]
# 或者: from livestreamer.Livestreamer import set_option [as 别名]
def start(portNum):
	global LIVESTREAMER
	LIVESTREAMER = Livestreamer()
	LIVESTREAMER.set_option('hls-segment-threads', '3')
	LIVESTREAMER.set_option('hds-segment-threads', '3')
	LIVESTREAMER.set_option('stream-segment-threads', '3')

	global httpd
	#httpd = ThreadedHTTPServer(('', portNum), StreamHandler)
	httpd = StoppableHTTPServer(('', portNum), StreamHandler)
	try:
		#thread.start_new_thread(httpd.serve, ())
		t1 = threading.Thread(target = httpd.serve, args = ())
		t1.daemon = True
		t1.start()
		print "Livestreamer: Server Starts - {0}:{1}".format("localhost", portNum)
	except Exception as ex:
		print ex
开发者ID:orenma,项目名称:xbmc-israel,代码行数:20,代码来源:livestreamersrv.py

示例5: get_streams

# 需要导入模块: from livestreamer import Livestreamer [as 别名]
# 或者: from livestreamer.Livestreamer import set_option [as 别名]
    def get_streams(self):
        live = Livestreamer()
        print self.url
        live.set_option("http-ssl-verify", False)


        streams = None

        live.load_plugins(os.path.join(os.getcwd(), "plugins"))
        try:
            plugin = live.resolve_url(self.url)
            streams = plugin.get_streams()

            self.play_url = stream_to_url(streams.get("best"))
        except NoPluginError:
            print("No plugin can handle URL")
        except PluginError as err:
            print("{0}", err)
开发者ID:AnteWall,项目名称:Twitcherino,代码行数:20,代码来源:TwitchPlayer.py

示例6: serveFile

# 需要导入模块: from livestreamer import Livestreamer [as 别名]
# 或者: from livestreamer.Livestreamer import set_option [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()
开发者ID:msousinha,项目名称:myhome-repository,代码行数:46,代码来源:livestreamerXBMCLocalProxy.py

示例7: serveFile

# 需要导入模块: from livestreamer import Livestreamer [as 别名]
# 或者: from livestreamer.Livestreamer import set_option [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)
开发者ID:igor-rangel7l,项目名称:igorrangel.repository,代码行数:24,代码来源:livestreamerXBMCLocalProxy.py

示例8: TestSession

# 需要导入模块: from livestreamer import Livestreamer [as 别名]
# 或者: from livestreamer.Livestreamer import set_option [as 别名]
class TestSession(unittest.TestCase):
    PluginPath = os.path.join(os.path.dirname(__file__), "plugins")

    def setUp(self):
        self.session = Livestreamer()
        self.session.load_plugins(self.PluginPath)

    def test_exceptions(self):
        try:
            self.session.resolve_url("invalid url")
            self.assertTrue(False)
        except NoPluginError:
            self.assertTrue(True)

    def test_load_plugins(self):
        plugins = self.session.get_plugins()
        self.assertTrue(plugins["testplugin"])

    def test_builtin_plugins(self):
        plugins = self.session.get_plugins()
        self.assertTrue("twitch" in plugins)

    def test_resolve_url(self):
        plugins = self.session.get_plugins()
        channel = self.session.resolve_url("http://test.se/channel")
        self.assertTrue(isinstance(channel, Plugin))
        self.assertTrue(isinstance(channel, plugins["testplugin"]))

    def test_options(self):
        self.session.set_option("test_option", "option")
        self.assertEqual(self.session.get_option("test_option"), "option")
        self.assertEqual(self.session.get_option("non_existing"), None)

        self.assertEqual(self.session.get_plugin_option("testplugin", "a_option"), "default")
        self.session.set_plugin_option("testplugin", "another_option", "test")
        self.assertEqual(self.session.get_plugin_option("testplugin", "another_option"), "test")
        self.assertEqual(self.session.get_plugin_option("non_existing", "non_existing"), None)
        self.assertEqual(self.session.get_plugin_option("testplugin", "non_existing"), None)

    def test_plugin(self):
        channel = self.session.resolve_url("http://test.se/channel")
        streams = channel.get_streams()

        self.assertTrue("best" in streams)
        self.assertTrue("worst" in streams)
        self.assertTrue(streams["best"] is streams["1080p"])
        self.assertTrue(streams["worst"] is streams["350k"])
        self.assertTrue(isinstance(streams["rtmp"], RTMPStream))
        self.assertTrue(isinstance(streams["http"], HTTPStream))
        self.assertTrue(isinstance(streams["hls"], HLSStream))
        self.assertTrue(isinstance(streams["akamaihd"], AkamaiHDStream))

    def test_plugin_stream_types(self):
        channel = self.session.resolve_url("http://test.se/channel")
        streams = channel.get_streams(stream_types=["http", "rtmp"])

        self.assertTrue(isinstance(streams["480p"], HTTPStream))
        self.assertTrue(isinstance(streams["480p_rtmp"], RTMPStream))

        streams = channel.get_streams(stream_types=["rtmp", "http"])

        self.assertTrue(isinstance(streams["480p"], RTMPStream))
        self.assertTrue(isinstance(streams["480p_http"], HTTPStream))

    def test_plugin_stream_sorted_excludes(self):
        channel = self.session.resolve_url("http://test.se/channel")
        streams = channel.get_streams(sorting_excludes=["1080p", "3000k"])

        self.assertTrue("best" in streams)
        self.assertTrue("worst" in streams)
        self.assertTrue(streams["best"] is streams["1500k"])

        streams = channel.get_streams(sorting_excludes=[">=1080p", ">1500k"])
        self.assertTrue(streams["best"] is streams["1500k"])

        streams = channel.get_streams(sorting_excludes=lambda q: not q.endswith("p"))
        self.assertTrue(streams["best"] is streams["3000k"])

    def test_plugin_support(self):
        channel = self.session.resolve_url("http://test.se/channel")
        streams = channel.get_streams()

        self.assertTrue("support" in streams)
        self.assertTrue(isinstance(streams["support"], HTTPStream))
开发者ID:492580195,项目名称:livestreamer,代码行数:86,代码来源:test_session.py

示例9: LivestreamerDumper

# 需要导入模块: from livestreamer import Livestreamer [as 别名]
# 或者: from livestreamer.Livestreamer import set_option [as 别名]
class LivestreamerDumper(object):
    "Main class for dumping streams"

    def __init__(self, config_path):
        """LivestreamerDumper constructor

        Parameters:
        config_path: path to user config directory
        """
        self.fd = None
        self.config_path = config_path

    def open(self, url, quality):
        """Attempt to open stream from *url*.

        Exits with '-1' (using self.exit()) in case of error, including
        an error msg.
        """

        self.original_url = url
        try:
            self.livestreamer = Livestreamer()
            self._load_config()
            streams = self.livestreamer.streams(url)
        except NoPluginError:
            self.exit("Livestreamer is unable to handle the URL '{}'".
                      format(url))
        except PluginError as err:
            self.exit("Plugin error: {}".format(err))

        if quality not in streams:
            print("Unable to find '{}' stream on URL '{}'"
                  .format(quality, url), file=sys.stderr)
            self.exit("List of available streams: {}".
                      format(sorted(streams.keys())))

        self.stream = streams[quality]
        try:
            self.fd = self.stream.open()
        except StreamError as err:
            self.exit("Failed to open stream: {}".format(err))

    def _load_config(self):
        "Load and parse config file, pass options to livestreamer"
        
        config = SafeConfigParser()
        config_file = os.path.join(self.config_path, 'settings.ini')
        config.read(config_file)

        for option, type in list(AVAILABLE_OPTIONS.items()):
            if config.has_option('DEFAULT', option):
                if type == 'int':
                    value = config.getint('DEFAULT', option)
                if type == 'float':
                    value = config.getfloat('DEFAULT', option)
                if type == 'bool':
                    value = config.getboolean('DEFAULT', option)
                if type == 'str':
                    value = config.get('DEFAULT', option)

                self.livestreamer.set_option(option, value)


    def get_title(self):
        """Returns the filename from URL (including extension), that
        may be:

        https://www.youtube.com/watch?v=ZEtEH-GIAJE ->
        '[Hatsune Miku] After Rain Sweet*Drops [English Sub] -
        YouTube.mp4'

        https://www.youtube.com/watch?v=ZEtEH-GIAJE ->
        'watch_v=ZEtEH-GIAJE.mp4'

        The former case occurs when URL is a web page with <title> tags.
        The last case will occur in pages with malformed HTML or when
        you pass a non-HTML URL as a parameter (for example, a link to
        a direct HTML5 video).

        The extension will be detected according to the stream type,
        for example RTMPStream will always be '.flv'. The only format
        that may returns a wrong extension is HTTPStream, since there
        is no standard container in this case. We assume (for now) that
        every HTTPStream is '.mp4'.
        """

        stream_type = self.stream.__class__.__name__
        try:
            extension = VIDEO_EXTENSIONS[stream_type]
        except KeyError:
            print('No extension found...', file=sys.stderr)
            extension = ''

        r = requests.get(self.original_url)
        regex_result = _RE_PAGE_TITLE.search(r.text)
        
        if regex_result is not None:
          filename = regex_result.group(1)

        # Badly formatted HTML (e.g. no '<title>')
#.........这里部分代码省略.........
开发者ID:dot-Sean,项目名称:livedumper,代码行数:103,代码来源:dumper.py


注:本文中的livestreamer.Livestreamer.set_option方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。