From 339256ff67723822ec5a9ee9739a4828e4bedf11 Mon Sep 17 00:00:00 2001 From: pbsds Date: Mon, 12 Sep 2016 02:12:11 +0200 Subject: [PATCH] Introduced the mainfunction and configfile, and added the parameter --no-mpv --- .gitignore | 2 ++ default_config.ini | 5 +++++ server.py | 38 +++++++++++++++++++++++++++++++------- 3 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 default_config.ini diff --git a/.gitignore b/.gitignore index 0d20b64..1ff648e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ *.pyc +__pycache__ +config.ini diff --git a/default_config.ini b/default_config.ini new file mode 100644 index 0000000..ccecbce --- /dev/null +++ b/default_config.ini @@ -0,0 +1,5 @@ +[server] +host=127.0.0.1 +port=8081 +start_browser=True +multiple_instance=True \ No newline at end of file diff --git a/server.py b/server.py index 5c9205f..02ca2e2 100644 --- a/server.py +++ b/server.py @@ -1,8 +1,13 @@ #!/usr/bin/env python3 -import remi.gui as gui, random, os, time +import remi.gui as gui, random, os, time, shutil, sys from remi import start, App from threading import Timer -from mpv_control import mpv +if sys.version_info[0] == 2: + from ConfigParser import ConfigParser +else: + from configparser import ConfigParser +if "--no-mpv" not in sys.argv: + from mpv_control import mpv class namespace(object): pass @@ -15,6 +20,8 @@ class MyApp(App): res_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'res') super(MyApp, self).__init__(*args, static_paths=(res_path,)) + #initalize mpv here? + def main(self): container = gui.VBox(width=512) @@ -79,11 +86,28 @@ class MyApp(App): def input_submit(self, value=None): if not value: value = self.input.field.get_text() - - print(value) - mpv.play(value) self.input.field.set_text("") + if mpv.play(value): + pass + -# starts the webserver -start(MyApp, address="0.0.0.0", start_browser=False, multiple_instance=True) + +def main(): + if not os.path.exists("config.ini"): + shutil.copyfile("default_config.ini", "config.ini") + + ini = ConfigParser() + with open("config.ini", "r") as f: + ini.readfp(f) + + host = ini.get("server", "host") + port = ini.getint("server", "port") + start_browser = ini.getboolean("server", "start_browser") + multiple_instance = ini.getboolean("server", "multiple_instance") + + # starts the webserver + start(MyApp, address=host, port=port, start_browser=start_browser, multiple_instance=multiple_instance) + +if __name__ == "__main__": + main() \ No newline at end of file