diff --git a/README.md b/README.md new file mode 100644 index 0000000..2c5e4c8 --- /dev/null +++ b/README.md @@ -0,0 +1,45 @@ +# Grzegorz API + + +Grzegorz is simple REST API for managing an instance of MPV. + +Why the name Grzegorz? [We have a bad tast in humor!](https://youtu.be/t-fcrn1Edik) + +When Grzegorz starts, it launches an instance of MPV and maintains it. It is designed to be used as an infoscreen or HTPC, and supports multiple users to push changes to the MPV instance. + +The API id described and can be tested on `http:/localhost:8080/swagger` when the server is running. All API endpoints are available under `/api` + + +## How to run it + +First of we need to install any needed dependencies. If you want to, you may do so in a virtual environment. + +To install the needed dependencies, run this with sufficient rights (as root?): + +``` +pip install -r requirements.txt +``` + +Gregorz managesa MPV process, meaning you need MPV installed on your system. Look for it in your package manager. + +When finished, you may run the server with: + +``` +python3 main.py +``` + +The server should now be available at `http://localhost:8080/`. +You may change the address and port in the file named `config.py` + + +## Making Grzegorz run on boot + +When setting up a infoscreen or HTPC using Grzegors, you may configure it to run automatically on startup. + +We recommend installing a headless linux, and create a user for Grzegorz to run as. (We named ours `grzegorz`, obviously) +Then make systemd automatically spin up a X session to run Grzegorz in: Copy the files in the folder `dist` into `$HOME/.config/systemd/user` and run the following commands as your user: + +``` +$ systemd --user enable grzegorz@0.service +$ systemd --user start grzegorz@0.service +``` diff --git a/config.py b/config.py new file mode 100644 index 0000000..671a164 --- /dev/null +++ b/config.py @@ -0,0 +1,5 @@ +# network interface ip +address = "0.0.0.0" + +# http listen port +port = 8080 diff --git a/dist/grzegorz@.service b/dist/grzegorz@.service new file mode 100644 index 0000000..3d97920 --- /dev/null +++ b/dist/grzegorz@.service @@ -0,0 +1,14 @@ +[Unit] +Description=Grzegorz at display %i + +Requires=xorg@%i.socket +Requires=xorg@%i.service +After=xorg@%i.socket +After=xorg@%i.service + +[Service] +Environment="DISPLAY=:%i" +ExecStart=/usr/bin/python grzegorz/main.py + +[Install] +WantedBy=default.target diff --git a/dist/xorg@.service b/dist/xorg@.service new file mode 100644 index 0000000..d7c3e22 --- /dev/null +++ b/dist/xorg@.service @@ -0,0 +1,8 @@ +[Unit] +Description=Socket for xorg at display %i + +[Socket] +ListenStream=/tmp/.X11-unix/X%i + +[Install] +WantedBy=sockets.target diff --git a/dist/xorg@.socket b/dist/xorg@.socket new file mode 100644 index 0000000..d7c3e22 --- /dev/null +++ b/dist/xorg@.socket @@ -0,0 +1,8 @@ +[Unit] +Description=Socket for xorg at display %i + +[Socket] +ListenStream=/tmp/.X11-unix/X%i + +[Install] +WantedBy=sockets.target diff --git a/main.py b/main.py index 33007a8..4270d27 100755 --- a/main.py +++ b/main.py @@ -1,11 +1,15 @@ #!/usr/bin/env python3 import asyncio import grzegorz +import config async def grzegorz_splash(): resp = await grzegorz.mpv_control.loadfile('grzegorz/grzegorz/res/logo.jpg') #print(resp) -loop, app = grzegorz.make_sanic_app() +loop, app = grzegorz.make_sanic_app( + host = config.address, + port = config.port +) asyncio.ensure_future(grzegorz_splash()) loop.run_forever() diff --git a/res/logo.png b/res/logo.png new file mode 100644 index 0000000..e9ba611 Binary files /dev/null and b/res/logo.png differ