mirror of
https://github.com/nova-r/fediplug.git
synced 2025-03-24 06:04:55 +01:00
configurable play command
This commit is contained in:
parent
8e451e9d62
commit
1be7fa4454
3 changed files with 27 additions and 2 deletions
4
.env
4
.env
|
@ -1,2 +1,4 @@
|
||||||
FEDIPLAY_API_BASE_URL=https://cybre.space
|
FEDIPLAY_API_BASE_URL="https://cybre.space"
|
||||||
#FEDIPLAY_NO_CHECK_CERTIFICATE=1
|
#FEDIPLAY_NO_CHECK_CERTIFICATE=1
|
||||||
|
FEDIPLAY_PLAY_COMMAND="ffplay -v 0 -nostats -hide_banner -autoexit -nodisp {filename}"
|
||||||
|
#FEDIPLAY_PLAY_COMMAND="afplay {filename}"
|
13
fediplay.py
13
fediplay.py
|
@ -1,4 +1,5 @@
|
||||||
from os import environ, umask
|
from os import environ, umask
|
||||||
|
import shlex
|
||||||
from subprocess import run
|
from subprocess import run
|
||||||
from threading import Thread, Lock
|
from threading import Thread, Lock
|
||||||
|
|
||||||
|
@ -26,7 +27,9 @@ class Queue(object):
|
||||||
|
|
||||||
def run_thread(filename, cb_complete):
|
def run_thread(filename, cb_complete):
|
||||||
print('==> Playing', filename)
|
print('==> Playing', filename)
|
||||||
run(['ffplay', '-v', '0', '-nostats', '-hide_banner', '-autoexit', '-nodisp', filename])
|
play_command = build_play_command(filename)
|
||||||
|
print('[executing]', play_command)
|
||||||
|
run(play_command, shell=True)
|
||||||
print('==> Playback complete')
|
print('==> Playback complete')
|
||||||
cb_complete()
|
cb_complete()
|
||||||
|
|
||||||
|
@ -97,6 +100,14 @@ def extract_links(toot):
|
||||||
all_links = html.cssselect('a')
|
all_links = html.cssselect('a')
|
||||||
return [link.attrib['href'] for link in all_links if not link_is_internal(link)]
|
return [link.attrib['href'] for link in all_links if not link_is_internal(link)]
|
||||||
|
|
||||||
|
def build_play_command(filename):
|
||||||
|
escaped_filename = shlex.quote(filename)
|
||||||
|
template = environ.get(
|
||||||
|
'FEDIPLAY_PLAY_COMMAND',
|
||||||
|
'ffplay -v 0 -nostats -hide_banner -autoexit -nodisp {filename}'
|
||||||
|
)
|
||||||
|
return template.format(filename=escaped_filename)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
from getpass import getpass
|
from getpass import getpass
|
||||||
from os import path
|
from os import path
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
from os import environ
|
||||||
|
|
||||||
import fediplay
|
import fediplay
|
||||||
|
|
||||||
def test_extract_links():
|
def test_extract_links():
|
||||||
|
@ -6,3 +8,13 @@ def test_extract_links():
|
||||||
}
|
}
|
||||||
urls = fediplay.extract_links(toot)
|
urls = fediplay.extract_links(toot)
|
||||||
assert urls == ['https://www.youtube.com/watch?v=eTLTXDHrgtw']
|
assert urls == ['https://www.youtube.com/watch?v=eTLTXDHrgtw']
|
||||||
|
|
||||||
|
def test_build_play_command_default():
|
||||||
|
environ.pop('FEDIPLAY_PLAY_COMMAND')
|
||||||
|
play_command = fediplay.build_play_command('Awesome Music.mp3')
|
||||||
|
assert play_command == 'ffplay -v 0 -nostats -hide_banner -autoexit -nodisp \'Awesome Music.mp3\''
|
||||||
|
|
||||||
|
def test_build_play_command_specified():
|
||||||
|
environ.update(FEDIPLAY_PLAY_COMMAND='afplay {filename}')
|
||||||
|
play_command = fediplay.build_play_command('Awesome Music.mp3')
|
||||||
|
assert play_command == 'afplay \'Awesome Music.mp3\''
|
||||||
|
|
Loading…
Add table
Reference in a new issue