cli args and start stop streaming

This commit is contained in:
encrypt 2020-04-15 21:31:24 +02:00
parent 881905a4b3
commit f64b0e8b45

View file

@ -1,16 +1,40 @@
import pymumble_py3 as pymumble import pymumble_py3 as pymumble
from pymumble_py3.constants import *
import subprocess as sp import subprocess as sp
import time import time
import sys import sys
import os import os
import fcntl import fcntl
import audioop import audioop
import argparse
def message_received(message):
global is_streaming
if message == "/start":
is_streaming = True
elif message == "/stop":
is_streaming = False
parser = argparse.ArgumentParser(description='Regia pienamente automatizzata')
parser.add_argument('--channel', help='Set channel')
parser.add_argument('--name', help='Set bot nickname', default="RadioRobbot")
parser.add_argument('--server', help='Set server', default="mumble.esiliati.org")
parser.add_argument('--port', help='Set port', type=int)
parser.add_argument('--stream', action='store_true', help='Ignore commands in chat and stream everything')
sys.argv.pop(0)
args = parser.parse_args(sys.argv)
pwd = "" # password pwd = "" # password
server = "mumble.esiliati.org" # server address server = args.server
nick = "TubiaBot" nick = args.name
channel = "radiospore" channel = args.channel
port = 64738 # port number port = args.port
is_streaming=False
stream_always= args.stream
mumble.callbacks.set_callback(PYMUMBLE_CLBK_TEXTMESSAGERECEIVED, message_received)
# Spin up a client and connect to mumble server # Spin up a client and connect to mumble server
mumble = pymumble.Mumble(server, nick, password=pwd, port=port) mumble = pymumble.Mumble(server, nick, password=pwd, port=port)
@ -46,12 +70,13 @@ while mumble.is_alive():
else: else:
base_sound = audioop.add(base_sound, stereo_pcm, 2) base_sound = audioop.add(base_sound, stereo_pcm, 2)
except RuntimeError: except RuntimeError:
eprint("ignored exception in stderr...") print("ignored exception in stderr...", file=sys.stderr)
if base_sound: if is_streaming or stream_always:
sys.stdout.buffer.write(base_sound) if base_sound:
else: sys.stdout.buffer.write(base_sound)
sys.stdout.buffer.write(silent) else:
sys.stdout.buffer.write(silent)
cursor_time += FLOAT_RESOLUTION cursor_time += FLOAT_RESOLUTION
else: else: