diff --git a/README.md b/README.md index acc5712..09df9c2 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,13 @@ 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 `stream.py` so it points to your Mastodon instance. +Edit `API_BASE_URL` at the top of `fediplay.py` so it points to your Mastodon instance. -Use `pipenv install --dev` from [Pipenv](https://docs.pipenv.org/) to install the Python dependencies and set up the package with a `stream` executable. +Use `pipenv install` from [Pipenv](https://docs.pipenv.org/) to install the Python dependencies. ## Streaming -Use `pipenv run stream` to start the stream. You'll need to log in the first time. +Use `pipenv run python -m fediplay` to start the stream. You'll need to log in the first time. Toots that include the hashtag #fediplay and have as their first link something that [youtube-dl](https://rg3.github.io/youtube-dl/) can play, will! diff --git a/fediplay.py b/fediplay.py index 9a4c708..e793b5c 100644 --- a/fediplay.py +++ b/fediplay.py @@ -1,3 +1,5 @@ +API_BASE_URL = 'https://cybre.space' + from subprocess import run from threading import Thread, Lock @@ -26,6 +28,7 @@ class Queue(object): def run_thread(filename, cb_complete): print('==> Playing', filename) run(['ffplay', '-v', '0', '-nostats', '-hide_banner', '-autoexit', '-nodisp', filename]) + print('==> Playback complete') cb_complete() thread = Thread(target=run_thread, args=(filename, cb_complete)) @@ -90,3 +93,21 @@ def extract_links(toot): all_links = html.cssselect('a') 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 + + if not os.path.exists('clientcred.secret'): + print('==> No clientcred.secret; registering application') + register(API_BASE_URL) + + if not os.path.exists('usercred.secret'): + print('==> No usercred.secret; logging in') + email = input('Email: ') + password = getpass('Password: ') + login(API_BASE_URL, email, password) + + stream(API_BASE_URL) + +if __name__ == '__main__': + main() diff --git a/setup.py b/setup.py index ebdf0f5..27233da 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ setup( ], entry_points={ 'console_scripts': [ - 'stream = stream:run' + 'fediplay = fediplay:main' ] } ) diff --git a/stream.py b/stream.py deleted file mode 100755 index 98cd935..0000000 --- a/stream.py +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python - -API_BASE_URL = 'https://cybre.space' - -import os -from getpass import getpass - -from fediplay import register, login, stream - -if not os.path.exists('clientcred.secret'): - register(API_BASE_URL) - -if not os.path.exists('usercred.secret'): - email = input('Email: ') - password = getpass('Password: ') - login(API_BASE_URL, email, password) - -def run(): - stream(API_BASE_URL) -