diff --git a/.env b/.env new file mode 100644 index 0000000..7f22c38 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +FEDIPLAY_API_BASE_URL=https://cybre.space diff --git a/README.md b/README.md index 09df9c2..e9df900 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A Mastodon client that automatically plays your friends' music as they toot link You'll need `ffplay` from [FFmpeg](https://ffmpeg.org/) to actually play music. On macOS, `ffplay` is part of the Homebrew ffmpeg package, but you need to build it with `brew install ffmpeg --with-sdl2`. -Edit `API_BASE_URL` at the top of `fediplay.py` so it points to your Mastodon instance. +Edit `.env` and set `FEDIPLAY_API_BASE_URL` to your Mastodon instance. Use `pipenv install` from [Pipenv](https://docs.pipenv.org/) to install the Python dependencies. diff --git a/fediplay.py b/fediplay.py index e793b5c..a5bca3f 100644 --- a/fediplay.py +++ b/fediplay.py @@ -1,5 +1,3 @@ -API_BASE_URL = 'https://cybre.space' - from subprocess import run from threading import Thread, Lock @@ -94,20 +92,26 @@ def extract_links(toot): return [link.attrib['href'] for link in all_links if not has_external_link_class(link.attrib.get('class', ''))] def main(): - import os from getpass import getpass + from os import environ, path + from sys import exit - if not os.path.exists('clientcred.secret'): + api_base_url = environ.get('FEDIPLAY_API_BASE_URL') + if not api_base_url: + print('FEDIPLAY_API_BASE_URL environment variable not set') + exit(1) + + if not path.exists('clientcred.secret'): print('==> No clientcred.secret; registering application') - register(API_BASE_URL) + register(api_base_url) - if not os.path.exists('usercred.secret'): + if not path.exists('usercred.secret'): print('==> No usercred.secret; logging in') email = input('Email: ') password = getpass('Password: ') - login(API_BASE_URL, email, password) + login(api_base_url, email, password) - stream(API_BASE_URL) + stream(api_base_url) if __name__ == '__main__': main()