Commit 633da7f1 authored by Gottfried Gaisbauer's avatar Gottfried Gaisbauer
Browse files

code quality enhanced, timer management improved, started to implement methods...

code quality enhanced, timer management improved, started to implement methods for manual playlist editing
parent 3bf43f00
This diff is collapsed.
......@@ -50,5 +50,8 @@ The heart of AURA Engine. It uses the built in mixer, to switch between differen
### Hardware
#### Soundcard
AURA Engine ist tested with an ASUS Xonar DGX. It should work with every by ALSA supported soundcard. PulseAudio support is planned.
#### Hard/Soft
When you use ALSA, you will have to play around with ALSA settings. In the folder ./modules/liquidsoap is a scipt called alsa_settings_tester.liq. You can start it with 'liquidsoap -v --debug alsa_settings_tester.liq'. Changing and playing with settings can help you to find correct ALSA settings.
\ No newline at end of file
......@@ -15,6 +15,7 @@ class Aura():
messenger = None
controller = None
# ------------------------------------------------------------------------------------------ #
def __init__(self):
self.config = ConfigReader()
self.config.loadConfig()
......
#!/usr/bin/python3
import time
import sys
import redis
from argparse import ArgumentParser
......@@ -14,6 +15,7 @@ class Guru:
config = ConfigReader()
config.loadConfig()
# ------------------------------------------------------------------------------------------ #
def __init__(self):
try:
parser = ArgumentParser()
......@@ -25,6 +27,8 @@ class Guru:
# options
parser.add_argument("-sep", "--stop-execution-time", action="store_true", dest="stoptime", default=False,
help="Prints the execution time at the end of the skript")
parser.add_argument("-q", "--quiet", action="store_true", dest="quiet", default=False,
help="Just the result will outputed to stout")
# getter
parser.add_argument("-gam", "--get-active-mixer", action="store_true", dest="get_active_mixer", default=False,
......@@ -34,7 +38,7 @@ class Guru:
parser.add_argument("-pap", "--print-act-programme", action="store_true", dest="get_act_programme", default=False,
help="Prints the actual Programme, the controller holds")
# manipulation
# liquid manipulation
parser.add_argument("-am", "--select-mixer", action="store", dest="select_mixer", default=-1, metavar="MIXERNUM",
help="Which mixer should be activated?", type=int)
......@@ -44,19 +48,29 @@ class Guru:
parser.add_argument("-vm", "--volume", action="store", dest="set_volume", default=0, metavar=("MIXERNUM","VOLUME"), nargs=2,
help="Set volume of a mixer source", type=int)
parser.add_argument("-as", "--add-source", action="store", dest="add_source", default=False,
help="Add new source to LiquidSoap mixer [Experimental]")
#parser.add_argument("-as", "--add-source", action="store", dest="add_source", default=False,
# help="Add new source to LiquidSoap mixer [Experimental]")
# redis comm. test
# playlist manipulation
parser.add_argument("-mpe", "--move-playlist-entry", action="store", dest="move_playlist_entry", default=0, metavar=("FROM", "TO"), nargs=2,
help="Move Playlistentry FROM index TO another index")
parser.add_argument("-dpe", "--delete-playlist-entry", action="store", dest="delete_playlist_entry", default=0, metavar=("INDEX"),
help="Delete Playlistentry at INDEX")
parser.add_argument("-ape", "--add-playlist-entry", action="store", dest="add_playlist_entry", default=0, metavar=("INDEX", "FROMTIME", "SOURCE"), nargs=3,
help="Add a new Playlistentry at a given index", type=valid_playlist_entry)
parser.add_argument("-pmq", "--print-message-queue", action="store_true", dest="print_message_queue", default=False,
help="Prints message queue")
# send a redis message
parser.add_argument("-rm", "--redis-message", action="store", dest="redis_message", default=False, metavar=("CHANNEL", "MESSAGE"), nargs=2,
help="Send a redis message to the Listeners")
# calls from liquidsoap
parser.add_argument("-gnf", "--get-next-fallback-file-for", action="store", dest="get_fallback_for", default=False, metavar=("FALLBACKTYPE"),
parser.add_argument("-gnf", "--get-next-fallback-file-for", action="store", dest="get_fallback_for", default=False, metavar="FALLBACKTYPE",
help="For which type you wanna GET a next audio file?")
parser.add_argument("-snf", "--set-next-fallback-file-for", action="store", dest="set_fallback_for", default=False, metavar=("FALLBACKTYPE", "FILE"), nargs=2,
help="For which type you wanna SET a next audio file?")
parser.add_argument("-ls", "--liquid-startup", action="store_true", dest="liquid_startup", default=False,
parser.add_argument("-ip", "--init-player", action="store_true", dest="init_player", default=False,
help="Reset liquidsoap volume and mixer activations?")
args = parser.parse_args()
......@@ -64,33 +78,62 @@ class Guru:
if len(sys.argv) == 1:
raise ValueError("No Argument passed!")
except ValueError:
except ValueError as e:
parser.print_help()
print()
print(e)
exit(1)
except TypeError:
except TypeError as e:
parser.print_help()
print()
print(e)
exit(2)
except:
exit(3)
if args.stoptime:
start = time.time()
print("Guru thinking...")
if not args.quiet:
print("Guru thinking...")
try:
p = Padavan(args, self.config)
p.meditate()
except FallbackException as fe:
print(fe)
exit(4)
except redis.exceptions.TimeoutError as te:
print(te)
print("Timeout when waiting for redis message. Is AURA daemon running? Exiting...")
exit(3)
if not args.quiet:
print("...result: ")
print("...result: \n" + p.stringreply)
if p.stringreply != "":
if p.stringreply[len(p.stringreply)-1] == "\n":
print(p.stringreply[0:len(p.stringreply) - 1])
else:
print(p.stringreply[0:len(p.stringreply)])
if args.stoptime:
end = time.time()
exectime = end-start
print("execution time: "+str(exectime)+"s")
def valid_playlist_entry(argument):
import datetime
import argparse
try:
index = int(argument[0])
fromtime = datetime.strptime(argument[1], "%Y-%m-%d")
source = argument[2]
return index, fromtime, source
except:
msg = "Not a valid date: '{0}'.".format(argument[0])
raise argparse.ArgumentTypeError(msg)
# # ## ## ## ## ## # #
# # ENTRY FUNCTION # #
# # ## ## ## ## ## # #
......
......@@ -14,6 +14,7 @@ class BroadcastModel:
def commit(self):
db.session.commit()
# ------------------------------------------------------------------------------------------ #
class Format(db.Model, BroadcastModel):
"""
......@@ -24,6 +25,7 @@ class Format(db.Model, BroadcastModel):
id = Column(Integer, primary_key=True)
name = Column(String(255))
# ------------------------------------------------------------------------------------------ #
class BroadcastPeriod(db.Model, BroadcastModel):
"""
......
......@@ -6,7 +6,7 @@ import datetime
import json
import re
import uuid
import threading
class RedisStateStore(object):
......@@ -299,14 +299,10 @@ class RedisStateStore(object):
# ------------------------------------------------------------------------------------------ #
def publish(self, channel, message):
#pb = self.db.pub
subscriber_count = self.db.execute_command('PUBSUB', 'NUMSUB', channel)
if subscriber_count[1] == 0:
if channel.lower().find("reply"):
print("Cannot reply to guru on channel '"+channel+"'")
else:
raise Exception("No subscriber! Is Aura daemon running?")
if channel.lower().find("reply") < 0 and subscriber_count[1] == 0:
raise Exception("No subscriber! Is Aura daemon running?")
self.db.publish(channel, message)
from enum import Enum
class TerminalColors:
class TerminalColors(Enum):
HEADER = '\033[95m'
OK_GREEN = '\033[32m'
OK_GREEN = "\033[32m"
OK_ORANGE = '\033[33m'
OK_BLUE = '\033[34m'
OK_PINK = '\033[35m'
......@@ -14,4 +15,4 @@ class TerminalColors:
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
ENDC = '\033[0m'
\ No newline at end of file
ENDC = "\033[0m"
\ No newline at end of file
from enum import Enum
class Channels(Enum):
STANDARD = "aura"
MAIN = "main"
FNP_REPLY = "fetch_new_programme_reply"
GAP_REPLY = "get_act_programme_reply"
IP_REPLY = "init_player_reply"
PMQ_REPLY = "print_message_queue_reply"
......@@ -31,7 +31,7 @@ class LiquidSoapClient:
self.socket_path = config.get('socketdir') + '/' + socket_filename
self.debug = config.get("debug")
if self.debug:
if self.debug > 2:
print("socketpath: " + self.socket_path)
# init
......@@ -155,7 +155,6 @@ class LiquidSoapClient:
"""
param = (param.strip() if param.strip() == "" else " " + urllib.parse.unquote(param.strip()))
if self.connected:
# print namespace + '.' + command + param + "\n"
if namespace is "":
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment