aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/livestreamer/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/livestreamer/__init__.py')
-rw-r--r--src/livestreamer/__init__.py94
1 files changed, 74 insertions, 20 deletions
diff --git a/src/livestreamer/__init__.py b/src/livestreamer/__init__.py
index f8a4fa2..f554fb6 100644
--- a/src/livestreamer/__init__.py
+++ b/src/livestreamer/__init__.py
@@ -1,29 +1,83 @@
-from . import plugins, stream
+from . import plugins
from .compat import urlparse
+from .logger import Logger
+from .options import Options
+from .plugins import PluginError, NoStreamsError, NoPluginError
+from .stream import StreamError
-def resolve_url(url):
- parsed = urlparse(url)
+import pkgutil
+import imp
- if len(parsed.scheme) == 0:
- url = "http://" + url
+class Livestreamer(object):
+ def __init__(self):
+ self.options = Options({
+ "rtmpdump": None,
+ "errorlog": False
+ })
+ self.plugins = {}
+ self.logger = Logger()
+ self.load_builtin_plugins()
- for name, plugin in plugins.get_plugins().items():
- if plugin.can_handle_url(url):
- obj = plugin(url)
- return obj
+ def set_option(self, key, value):
+ self.options.set(key, value)
- raise plugins.NoPluginError()
+ def get_option(self, key):
+ return self.options.get(key)
-def get_plugins():
- return plugins.get_plugins()
+ def set_plugin_option(self, plugin, key, value):
+ if plugin in self.plugins:
+ plugin = self.plugins[plugin]
+ plugin.set_option(key, value)
-PluginError = plugins.PluginError
-NoStreamsError = plugins.NoStreamsError
-NoPluginError = plugins.NoPluginError
-StreamError = stream.StreamError
+ def get_plugin_option(self, plugin, key):
+ if plugin in self.plugins:
+ plugin = self.plugins[plugin]
+ return plugin.get_option(key)
-plugins.load_plugins(plugins)
+ def set_loglevel(self, level):
+ self.logger.set_level(level)
-__all__ = ["resolve_url", "get_plugins",
- "PluginError", "NoStreamsError", "NoPluginError",
- "StreamError"]
+ def set_logoutput(self, output):
+ self.logger.set_output(output)
+
+ def resolve_url(self, url):
+ parsed = urlparse(url)
+
+ if len(parsed.scheme) == 0:
+ url = "http://" + url
+
+ for name, plugin in self.plugins.items():
+ if plugin.can_handle_url(url):
+ obj = plugin(url)
+ return obj
+
+ raise NoPluginError
+
+ def get_plugins(self):
+ return self.plugins
+
+ def load_builtin_plugins(self):
+ for loader, name, ispkg in pkgutil.iter_modules(plugins.__path__):
+ file, pathname, desc = imp.find_module(name, plugins.__path__)
+ self.load_plugin(name, file, pathname, desc)
+
+ def load_plugins(self, path):
+ for loader, name, ispkg in pkgutil.iter_modules(path):
+ file, pathname, desc = imp.find_module(name, path)
+ self.load_plugin(name, file, pathname, desc)
+
+ def load_plugin(self, name, file, pathname, desc):
+ module = imp.load_module(name, file, pathname, desc)
+
+ plugin = module.__plugin__
+ plugin.module = module.__name__
+ plugin.session = self
+
+ self.plugins[module.__name__] = plugin
+
+ if file:
+ file.close()
+
+
+__all__ = ["PluginError", "NoStreamsError", "NoPluginError", "StreamError",
+ "Livestreamer"]