diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ddd1ac582372c8c50ebfc1ee6194db3084b19292..d1998aa2b33c32cec9ad5efd42a0b3b628e33e5b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -20,7 +20,7 @@ simple_guru_help: script: - python3 guru.py -h -print_connection_status: - stage: test - script: - - python3 guru.py -pcs \ No newline at end of file +#print_connection_status: +# stage: test +# script: +# - python3 guru.py -pcs \ No newline at end of file diff --git a/configuration/engine.ini b/configuration/engine.ini index 663e3c3faa6b53a01e3ed8a6d16e2d7b9980306d..a7ed1c28e3fad427f57115836262d950d7eb31f5 100644 --- a/configuration/engine.ini +++ b/configuration/engine.ini @@ -24,7 +24,7 @@ alsa_buffer_length="7" # alsa_periods => int alsa_periods="0" # frame_duration => double -frame_duration="0.4" +frame_duration="0.40" # frame_size => int frame_size="" diff --git a/libraries/security/user.py b/libraries/security/user.py index c4158b98fb26a7e6d635f7650bb1c494a2909e4d..3747f9ad4113687ae594c039e1faadcaef1387c9 100644 --- a/libraries/security/user.py +++ b/libraries/security/user.py @@ -22,6 +22,8 @@ sys.path.insert(0, package_dir) """ User verwalten """ + + class AuraUser(object): def __init__(self): @@ -37,23 +39,23 @@ class AuraUser(object): :param username: :return: boolean """ - userid = self.db.hget(self.dbname,username).decode("utf-8") + userid = self.db.hget(self.dbname, username).decode("utf-8") if not userid: return False else: self.db.delete(self.userprefix + userid) - self.db.hdel(self.dbname,username) + self.db.hdel(self.dbname, username) return True # ------------------------------------------------------------------------------------------ # - def setPassword(self,username, password): + def setPassword(self, username, password): """ Set users password :param username: string :param password: string :return: boolean """ - userid = self.db.hget(self.dbname,username).decode("utf-8") + userid = self.db.hget(self.dbname, username).decode("utf-8") if not userid: return False self.db.hset(self.userprefix + userid, 'password', password) @@ -67,10 +69,10 @@ class AuraUser(object): :param role: string :return:boolean """ - userid = self.db.hget(self.dbname,username).decode("utf-8") + userid = self.db.hget(self.dbname, username).decode("utf-8") dbrole = self.db.hget(self.userprefix + str(userid), 'role').decode("utf-8") - if(dbrole == "admin"): + if (dbrole == "admin"): return True print("username: " + username + " - userid: " + userid + " - role: " + role + " - dbrole: " + dbrole) @@ -78,7 +80,7 @@ class AuraUser(object): return (dbrole == role) # ------------------------------------------------------------------------------------------ # - def hasPassword(self,username, password): + def hasPassword(self, username, password): """ Compare users password with the given one :param username: string @@ -86,10 +88,11 @@ class AuraUser(object): :return: """ - userid = self.db.hget(self.dbname,username).decode("utf-8") + userid = self.db.hget(self.dbname, username).decode("utf-8") dbpassword = self.db.hget(self.userprefix + userid, 'password').decode("utf-8") - print("username: "+username+" - userid: "+userid+" - password: "+password+" - dbpassword: "+dbpassword) + print( + "username: " + username + " - userid: " + userid + " - password: " + password + " - dbpassword: " + dbpassword) print(dbpassword == password) return (dbpassword == password) @@ -102,7 +105,7 @@ class AuraUser(object): :param password: password :return: """ - return (self.hasPassword(username,password) and self.hasRole(username, 'admin')) + return (self.hasPassword(username, password) and self.hasRole(username, 'admin')) # ------------------------------------------------------------------------------------------ # def insertUser(self, username, password, role="user"): @@ -113,13 +116,23 @@ class AuraUser(object): :param role: string :return: string - the password """ - userid = self.db.hget(self.dbname,username).decode("utf-8") + + userid = self.db.hget(self.dbname, username) if not userid: - userid = self.db.incr("next_aurauser_id") - self.db.hset(self.dbname,username,userid) - self.db.hmset(self.userprefix + userid, {"username" : username,"password" :password, "role" : role}) - return password + # insert + userid = str(self.db.incr("next_aurauser_id")) + self.db.hset(self.dbname, username, userid) + else: + # update + userid = userid.decode("utf-8") + + id = self.userprefix + userid + user = {"username": username, "password": password, "role": role} + self.db.hmset(id, user) + + # return inserted user id + return id # ------------------------------------------------------------------------------------------ # def getUser(self, username): @@ -128,8 +141,23 @@ class AuraUser(object): :param username: string :return: dict - userdata """ - userid = self.db.hget(self.dbname,username).decode("utf-8") - return self.db.hgetall(self.userprefix + userid) + userid = self.db.hget(self.dbname, username) + if userid is None: + return None + + return self.getUserByKey(self.userprefix + userid.decode("utf-8")) + + # ------------------------------------------------------------------------------------------ # + def getUserByKey(self, key): + """ + Get users data + :param id: string + :return: dict - userdata + """ + + data = self.db.hgetall(key) + user = {key.decode('utf-8'): value.decode('utf-8') for (key, value) in data.items()} + return user # ------------------------------------------------------------------------------------------ # def getUserlist(self): @@ -137,7 +165,7 @@ class AuraUser(object): get all users :return: list - the userlist """ - accounts=[] + accounts = [] keys = self.db.keys(self.userprefix + "*") for key in keys: accounts.append(self.db.hgetall(key)) @@ -149,15 +177,16 @@ class AuraUser(object): get usernames passwords as dict in format {username1:password1, username2;password2, ...} :return: """ - accounts={} + accounts = {} keys = self.db.keys(self.userprefix + "*") for key in keys: account = self.db.hgetall(key) try: - accounts[account['username']] = account['password'] + accounts[account[b'username']] = account[b'password'] except: - pass + import traceback + traceback.print_exc() return accounts # ------------------------------------------------------------------------------------------ # @@ -166,5 +195,5 @@ class AuraUser(object): create a new passoword :return: string - the password """ - password = ''.join(random.sample(string.lowercase+string.uppercase+string.digits,14)) - return password \ No newline at end of file + password = ''.join(random.sample(string.lowercase + string.uppercase + string.digits, 14)) + return password diff --git a/modules/communication/liquidsoap/communicator.py b/modules/communication/liquidsoap/communicator.py index 33931b0049e3d8714266b6eaa43da594c967a9de..5aef8a409903be3ff9cf39cac5b281e5486ff61b 100644 --- a/modules/communication/liquidsoap/communicator.py +++ b/modules/communication/liquidsoap/communicator.py @@ -42,11 +42,13 @@ class LiquidSoapCommunicator(ExceptionLogger): self.config = config self.logger = logging.getLogger("AuraEngine") - self.lqc = LiquidSoapPlayerClient(config, "simplestmixer.sock") + self.lqc = LiquidSoapPlayerClient(config, "engine.sock") self.lqcr = LiquidSoapRecorderClient(config, "record.sock") errors_file = self.config.get("install_dir") + "/errormessages/controller_error.js" - self.error_data = simplejson.load(open(errors_file)) + f = open(errors_file) + self.error_data = simplejson.load(f) + f.close() self.auramailer = AuraMailer(config.get("admin_mail"), config.get("from_mail")) @@ -217,7 +219,7 @@ class LiquidSoapCommunicator(ExceptionLogger): t.liquidsoapcommunicator = self t.active_entry = self.scheduler.get_active_entry() t.start() - return "Started LiquidSoapInitThread!" + return "LiquidSoapInitThread started!" # ------------------------------------------------------------------------------------------ # def all_data(self): diff --git a/modules/liquidsoap/__init__.py b/modules/liquidsoap/__init__.py index 1994bc11bb6015ba8fbea1aab56d1ec8fb056146..13fef6e4de1114c06ab259327621d0bd9549ff2a 100644 --- a/modules/liquidsoap/__init__.py +++ b/modules/liquidsoap/__init__.py @@ -1 +1 @@ -__author__ = 'michel' +__author__ = 'gg' diff --git a/modules/liquidsoap/simplestmixer.liq b/modules/liquidsoap/engine.liq similarity index 96% rename from modules/liquidsoap/simplestmixer.liq rename to modules/liquidsoap/engine.liq index 4cd1402cdbe2921d1b31987bdc858503b38662f5..2a48c0205cf28db313fc22a668d1ef2b3981265a 100644 --- a/modules/liquidsoap/simplestmixer.liq +++ b/modules/liquidsoap/engine.liq @@ -2,7 +2,7 @@ %include "readini.liq" -ini = read_ini("/etc/aura/aura.ini") +ini = read_ini("/etc/aura/engine.ini") %include "settings.liq" %include "fallback.liq" diff --git a/modules/liquidsoap/readini.liq b/modules/liquidsoap/readini.liq index 878fb11263325b0ba5dabaf97df85d9018363d1f..a37d2642922d00da9b580393a0e5da801f992863 100644 --- a/modules/liquidsoap/readini.liq +++ b/modules/liquidsoap/readini.liq @@ -7,15 +7,19 @@ def read_ini(file) def f(l',l)= if list.length(l) >= 2 then line = string.extract(pattern='"(.*)"', list.nth(l,1)) - print(line) - print((list.hd(l),line['1'])) + + # print(line) + # print((list.hd(l),line['1'])) list.append([(list.hd(l),line['1'])],l') else if list.length(l) >= 1 then list.append([(list.hd(l),"")],l') else - l' + directory = dirname() + ignore(directory) + list.add(("install_dir", "/home/gg/PycharmProjects/engine"), l') +# l' end end end diff --git a/modules/liquidsoap/unused.alsa.liq b/modules/liquidsoap/unused.alsa.liq deleted file mode 100644 index 20c18621d07c9ecd647e8fe3ab99e757232d1f7e..0000000000000000000000000000000000000000 --- a/modules/liquidsoap/unused.alsa.liq +++ /dev/null @@ -1,6 +0,0 @@ - -input_fs = single(id="fs", "/var/audio/fallback/output.flac") -input_http = input.http(id="http", "http://stream.fro.at/fro128.mp3") -linein_alsa_1 = input.alsa(id="linein", device = input_device_0, bufferize = false) -mixer = mix(id="mixer", [input_fs, input_http, linein_alsa_1]) -output.alsa(id="lineout", device = output_device_0, bufferize = false, mixer) diff --git a/modules/liquidsoap/unused.dynamicsources.liq b/modules/liquidsoap/unused.dynamicsources.liq deleted file mode 100644 index 6ae441c432ec0e8bf5c19bef607a1846ee2e8abf..0000000000000000000000000000000000000000 --- a/modules/liquidsoap/unused.dynamicsources.liq +++ /dev/null @@ -1,150 +0,0 @@ -%include "readini.liq" - -inifile = '/etc/aura/aura.ini' -ini = read_ini(inifile) - -set("log.file.path", "./<script>.log") - -set("server.telnet", true) -set("server.telnet.bind_addr", "0.0.0.0") -set("server.telnet.port", 1234) - -use_alsa = list.assoc("use_alsa", ini) == "y" -frame_duration = float_of_string(list.assoc("frame_duration", ini)) -frame_size = int_of_string(list.assoc("frame_size", ini)) -alsa_buffer = int_of_string(list.assoc("alsa_buffer", ini)) -alsa_buffer_length = int_of_string(list.assoc("alsa_buffer_length", ini)) -alsa_periods = int_of_string(list.assoc("alsa_periods", ini)) - -if use_alsa then - if frame_duration > 0.0 then - print("setting frame.duration to #{frame_duration}") - set("frame.duration", frame_duration) - end - if frame_size > 0 then - print("setting frame.size to #{frame_size}") - set("frame.size", frame_size) - end - if alsa_buffer > 0 then - print("setting alsa.buffer to #{alsa_buffer}") - set("alsa.alsa_buffer", alsa_buffer) - end - if alsa_buffer > 0 then - print("setting alsa.buffer_length to #{alsa_buffer_length}") - set("alsa.buffer_length", alsa_buffer_length) - end - if alsa_periods > 0 then - print("setting alsa.periods to #{alsa_periods}") - set("alsa.periods", alsa_periods) # assertion error when setting periods other than 0 => alsa default - end -end - -# First, we create a list referencing the dynamic sources: -dyn_sources = ref [] - -# This is our icecast output. -# It is a partial application: the source needs to be given! -out = output.icecast(%mp3, - host="test", - password="hackme", - fallible=true) - - - -# Now we write a function to create -# a playlist source and output it. -def create_playlist(uri) = - # The playlist source - s = playlist(uri) - - # The output - output = out(s) - - # We register both source and output - # in the list of sources - dyn_sources := - list.append( [(uri,s),(uri,output)], - !dyn_sources ) - "Done!" -end - -# And a function to destroy a dynamic source -def destroy_playlist(uri) = - # We need to find the source in the list, - # remove it and destroy it. Currently, the language - # lacks some nice operators for that so we do it - # the functional way - - # This function is executed on every item in the list - # of dynamic sources - def parse_list(ret, current_element) = - # ret is of the form: (matching_sources, remaining_sources) - # We extract those two: - matching_sources = fst(ret) - remaining_sources = snd(ret) - - # current_element is of the form: ("uri", source) so - # we check the first element - current_uri = fst(current_element) - if current_uri == uri then - # In this case, we add the source to the list of - # matched sources - (list.append( [snd(current_element)], - matching_sources), - remaining_sources) - else - # In this case, we put the element in the list of remaining - # sources - (matching_sources, - list.append([current_element], - remaining_sources)) - end - end - - # Now we execute the function: - result = list.fold(parse_list, ([], []), !dyn_sources) - matching_sources = fst(result) - remaining_sources = snd(result) - - # We store the remaining sources in dyn_sources - dyn_sources := remaining_sources - - # If no source matched, we return an error - if list.length(matching_sources) == 0 then - "Error: no matching sources!" - else - # We stop all sources - list.iter(source.shutdown, matching_sources) - # And return - "Done!" - end -end - -def backup_pool () = - result = get_process_lines("python ./helpers/next_song_from_pool.py") - log("next song: #{result}") - request.create(list.hd(result)) -end - -backup_pool = request.dynamic(backup_pool) - - -# Now we register the telnet commands: -server.register(namespace="dynamic_playlist", - description="Start a new dynamic playlist.", - usage="start <uri>", - "start", - create_playlist) -server.register(namespace="dynamic_playlist", - description="Stop a dynamic playlist.", - usage="stop <uri>", - "stop", - destroy_playlist) -server.register(namespace="dyn", - description="load next song from pool", - usage="next <folder>", - "next", - - - -output.dummy(blank()) diff --git a/modules/liquidsoap/unused.inToOut.liq b/modules/liquidsoap/unused.inToOut.liq deleted file mode 100644 index 5543c2799b95a263f859a0505ec2ec09a83bd745..0000000000000000000000000000000000000000 --- a/modules/liquidsoap/unused.inToOut.liq +++ /dev/null @@ -1,48 +0,0 @@ -set("frame.size", 1881) -#set("decoding.buffer_length", 20.) -#set("frame.channels", 2) -#set("frame.samplerate", 44100) - -set("server.telnet", true) -set("server.telnet.port", 1234) - -set("alsa.alsa_buffer", 2048) -#set("alsa.periods", 8) -#set("alsa.buffer_length", 4096) - -# works, but every now and then buffer overruns in alsa.in on node -# more or less the same with or w/o clock_safe set. maybe a bit better with clock_safe=false -input_alsa = input.alsa(bufferize=false, clock_safe=false) -output.alsa(bufferize=false, clock_safe=false, input_alsa) - -#output.alsa(bufferize = false, input.alsa(bufferize = false)) - -# works -#url = "http://stream.fro.at/fro64.mp3" -#i = strip_blank(input.http(id="stream", url)) -#input_http = mksafe(i) -#output.alsa(bufferize=false, input_http) - -# works -#input_fs = fallback(track_sensitive=false, -# [ single("/var/audio/fallback/music.flac"), playlist.safe("/var/audio/fallback/NightmaresOnWax/Smokers Delight") ] ) -#ignore(input_fs) -#output.alsa(bufferize=false, input_fs) - -#output.alsa(device="hw:1,0", bufferize=false, input_alsa) -#output.alsa(device="hw:1,0", bufferize=false, input_http) -#output.pulseaudio(input_http) -#output.alsa(device="hw:0,0", bufferize=false, input_alsa) -#output.pulseaudio(input_fs) - -#mixer = mix(id = "mixer", [input_alsa]) -#final_stream = fallback(id="station_fallback", [mixer, playlist.safe("/var/audio/fallback/NightmaresOnWax/Smokers Delight")]) -#output.alsa(device="hw:1,0", bufferize=false, final_stream) - -#ignore(mixer) -#ignore(input_fs) -#ignore(input_http) -#ignore(input_alsa) - - - diff --git a/modules/liquidsoap/unused.inputToOutput.liq b/modules/liquidsoap/unused.inputToOutput.liq deleted file mode 100644 index fe5d30609d702859d566c409538c40bf91f44b6e..0000000000000000000000000000000000000000 --- a/modules/liquidsoap/unused.inputToOutput.liq +++ /dev/null @@ -1,42 +0,0 @@ -#set("frame.size", 3763) -#set("decoding.buffer_length", 20.) -#set("frame.channels", 2) -#set("frame.samplerate", 44100) - -set("server.telnet", true) -set("server.telnet.port", 1234) - -input_alsa = input.alsa(bufferize=false) -#output.alsa(device="hw:0,0", bufferize=false, input_alsa) - -#output.alsa(bufferize = false, input.alsa(bufferize = false)) - -url = "http://stream.fro.at/fro64.mp3" -#url = "http://mp3stream1.apasf.apa.at:8000/listen.pls" -input_http = strip_blank(id="http_strip", input.http(id="stream", url)) -#input_http = mksafe(i) -ignore(input_http) - - -input_fs = strip_blank(id="fs_strip", single("/var/audio/fallback/music.flac")) -#fallback(track_sensitive=false, -# [ single("/var/audio/fallback/music.flac"), playlist.safe("/var/audio/fallback/NightmaresOnWax/Smokers Delight") ] ) -ignore(input_fs) - -#output.alsa(device="hw:0,0", bufferize=false, input_alsa) -#output.alsa(device="hw:0,0", bufferize=false, input_http) -#output.pulseaudio(input_http) -#output.alsa(device="hw:0,0", bufferize=false, input_fs) -#output.pulseaudio(input_fs) - -mixer = mix(id = "mixer", [input_fs, input_http, input_alsa]) -#final_stream = fallback(id="station_fallback", [mixer, playlist.safe("/var/audio/fallback/NightmaresOnWax/Smokers Delight")]) -output.alsa(bufferize=false, mixer) - -ignore(mixer) -#ignore(input_fs) -#ignore(input_http) -#ignore(input_alsa) - - - diff --git a/modules/liquidsoap/unused.library.liq b/modules/liquidsoap/unused.library.liq deleted file mode 100644 index a0bacf9410172ab9e9431fc0099cf9e0747b51ad..0000000000000000000000000000000000000000 --- a/modules/liquidsoap/unused.library.liq +++ /dev/null @@ -1,139 +0,0 @@ -%include "readini.liq" - -inifile = '/etc/aura/aura.ini' -ini = read_ini(inifile) - -def get_task_number (taskname) = - tasks = [ - ('seek_track', '10'), - ('load', '11'), - ('move', '12'), - ('insert', '13'), - ('remove', '14'), - ('push', '15'), - ('data', '16'), - ('skip', '17'), - ('pause', '19'), - ('play', '18'), - ('flush', '16'), - ] - if list.mem_assoc(taskname, tasks) then - tasks[taskname] - else - log("Warning: task #{taskname} does not exist") - "00" - end -end - -def get_namespace_number(namespace) = - channelnames = ref string.split(separator=',', list.assoc("channels", ini)) - - namespaces = [ - ('player', '10'), - ('common', '11'), - ('playlist', '11'), - ('request', '12'), - ('mixer', '13'), - ] - def addNamespace (ret, el) - number = string_of((list.length(ret) + 10)) - list.append(ret,[("ch#{el}", "#{number}")]) - end - namespaces = list.fold(addNamespace, namespaces, !channelnames) - - if list.mem_assoc(namespace, namespaces) then - namespaces[namespace] - else - log("Warning: namespace #{namespace} does not exist") - log(json_of(namespaces)) - "00" - end -end - -def create_protocol () = - #pwd = list.hd(get_process_lines('pwd')) - #def getdirname() = - - # if dirname(argv(0)) == "." then - # "" - # else - # '/'^dirname(argv(0)) - # end - #end - #cur = getdirname() - add_protocol(temporary=true, "silence", fun(arg,delay)-> begin system('#{list.assoc("install_dir", ini)}/modules/soundengine/helpers/silence.sh 0.01 > /var/tmp/quiet.wav; qwavheaderdump -q -F /var/tmp/quiet.wav > /dev/null' ) ['/var/tmp/quiet.wav'] end) -end - -#create_protocol() - -def message (~value="", namespace, success, message, code, error, ~level="error", ~type='internal') = - - level = if success then 'success' else level end - namespace = if namespace == 'common' then - 'playlist' - else - namespace - end - namespace_number = get_namespace_number(namespace) - code = "10#{namespace_number}#{code}" - result = [('section', '#{namespace}'), - ('success', '#{success}'), - ('message', '#{message}'), - ('value', '#{value}'), - ('code', '#{code}#{error}'), - ('level', '#{level}'), - ('type', '#{type}'), - ] - json_of(compact=true,result) - -end - -##Sorgt für unterbrechungsfreien Wechsel zwischen den Tracks -def crossfade(a,b) - add(normalize=false, - [ fade.initial(duration=2., b), - sequence(merge=true, - [ blank(duration=0.), fallback([]) ]), - fade.final(duration=2.,a) ]) -end - -def foldplaylist(l, el)= - # fold metadata to list - def tolist (ret, el) = - tmp = string.split(separator='=',el) - if list.length(tmp) > 1 then # found the separator in current el - # get the key -> value pair - key = list.nth(tmp,0) - value = list.nth(tmp,1) - # append to list - list.append(ret,[(key,value)]) - else - # nothing to do - ret - end - end - # extract metadata part from annotation - extracted = string.extract(pattern="annotate:[,](.*):/",string.replace(pattern='"',(fun (s) -> ""),el)) - # split extracted string by comma separator and create a list - list.append(l,[list.fold(tolist, [], string.split(separator=',',extracted["1"]))]) -end -# The server seeking function -def seek_track(source, t) = - - t = float_of_string(default=0.,t) - ret = source.seek(source,t) - log("Seeked #{ret} seconds.") - success = ret > 0. - error = if success then '00' else '01' end - errors = [('00', 'Seeked #{ret} seconds on #{source.id(source)}'), ('01', 'Seek failed')] - message(value=string_of(ret), source.id(source), success, errors[error], get_task_number ('seek_track'), error, level="warning", type='unknown') - #"Seeked #{ret} seconds." -end - -def reload_recorded(~skip, ~uri) = - print('param skip: #{skip} +++ param uri: #{uri}') - print("reload_recorded not implemented") - "nana" -end - - diff --git a/modules/liquidsoap/unused.playd.liq b/modules/liquidsoap/unused.playd.liq deleted file mode 100644 index 42466444241f59c5e625756943af8480b998688c..0000000000000000000000000000000000000000 --- a/modules/liquidsoap/unused.playd.liq +++ /dev/null @@ -1,310 +0,0 @@ -#!/usr/bin/liquidsoap - -#set("log.stdout", true) - -inst = if argv(1) != "" then string_of(argv(1)) else 'playd' end -instance = ref inst - -%include "readini.liq" - -inifile = '/etc/aura/aura.ini' -ini = read_ini(inifile) - -# send alive -ignore(system('#{list.assoc("install_dir", ini)}/modules/liquidsoap/helpers/message.py -c #{!instance} -t sayAlive')) -# send alive frequently -exec_at(freq=20., pred={true}, {ignore(system('#{list.assoc("install_dir", ini)}/modules/liquidsoap/helpers/message.py -c #{!instance} -t sayAlive'))}) - -# set current playlist -ignore(system('#{list.assoc("install_dir", ini)}/modules/liquidsoap/helpers/message.py -c #{!instance} --task=setState -n playlistcurrent -v ""')) - -# load data from ini file -#daemongroup = list.assoc("daemongroup", ini) -#daemonuser = list.assoc("daemonuser", ini) - - -socketdir = list.assoc("socketdir", ini) - -# ALSA settings -use_alsa = list.assoc("use_alsa", ini) -alsa_buffer = int_of_string(list.assoc("alsa_buffer", ini)) -alsa_periods = int_of_string(list.assoc("alsa_periods", ini)) - -# set player i/o devices -player_input = list.assoc("input_device", ini) -#player_second_input = list.assoc("player_second") -player_output = list.assoc("output_device", ini) - -# fallback settings -fallback_audio_folder = list.assoc("fallback_audio_folder", ini) -fallback_max_blank = float_of_string(list.assoc("fallback_max_blank", ini)) -fallback_min_noise = float_of_string(list.assoc("fallback_min_noise", ini)) -fallback_threshold = float_of_string(list.assoc("fallback_threshold", ini)) - -# channel names from config -channelnames = ref string.split(separator=',', list.assoc("channels", ini)) - -# alsa settings -# buffer - decrease latency: eg. alsa_buffer="2024" -set("alsa.alsa_buffer", alsa_buffer) -set("alsa.periods", alsa_periods) - -# enable socketserver -set("server.socket", true) -set("server.socket.path", socketdir^"/<script>.sock") -set("server.telnet", true) -set("server.telnet.port", 1234) - -# enable daemon -#set("init.daemon", true) -#set("init.daemon.change_user.group", daemongroup) -#set("init.daemon.change_user.user", daemonuser) -#set("init.daemon.pidfile.path", socketdir^"/<script>.pid") -#set("init.daemon.pidfile.perms", 0o666) - -# set logging -set("log.file",true) -set("log.file.path", list.assoc("logdir", ini)^"/<script>.log") -set("log.file.perms",0o640) -set("log.level", 10) - -# allowed mime types -set("playlists.mime_types.xml",["text/xml","application/xml","application/xspf+xml"]) - -# load functions -# dir = list.assoc("install_dir", ini) - -%include "library.liq" -%include "playlist.liq" - -# Der input wie oben definiert -def get_input() - def get_input() - if use_alsa == "y" then - if player_input == "soundcard" then - print("autodetect device") - input.alsa(id="sound_input", fallible=true, clock_safe=false) - else - print("manual set device: "^player_input) - input.alsa(id="sound_input", fallible=true, clock_safe=false, device=player_input) - end - else - input.pulseaudio(id="sound_input") - end - end - def get_fallback() - if fallback_audio_folder != "" then - print("fallbackfolder chosen: "^fallback_audio_folder) - playlist.safe("/var/audio/fallback/music.flac") - #playlist.safe(fallback_audio_folder) - else - blank(duration=20.0) - end - end - - if player_input == "" then - blank(duration=0.1) # wait... - else - # start silence detector on input alsa and set a fallback - fallback(track_sensitive=false, - [ strip_blank(max_blank=fallback_max_blank, min_noise=fallback_min_noise, threshold=fallback_threshold, get_input()), - get_fallback() ] - ) - end -end - -playlistrunning = ref false - -playlist_recorded = playlist.xml(id='playlist', on_done=fun() -> begin ignore(system('#{list.assoc("install_dir", ini)}/modules/soundengine/helpers/message.py -c #{!instance} --task=setState -n playlistcurrent -v ""')) ignore(server.execute('mixer.select 0 false')) end, 'none') -# Die Source aus der Playlist -recorded = snd(playlist_recorded) - -# Skippen erlauben -add_skip_command(recorded) - -# Funktion zum laden einer neuen Playlist -playlist_funcs = fst(playlist_recorded) - -# Flush functions -flush_recorded = snd(fst(playlist_funcs)) - -# Reload function -reload_recorded = fst(fst(playlist_funcs)) - -#up funtction -move_recorded = fst(fst(snd(playlist_funcs))) - -#insert funtction -insert_recorded = fst(snd(fst(snd(playlist_funcs)))) - -# remove function -remove_recorded = snd(snd(fst(snd(playlist_funcs)))) - -#push function -push_recorded = snd(snd(snd(playlist_funcs))) - -#show playlist function -data_recorded = fst(snd(snd(playlist_funcs))) - -# create playlist source with smart crossfade -playlist = fallback(id="common", track_sensitive=false, [ - switch(transitions = - [crossfade,crossfade], - [ - ( {!playlistrunning == true}, recorded ), # play the playlist - ( {!playlistrunning == false}, get_input() ) - ] - ), - if fallback_audio_folder != "" then - playlist.safe(fallback_audio_folder) - else - blank(duration=20.0) - end -]) - -# method to dynamicaly create a channel -def addChannel (ret, el, ~base="ch") - equeue = request.equeue(id = base^el) # create the equeue request - # add a seek function to the channel - server.register(namespace="ch"^el, - description="Seek to a relative position", - usage="seek <duration>", - "seek",fun (x) -> begin seek_track(equeue, x) end) - # append and return the list - list.append(ret,[equeue]) -end - -channels = addChannel([], '1', base='auto') -channels = addChannel(channels, '2', base='auto') -channels = list.fold(addChannel, channels, !channelnames) - -mixer = mix(id = "mixer", list.append([playlist], channels)) -#ignore(s) # testing - - -# User may load a XML-Playlist -#server.register(namespace='playlist', -# description="Load Playlist", -# usage="load <uri>", -# "load",fun (p) -> begin -# reload_recorded(skip=0, uri=p) -# end -#) - -# Register the seek function -server.register(namespace='playlist', - description="Seek to a relative position", - usage="seek <duration>", - "seek",fun (x) -> begin seek_track(recorded, x) end -) - -# The play function -server.register(namespace='playlist', - description="Play recorded files", - usage="play", - "play",fun (x) -> if !playlistrunning == true then - message('playlist', false, 'Playlist already playing', get_task_number ('play'), '01', level="info", type="user") - else - ignore(server.execute('mixer.select 0 true')) - playlistrunning := true - message('playlist', true, 'Start playing' , get_task_number ('play'), '00') - end -) - -# Flush current playlist -server.register(namespace='playlist', - description="Flush recorded playlist", - usage="flush", - "flush",fun (s) -> begin flush_recorded() end) - -# The remove function -server.register(namespace='playlist', - description="Remove item from playlist", - usage="remove <pos>", - "remove",fun (p) -> begin remove_recorded(int_of_string(p)) end) - -# Let the user move up or down a track -server.register(namespace='playlist', - description="Move an item up or down", - usage="move <from> <to>", - "move",fun (p) -> begin - params=string.split(separator=" ",p) - src=if list.length(params)>0 then (int_of_string(list.nth(params,0))+0) else 0 end - target=if list.length(params)>1 then (int_of_string(list.nth(params,1))+0) else 0 end - move_recorded(src, target) - end -) - -# Insert an entry -server.register(namespace='playlist', - description="Add an entry", - usage="insert <pos> <uri> [<title> <time>]", - "insert",fun (p) -> begin - params=string.split(separator=" ",p) - pos=if list.length(params)>0 then list.nth(params,0) else '' end - uri=if list.length(params)>1 then list.nth(params,1) else '' end - title=if list.length(params)>2 then list.nth(params,2) else '' end - time=if list.length(params)>3 then list.nth(params,3) else '' end - insert_recorded(pos=pos, title=title,time=time,uri) - end -) - -# Insert a track on top of playlist -server.register(namespace='playlist', - description="Push an item to top and play immediately", - usage="push <pos>", - "push",fun (p) -> begin - params=string.split(separator=" ",p) - pos=if list.length(params)>0 then int_of_string(list.nth(params,0)) else 0 end - push_recorded(pos) - end -) - -# Show metadata -server.register(namespace='playlist', - description="Show remaining playlist data in json format", - usage="data", - "data",fun (s) -> begin - playlist = data_recorded() - json_of(compact=true, playlist) - end -) - -# Pause/stop playlist -server.register(namespace='playlist', - description="Pause playing recorded files", - usage="pause", - "pause", fun (x) -> if !playlistrunning == false then - message('playlist', false, 'Playlist already stopped', get_task_number ('pause'), '01', level="info", type="user") - else - playlistrunning := false - ignore(server.execute('playlist.skip')) - ignore(system('#{list.assoc("install_dir", ini)}/modules/soundengine/helpers/message.py -c #{!instance} --task=setState -n playlistcurrent -v ""')) - message('playlist', true, 'Playlist stopped', get_task_number ('pause'), '00') - end -) - -# get remaining time -server.register(namespace='playlist', - description="Remaining time", - usage = "remaining", - "remaining", fun(x) -> string_of(source.remaining(recorded)) -) - -#streamm = single("/var/audio/fallback/music.flac") -#ignore(streamm) # testing - -# Alsa output -if use_alsa == "y" then - if player_output == 'soundcard' then - output.alsa(id="player", fallible=true, mixer) - else - output.alsa(id="player", fallible=true, device=player_output, mixer) - end -else - output.pulseaudio(id="player", mixer) -end - - -# %include "stream.liq" - diff --git a/modules/liquidsoap/unused.playlist.liq b/modules/liquidsoap/unused.playlist.liq deleted file mode 100644 index dcc724f39e05886163d3f505a43036a85f7dd3bf..0000000000000000000000000000000000000000 --- a/modules/liquidsoap/unused.playlist.liq +++ /dev/null @@ -1,202 +0,0 @@ - -# Liest Playlist im XML-Format (XSPF) -%include "readini.liq" -%include "library.liq" - -inst = if argv(1) != "" then string_of(argv(1)) else 'playd' end -instance = ref inst - -error_message = ref "" - -def playlist.xml(~id="",~skip=0,~on_done={()},uri) - # A reference to the playlist - - playlist = ref [] - - # A reference to the uri - playlist_uri = ref uri - # A reference to know if the source - # has been stopped - has_stopped = ref false - # The next function - see request.dynamic - def next () = - file = - if list.length(!playlist) > 0 then - ret = list.hd(!playlist) # get first entry - playlist := list.tl(!playlist) # remove first entry from playlist - ret - else - # Playlist finished? - if not !has_stopped then - on_done () # call on_done method - end - has_stopped := true - "" - end - if file == '' then - request.create("silence:waiting") # - else - track = file - extracted = string.extract(pattern="annotate:.*:(/.*)",string.replace(pattern='"',(fun (s) -> ""), track)) - wavfile = extracted["1"] - - ignore(system('#{list.assoc("install_dir", ini)}/modules/soundengine/helpers/message.py -c #{!instance} --task=setState -n playlistcurrent -v "#{wavfile}"')) - request.create(track) - end - end - # Instanciate the source - source = request.dynamic(id=id,next) - - # flush function - def flush () = - log(label=id,"Flush "^string_of(list.length(!playlist))^" Items") - playlist := [] # playlist is empty now - ignore(system('#{list.assoc("install_dir", ini)}/modules/soundengine/helpers/message.py -c #{!instance} --task=setState -n playlistcurrent -v ""')) - message(value=json_of(!playlist), 'playlist', true, "Playlist flushed", get_task_number ('flush'), "00", type='internal') - end - - # Get its id. - id = source.id(source) - # The load function - def load_playlist (~skip=1) = - - playlist_tmp = request.create.raw(!playlist_uri) # temporary try to create the playlist - - result = - if file.exists(!playlist_uri) and request.resolve(playlist_tmp) then # playlist should exist and be resolvable - playlist_tmp = request.filename(playlist_tmp) # create a temporary request - entries = playlist.parse(playlist_tmp) # parse the playlist request - - # create a annotation from playlist track - def annotate_track(el) = - meta = fst(el) - # remove protocol from filepath - filepath = string.replace(pattern='"',(fun (s) -> ""),string.replace(pattern='file://',(fun (s) -> ""),string.escape(snd(el)))) - # fold metadata - s = list.fold(fun (cur, el) -> begin "#{cur},#{fst(el)}=#{string.escape(snd(el))}" end, "", meta) - # return annotation - "annotate:#{s}:#{filepath}" - end - # map entries - error_message := if list.length(entries) > 0 then "OK" else "empty" end - list.map(annotate_track,entries) - else - error_message := if file.exists(!playlist_uri) then "!resolve" else "!exist" end - log(label=id,"Couldn't read playlist: request resolution failed.") - # return an empty list - [] - end - request.destroy(playlist_tmp) # destroy the temporary request - playlist := result - end - - # Move function - def move (fromPos, toPos) = - countx = ref -1 # counter - fromx = ref (fromPos - 1) # position of item - tox = ref (toPos - 1) # position to move - msg = ref "" - msg := message('playlist', true, "Item #{fromPos} moved to #{toPos} in Playlist", get_task_number ('move'), "00", type='internal') - # check if we can move - if (toPos) > list.length(!playlist) - or (fromPos) > list.length(!playlist) - or toPos < 1 - or fromPos < 1 then - msg := message('playlist', false, "Moving item #{fromPos} to position #{toPos} is impossible.", get_task_number ('move'), "01", type='user', level="warning") - elsif toPos != fromPos then - # get the item to move - itemToMove = ref list.nth(!playlist, !fromx) - - # returns the resorted list - def resort (ret, el) = - countx := !countx + 1 - if !countx == !fromx then # das ist das Item, das verschoben wird - es wird uebersprungen - ret - elsif !countx == !tox then # Wir haben die Position erreicht, an der das zu verschiebende Item platziert wird - if !fromx < !tox then # aber entry wurde bereits uebersprungen - list.append(ret,[el, !itemToMove]) # also muss hinter dem aktuellen Element eingefuegt werden - else - list.append(ret,[!itemToMove, el]) # ...andernfalls davor - end - - else - list.append(ret,[el]) #Liste um den aktuellen Eintrag erweitern - end - end - playlist := list.fold(resort, [], !playlist) - end - !msg - end - - # method to delete an item from the list - def remove (index) = - countx = ref 0 - delx = ref (index - 1) - - def delete (ret, el) = - countx := !countx + 1 - if !countx == (!delx +1) then - ret # the position to be removed - else - list.append(ret,[el]) # append evereything else - end - end - - playlist := list.fold(delete, [], !playlist) - message(value=json_of(!playlist), 'playlist', true, "Item #{index} removed from Playlist", get_task_number ('remove'), "00", type='internal') - end - - # method to insert an item - def insert (~title='Unknown', ~time='00:00', ~pos='', uri) = - el = 'annotate:title="#{title}",time="#{time}",location="#{uri}":#{uri}' - playlist := list.append(!playlist,[el]) #Item erst mal an die Playlist anhaengen - if int_of_string(pos) > 0 then # Eine Position ist angegeben - result = move(list.length(!playlist), int_of_string(pos)) # Item dorthin verschieben - result_list = of_json(default=[('success','false')], result) # Die Ausgabe von "move" als assoziatives Array - if list.assoc('success', result_list) != "true" then # War move nicht erfolgreich? - result # ... dann geben wir die Ausgabe von move zurueck - else # ... andernfalls Erfolgsmeldung - message(value=json_of(!playlist), 'playlist', true, "#{title} item inserted into #{pos} in Playlist", get_task_number ('insert'), "00", type='internal') - end - elsif int_of_string(uri) > 0 then # uri ist ein int? Da hat der User was falsch gemacht... - message('playlist', true, "Syntax error: playlist.insert <pos> <uri> [<title> <time>]", get_task_number ('insert'), "01", type='user', level="info") - else # da auch, da ist pos 0 oder negativ - message('playlist', true, "Cannot insert #{title} at position #{pos}. Put it on the end.", get_task_number ('insert'), "02", type='user', level="info") - end - end - - # returns the remaining list - def getplaylist () = - - list.fold(foldplaylist, [], !playlist) - end - - def push (index) = - "Not implemented yet" - end - - # The reload function - def reload(~blank=false, ~skip=0, ~uri="") = - if uri != "" then - playlist_uri := uri - end - log(label=id,"Reloading playlist with URI #{!playlist_uri}") - has_stopped := false - load_playlist(skip=skip) - #if !error_message == 'OK' then - # message('playlist', true, 'Playlist #{!playlist_uri} loaded', get_task_number ('load'), '00', level="success") - #elsif !error_message == '!exist' then - # message('playlist', false, "Playlist #{!playlist_uri} does not exist", get_task_number ('load'), '01', level="warning", type="external") - #elsif !error_message == 'empty' then - # message('playlist', false, "Playlist #{!playlist_uri} is empty or wrong format", get_task_number ('load'), '02', level="warning", type="external") - #else - # message('playlist', false, "Playlist #{!playlist_uri} doesn't resolve.", get_task_number ('load'), '03', level="warning", type="external") - #end - end - log(label=id,"Loading playlist with URI #{!playlist_uri}") - # Load the playlist - load_playlist(skip=skip) - # Return - (((reload,flush),((move,(insert,remove)),(getplaylist,push))),source) -end - diff --git a/modules/liquidsoap/unused.pulse.liq b/modules/liquidsoap/unused.pulse.liq deleted file mode 100644 index f1a018955e0c107f094a84eeb7f8348b62a510fe..0000000000000000000000000000000000000000 --- a/modules/liquidsoap/unused.pulse.liq +++ /dev/null @@ -1,6 +0,0 @@ - -input_fs = single(id="fs", "/var/audio/fallback/output.flac") -input_http = input.http(id="http", "http://stream.fro.at/fro128.mp3") -linein_pulse_1 = input.pulseaudio(id="linein", device = input_device_0) -mixer = mix(id="mixer", [input_fs, input_http, linein_pulse_1]) -out := output.pulseaudio(id="lineout", mixer) diff --git a/modules/liquidsoap/unused.record.liq b/modules/liquidsoap/unused.record.liq deleted file mode 100644 index b2952201fb920e11f2f916dcbfd7283464a69356..0000000000000000000000000000000000000000 --- a/modules/liquidsoap/unused.record.liq +++ /dev/null @@ -1,159 +0,0 @@ -inst = if argv(1) != "" then string_of(argv(1)) else 'record' end -instance = ref inst - -%include "readini.liq" - -ignore(system('#{list.assoc("install_dir", ini)}/modules/soundengine/helpers/message.py -c #{!instance} -t sayAlive')) -exec_at(freq=20., pred={true}, {ignore(system('#{list.assoc("install_dir", ini)}/modules/soundengine/helpers/message.py -c #{!instance} -t sayAlive'))}) - -audiobase= if !instance == 'record' then list.assoc("audiobase", ini) else list.assoc("altaudiobase", ini) end -filenamepattern = ref audiobase^"/%Y-%m-%d/%Y-%m-%d-%H-%M.wav" -daemongroup = list.assoc("daemongroup", ini) -daemonuser = list.assoc("daemonuser", ini) -socketdir = list.assoc("socketdir", ini) -recinput = if !instance == 'record' then list.assoc("recinput", ini) else list.assoc("altrecinput", ini) end -recorder_device = if !instance == 'record' then list.assoc("recorder_device", ini) else list.assoc("altrecorder_device", ini) end -set("init.daemon",true) -set("init.daemon.change_user.group",daemongroup) -set("init.daemon.change_user.user",daemonuser) -set("server.socket",true) -set("server.socket.path",socketdir^"/"^!instance^".sock") -set("init.daemon.pidfile.path",socketdir^"/"^!instance^".pid") -set("init.daemon",true) -set("log.file",true) -set("log.file.path",list.assoc("logdir", ini)^"/"^!instance^".log") -set("log.file.perms",0o660) -set("log.level",4) - -# Der aktuelle Dateiname für die Aufnahme -recordingfile = ref "" -#wir definieren eine Referenz für die Stop-Funktion, die aber bisher noch nichts tun kann -stop_f = ref (fun () -> ()) -#bewahre uns davor, dass zweimal gleichzeitig die gleiche Date aufgenommen wird -block_dump = ref false - -# Stop dump - wir definieren die Funktion, die stop_f ausführt -def stop_dump() = - f = !stop_f - f () -end - -#Der input wie oben definiert -def get_input() - if recinput == 'soundcard' then - ## input ist Alsa - if recorder_device != '' then - input.alsa(device=recorder_device) - else - input.alsa() - end - - elsif recinput == 'nosound' then - mksafe(empty()) - else - ## input ein via config definierter Stream - mksafe(input.http(recinput)) - end -end - -#Wav header fixen und ggf. die Aufzeichnung beenden -def on_close(filename) - # es darf wieder aufgenommen werden - block_dump := false - # Korrekten WAV-Header schreiben - system("qwavheaderdump -F #{filename}") - # event dumpend feuern - ignore(system('#{list.assoc("install_dir", ini)}/modules/soundengine/helpers/message.py -c #{!instance} --task=setState -n dumpend -v #{filename}')) - log('#{list.assoc("install_dir", ini)}/modules/soundengine/helpers/message.py -c #{!instance} --task=setState -n dumpend -v #{filename}') - # Naechsten Dateinamen vormerken - recordingfile := list.hd(get_process_lines("date +#{!filenamepattern}")) - ignore(system('#{list.assoc("install_dir", ini)}/modules/soundengine/helpers/message.py -c #{!instance} --task=setState -n dumpfile -v #{!recordingfile}')) -end - -#Funktion gibt Auskunft welches File aktuell ist und wieviel Prozent bereits aufgenommen werden -def currecording() - curfile = !recordingfile - if curfile != "" then - procent_done = list.hd(get_process_lines("echo $(($(stat -c%s "^curfile^")/3174777))")) - "#{curfile},#{procent_done}" - else - "" - end -end - -#Funktion zum Start der Aufzeichnung -def start_dump() = - log('start dump') - # don't record twice - if !block_dump == false then - block_dump := true - # Der Input - Alsa oder Stream - input=get_input() - record = output.file( - id="recorder", - # Wav Stereo erzeugen - %wav(stereo=true), - perm = 0o664, - # die aktuell aufnehmende Datei in 'recordingfile' festhalten - on_start={ begin - recordingfile := list.hd(get_process_lines("date +#{!filenamepattern}")) - log('#{list.assoc("install_dir", ini)}/modules/soundengine/helpers/message.py -c #{!instance} --task=setState -n dumpfile -v #{!recordingfile}') - ignore(system('#{list.assoc("install_dir", ini)}/modules/soundengine/helpers/message.py -c #{!instance} --task=setState -n dumpfile -v #{!recordingfile}')) - end}, - # Beim Stoppen den Status zurücksetzen - on_stop={ignore(system('#{list.assoc("install_dir", ini)}/modules/soundengine/helpers/message.py -c #{!instance} --task=setState -n dumpfile -v ""'))}, - # Dateipfad - !filenamepattern, - # Funktion die beim Schließen der Datei aufgerufen wird - on_close=on_close, - # Alle 30 Minuten eine neue Datei - reopen_when={ if !instance == 'record' then int_of_float(gettimeofday()/60.) mod 30 == 0 else false end }, - # Der Input - input - ) - # Die Stopfunkton zeigt nun auf die Shutdown-Funktion der aktuellen Source - stop_f := fun () -> begin - log('stop recording') - # Aufnahme sauber beenden - ignore(server.execute('recorder.stop')) - # Source zerstören - source.shutdown(record) - # Variable zurücksetzen - recordingfile := "" - end - end -end - - -# Der Server wird durch 3 Funktionen bereichert -# Der User darf die Aufzeichnung manuell starten -server.register(namespace="record", - description="Start recording.", - usage="start", - "start", - fun (s) -> begin start_dump() "OK" end) - -# Der User darf die Aufzeichnung manuell stoppen -server.register(namespace="record", - description="Stop recording.", - usage="stop", - "stop", - fun (s) -> begin stop_dump() "OK" end) - -if !instance != 'record' then - # Der User darf einen Dateinamen für die Aufnahme definieren - server.register(namespace="record", - description="Define filename for output.", - usage="setfilename", - "setfilename", - fun (s) -> begin filenamepattern := audiobase^"/"^string_of(s) "OK" end) -end - -# Der USer kann sich über den Fortschritt der Aufnahme informieren -server.register(namespace="record", - description="Show current file.", - usage="curfile", - "curfile", - fun (s) -> currecording() ) - -output.dummy(blank(id="serve")) diff --git a/modules/liquidsoap/unused.simpleplayer.liq b/modules/liquidsoap/unused.simpleplayer.liq deleted file mode 100644 index c5dc9f1dec7a1f9086836b2033fca6d397b8f1ab..0000000000000000000000000000000000000000 --- a/modules/liquidsoap/unused.simpleplayer.liq +++ /dev/null @@ -1,30 +0,0 @@ -%include "/home/gg/PycharmProjects/aura/modules/liquidsoap/readini.liq" - -ini = read_ini("/etc/aura/aura.ini") - -set("log.file",true) -set("log.file.path",list.assoc("logdir", ini)^"/<script>.log") -#set("log.file.path", "<script>.log") -set("log.file.perms",0o660) -set("log.level",3) - -#fallback_audio_folder = list.assoc("fallback_audio_folder", ini) -#fallback_audio_folder = "/var/audio/fallback" - -# track_sensitive => fallback_folder track sensitivity -# max_blank => maximum time of blank from source -# min_noise => minimum duration of noise on source to switch back over -# threshold => power in dB under which the stream is considered silent - -#stream = fallback(track_sensitive=false, -# [ strip_blank(id="", max_blank=10., min_noise=10., threshold=0., once(input.alsa(id="sound_input", fallible=true, clock_safe=false))), -# playlist.safe(fallback_audio_folder) ]) - -stream = fallback(track_sensitive=false, - [ strip_blank(id="defaultstripper", max_blank=10., min_noise=10., threshold=0., single("/var/audio/fallback/music.flac")), - playlist.safe("/var/audio/fallback/NightmaresOnWax/Smokers Delight") ] ) - -#stream = single("/var/audio/fallback/music.flac") -output.alsa(id="player", device="hw:0,0", stream) - -#output.alsa(fallible=true, input.alsa(id="sound_input", fallible=true, clock_safe=false)) diff --git a/modules/liquidsoap/unused.stream.liq b/modules/liquidsoap/unused.stream.liq deleted file mode 100644 index 041ee83d99391ee618972b1eca79574497cb7969..0000000000000000000000000000000000000000 --- a/modules/liquidsoap/unused.stream.liq +++ /dev/null @@ -1,103 +0,0 @@ -#Create stream? -stream = list.assoc("stream", ini) -stream_type = list.assoc("stream_type", ini) -stream_bitrate = int_of_string(list.assoc("stream_bitrate", ini)) -stream_port = int_of_string(list.assoc("stream_port", ini)) -stream_mountpoint = list.assoc("stream_mountpoint", ini) -stream_user = list.assoc("stream_user", ini) -stream_password = list.assoc("stream_password", ini) -stream_host = list.assoc("stream_host", ini) -stream_url = list.assoc("stream_url", ini) -stream_name = list.assoc("stream_name", ini) -stream_genre = list.assoc("stream_genre", ini) -stream_description = list.assoc("stream_description", ini) - - -if stream != "" then - if stream_type == "icecast" then - - if stream_bitrate == 24 then - ignore(output.icecast(%mp3(bitrate = 24, samplerate = 22050), mount=stream_mountpoint, host=stream_host, port=stream_port, name=stream_name, url=stream_url, genre=stream_genre, description=stream_description, user=stream_user, password=stream_password, icy_metadata="true", fallible=true, s)) - - elsif stream_bitrate == 32 then - ignore(output.icecast(%mp3(bitrate = 32, samplerate = 22050), mount=stream_mountpoint, host=stream_host, port=stream_port, name=stream_name, url=stream_url, genre=stream_genre, description=stream_description, user=stream_user, password=stream_password, icy_metadata="true", fallible=true, s)) - - elsif stream_bitrate == 48 then - ignore(output.icecast(%mp3(bitrate = 48, samplerate = 22050), mount=stream_mountpoint, host=stream_host, port=stream_port, name=stream_name, url=stream_url, genre=stream_genre, description=stream_description, user=stream_user, password=stream_password, icy_metadata="true", fallible=true, s)) - - elsif stream_bitrate == 64 then - ignore(output.icecast(%mp3(bitrate = 64, samplerate = 44100), mount=stream_mountpoint, host=stream_host, port=stream_port, name=stream_name, url=stream_url, genre=stream_genre, description=stream_description, user=stream_user, password=stream_password, icy_metadata="true", fallible=true, s)) - - elsif stream_bitrate == 80 then - ignore(output.icecast(%mp3(bitrate = 80, samplerate = 44100), mount=stream_mountpoint, host=stream_host, port=stream_port, name=stream_name, url=stream_url, genre=stream_genre, description=stream_description, user=stream_user, password=stream_password, icy_metadata="true", fallible=true, s)) - - elsif stream_bitrate == 96 then - ignore(output.icecast(%mp3(bitrate = 96, samplerate = 44100), mount=stream_mountpoint, host=stream_host, port=stream_port, name=stream_name, url=stream_url, genre=stream_genre, description=stream_description, user=stream_user, password=stream_password, icy_metadata="true", fallible=true, s)) - - elsif stream_bitrate == 112 then - ignore(output.icecast(%mp3(bitrate = 112, samplerate = 44100), mount=stream_mountpoint, host=stream_host, port=stream_port, name=stream_name, url=stream_url, genre=stream_genre, description=stream_description, user=stream_user, password=stream_password, icy_metadata="true", fallible=true, s)) - - elsif stream_bitrate == 128 then - ignore(output.icecast(%mp3(bitrate = 128, samplerate = 44100), mount=stream_mountpoint, host=stream_host, port=stream_port, name=stream_name, url=stream_url, genre=stream_genre, description=stream_description, user=stream_user, password=stream_password, icy_metadata="true", fallible=true, s)) - - elsif stream_bitrate == 160 then - ignore(output.icecast(%mp3(bitrate = 160, samplerate = 44100), mount=stream_mountpoint, host=stream_host, port=stream_port, name=stream_name, url=stream_url, genre=stream_genre, description=stream_description, user=stream_user, password=stream_password, icy_metadata="true", fallible=true, s)) - - elsif stream_bitrate == 192 then - ignore(output.icecast(%mp3(bitrate = 192, samplerate = 44100), mount=stream_mountpoint, host=stream_host, port=stream_port, name=stream_name, url=stream_url, genre=stream_genre, description=stream_description, user=stream_user, password=stream_password, icy_metadata="true", fallible=true, s)) - - elsif stream_bitrate == 224 then - ignore(output.icecast(%mp3(bitrate = 224, samplerate = 44100), mount=stream_mountpoint, host=stream_host, port=stream_port, name=stream_name, url=stream_url, genre=stream_genre, description=stream_description, user=stream_user, password=stream_password, icy_metadata="true", fallible=true, s)) - - elsif stream_bitrate == 256 then - ignore(output.icecast(%mp3(bitrate = 256, samplerate = 44100), mount=stream_mountpoint, host=stream_host, port=stream_port, name=stream_name, url=stream_url, genre=stream_genre, description=stream_description, user=stream_user, password=stream_password, icy_metadata="true", fallible=true, s)) - - elsif stream_bitrate == 320 then - ignore(output.icecast(%mp3(bitrate = 320, samplerate = 44100), mount=stream_mountpoint, host=stream_host, port=stream_port, name=stream_name, url=stream_url, genre=stream_genre, description=stream_description, user=stream_user, password=stream_password, icy_metadata="true", fallible=true, s)) - - end - - elsif stream_type == "harbor" then - - if stream_bitrate == 24 then - ignore(output.harbor(%mp3(bitrate = 24, samplerate = 22050), user=stream_user, password=stream_password, id="stream", port=stream_port, url=stream_url, mount=stream_mountpoint, icy_metadata="true", fallible=true, s)) - - elsif stream_bitrate == 32 then - ignore(output.harbor(%mp3(bitrate = 32, samplerate = 22050), user=stream_user, password=stream_password, id="stream", port=stream_port, url=stream_url, mount=stream_mountpoint, icy_metadata="true", fallible=true, s)) - - elsif stream_bitrate == 48 then - ignore(output.harbor(%mp3(bitrate = 48, samplerate = 22050), user=stream_user, password=stream_password, id="stream", port=stream_port, url=stream_url, mount=stream_mountpoint, icy_metadata="true", fallible=true, s)) - - elsif stream_bitrate == 64 then - ignore(output.harbor(%mp3(bitrate = 64, samplerate = 44100), user=stream_user, password=stream_password, id="stream", port=stream_port, url=stream_url, mount=stream_mountpoint, icy_metadata="true", fallible=true, s)) - - elsif stream_bitrate == 80 then - ignore(output.harbor(%mp3(bitrate = 80, samplerate = 44100), user=stream_user, password=stream_password, id="stream", port=stream_port, url=stream_url, mount=stream_mountpoint, icy_metadata="true", fallible=true, s)) - - elsif stream_bitrate == 96 then - ignore(output.harbor(%mp3(bitrate = 96, samplerate = 44100), user=stream_user, password=stream_password, id="stream", port=stream_port, url=stream_url, mount=stream_mountpoint, icy_metadata="true", fallible=true, s)) - - elsif stream_bitrate == 112 then - ignore(output.harbor(%mp3(bitrate = 112, samplerate = 44100), user=stream_user, password=stream_password, id="stream", port=stream_port, url=stream_url, mount=stream_mountpoint, icy_metadata="true", fallible=true, s)) - - elsif stream_bitrate == 128 then - ignore(output.harbor(%mp3(bitrate = 128, samplerate = 44100), user=stream_user, password=stream_password, id="stream", port=stream_port, url=stream_url, mount=stream_mountpoint, icy_metadata="true", fallible=true, s)) - - elsif stream_bitrate == 160 then - ignore(output.harbor(%mp3(bitrate = 160, samplerate = 44100), user=stream_user, password=stream_password, id="stream", port=stream_port, url=stream_url, mount=stream_mountpoint, icy_metadata="true", fallible=true, s)) - - elsif stream_bitrate == 192 then - ignore(output.harbor(%mp3(bitrate = 192, samplerate = 44100), user=stream_user, password=stream_password, id="stream", port=stream_port, url=stream_url, mount=stream_mountpoint, icy_metadata="true", fallible=true, s)) - - elsif stream_bitrate == 224 then - ignore(output.harbor(%mp3(bitrate = 224, samplerate = 44100), user=stream_user, password=stream_password, id="stream", port=stream_port, url=stream_url, mount=stream_mountpoint, icy_metadata="true", fallible=true, s)) - - elsif stream_bitrate == 256 then - ignore(output.harbor(%mp3(bitrate = 256, samplerate = 44100), user=stream_user, password=stream_password, id="stream", port=stream_port, url=stream_url, mount=stream_mountpoint, icy_metadata="true", fallible=true, s)) - - elsif stream_bitrate == 320 then - ignore(output.harbor(%mp3(bitrate = 320, samplerate = 44100), user=stream_user, password=stream_password, id="stream", port=stream_port, url=stream_url, mount=stream_mountpoint, icy_metadata="true", fallible=true, s)) - - end - end -end \ No newline at end of file diff --git a/modules/liquidsoap/unused.test.liq b/modules/liquidsoap/unused.test.liq deleted file mode 100644 index e5c2c61e30d6c03201d023a5adcf17339193463b..0000000000000000000000000000000000000000 --- a/modules/liquidsoap/unused.test.liq +++ /dev/null @@ -1,8 +0,0 @@ -set("log.file.path", "./test.log") - -#input_alsa = input.alsa(bufferize=false) #, clock_safe=false) -#output.alsa(bufferize=false, input_alsa) - -input_pulse = input.pulseaudio() #, clock_safe=false) -output.pulseaudio(input_pulse) - diff --git a/modules/liquidsoap/unused.tester.liq b/modules/liquidsoap/unused.tester.liq deleted file mode 100644 index f6e3f384aa4d9cabaf7d5b43650efbad90349430..0000000000000000000000000000000000000000 --- a/modules/liquidsoap/unused.tester.liq +++ /dev/null @@ -1,157 +0,0 @@ -#!/usr/bin/liquidsoap - -%include "/etc/aura/readini.liq" -%include "/etc/aura/library.liq" -%include "/etc/aura/playlist.liq" - -inifile = '/etc/aura/aura.ini' -ini = read_ini(inifile) - -socketdir = list.assoc("socketdir", ini) - -# set player i/o devices -live_input_device = list.assoc("live_input_device", ini) -output_device = list.assoc("output_device", ini) - -# fallback settings -station_fallback_pool = list.assoc("station_fallback_pool", ini) -ignore(station_fallback_pool) -fallback_audio_folder = list.assoc("fallback_audio_folder", ini) -fallback_max_blank = float_of_string(list.assoc("fallback_max_blank", ini)) -fallback_min_noise = float_of_string(list.assoc("fallback_min_noise", ini)) -fallback_threshold = float_of_string(list.assoc("fallback_threshold", ini)) - -# channel names from config -channelnames = ref string.split(separator=',', list.assoc("channels", ini)) - -set("server.socket", true) -set("server.socket.path", socketdir^"/<script>.sock") -set("server.telnet", true) -set("server.telnet.port", 1234) - -# alsa settings -#set("alsa.alsa_buffer", 2048) -#set("alsa.periods", 0) -#set("alsa.buffer_length", 1) - -playlistrunning = ref false -# dynamic list of sources -sources = ref [] - -playlist_recorded = playlist.xml( - id='playlist', on_done=fun() -> begin ignore(system('#{list.assoc("install_dir", ini)}/modules/soundengine/helpers/message.py -c #{!instance} --task=setState -n playlistcurrent -v ""')) ignore(server.execute('mixer.select 0 false')) end, 'none') -# Die Source aus der Playlist -recorded = snd(playlist_recorded) - -# Skippen erlauben -add_skip_command(recorded) - -# User may load a XML-Playlist -server.register(namespace='playlist', - description="Load Playlist", - usage="load <uri>", - "load",fun (p) -> begin - reload_recorded(skip=0, uri=p) - end -) - -def get_station_fallback_pool() - #playlist.safe("/var/audio/fallback/NightmaresOnWax/Smokers Delight") - playlist.safe(station_fallback_pool) - #if station_fallback_pool != "" then - # print("fallbackfolder chosen: "^station_fallback_pool) - # playlist.safe(station_fallback_pool) - #else - # print("no fallbackfolder chosen. blanking 20s.") - # blank(duration=20.0) - #end -end - -def get_live_input() - if live_input_device == "soundcard" then - print("autodetect input device") - #strip_blank(id="input_alsa_strip", max_blank=fallback_max_blank, min_noise=fallback_min_noise, threshold=fallback_threshold, - input.alsa(id="input_alsa", bufferize=false) #) - else - print("manually set device: "^live_input_device) - #strip_blank(id="input_alsa_strip", max_blank=fallback_max_blank, min_noise=fallback_min_noise, threshold=fallback_threshold, - input.alsa(id="input_alsa", bufferize=false, device=live_input_device) #) - end -end - -def get_input_fs() - fallback(track_sensitive=false, - [ single("/var/audio/fallback/music.flac"), get_station_fallback_pool() ] ) -end - -def get_input_stream() - url = "http://stream.fro.at/fro128.mp3" - #url = "http://mp3stream1.apasf.apa.at:8000/listen.pls" - mksafe(strip_blank(id="stream_strip", input.http(id="stream", url))) -end - -# create playlist source with smart crossfade -#filesystem_input = fallback(id="filesystem_input", track_sensitive=false, [ -# get_input(), -# get_fallback()]) - -# filesystem_input -#fs_input = get_input_fs() -fs_input = fallback(track_sensitive=false, - [ single("/var/audio/fallback/music.flac"), get_station_fallback_pool() ] ) - -# create a source for stream overtakes -stream_input = get_input_stream() -#url = "http://stream.fro.at/fro64.mp3" -#url = "http://mp3stream1.apasf.apa.at:8000/listen.pls" -#stream_input = strip_blank(id="httpsttrip", input.http(id="stream", url)) - -# and the studio input -#live_input = get_live_input() -live_input = input.alsa(id="input_alsa", bufferize=false) - -# API HOWTO: -# mixer.inputs -# stream.stop -# stream.url [url] -# stream.start -# mixer.select [streamovertake] true - -def addChannel(source) - sources := list.append([source], !sources) -end - -addChannel(fs_input) -addChannel(stream_input) -addChannel(live_input) - -mixer = mix(id = "mixer", !sources) - -#final_stream = fallback(id="station_fallback", [mixer, playlist.safe("/var/audio/fallback/NightmaresOnWax/Smokers Delight")] - -#server.register(namespace='mixer', -# description="Load Playlist", -# usage="select <num>", -# "load",fun (p) -> begin -# reload_recorded(skip=0, uri=p) -# end -#) - -ignore(mixer) -ignore(fs_input) -ignore(live_input) -ignore(addChannel) -ignore(stream_input) -ignore(channelnames) -ignore(output_device) -ignore(playlistrunning) -ignore(fallback_max_blank) -ignore(fallback_min_noise) -ignore(fallback_threshold) -ignore(fallback_audio_folder) - -print("output_device: "^output_device) -output.alsa(id="alsaout", bufferize=false, device=output_device, mixer) - -#ret = server.execute('help') -#print(ret) diff --git a/modules/scheduling/calendar.py b/modules/scheduling/calendar.py index fabc7fc65fb76f1bb1de2a39fdd244e1623e48c6..01bbfec278709e30b55891ea85f77d588a8120f2 100644 --- a/modules/scheduling/calendar.py +++ b/modules/scheduling/calendar.py @@ -176,11 +176,10 @@ class AuraCalendarService(threading.Thread): def store_schedule_playlist(self, schedule_db, schedule, playlistname, isfallbackplaylist=False): playlist = schedule[playlistname] - info = "Trying to store schedule playlist (" + playlistname + ") for " + schedule_db.show_name + info = "Schedule playlist (" + playlistname + ") for " + schedule_db.show_name + " stored" warning = "No scheduleentries for playlist #" + str(playlist['playlist_id']) + " in schedule #" + str(schedule_db.schedule_id) + " found" entrynum = 0 - self.logger.info(info) if "entries" in playlist: lastentry = None @@ -190,6 +189,8 @@ class AuraCalendarService(threading.Thread): if lastentry is None: self.logger.warning(warning) + else: + self.logger.info(info) else: self.logger.warning(warning) @@ -278,7 +279,6 @@ class AuraCalendarService(threading.Thread): json_response = self.__fetch_data__(servicetype) if not json_response: - self.logger.info("Using hardcoded playlists") use_testdata = True for entry in fetched_schedule_entries: @@ -300,6 +300,8 @@ class AuraCalendarService(threading.Thread): else: # pool playlist json_response = '{"playlist_id":' + str(schedule[id_name]) + ',"entries":[{"source":"pool:///chillout"}]}' + self.logger.info("Using hardcoded playlists: "+json_response) + try: schedule_entries = simplejson.loads(json_response) except Exception as e: diff --git a/modules/scheduling/scheduler.py b/modules/scheduling/scheduler.py index d17518b19fa8a2142ec8d9e243eda435ff45cf0d..589d9bc202ab5b97539cae20d25baf5a8b5b08e9 100644 --- a/modules/scheduling/scheduler.py +++ b/modules/scheduling/scheduler.py @@ -101,7 +101,10 @@ class AuraScheduler(ExceptionLogger, threading.Thread): # load error messages error_file = self.config.get("install_dir") + "/errormessages/scheduler_error.js" - self.error_data = simplejson.load(open(error_file)) + f = open(error_file) + self.error_data = simplejson.load(f) + f.close() + # init database ? self.init_database() diff --git a/testing/test.py b/testing/test.py index ef4405919e493613917e802de1fc8b55be18355f..5a9ef6a380d94c9021e04aed605b7d6914ba1d2e 100644 --- a/testing/test.py +++ b/testing/test.py @@ -9,7 +9,12 @@ from libraries.base.logger import AuraLogger from libraries.base.config import AuraConfig # libraries.database from libraries.database.broadcasts import Schedule, ScheduleEntry, TrackService +# libraries.security +from libraries.security.user import AuraUser +# modules +from modules.communication.liquidsoap.communicator import LiquidSoapCommunicator +from modules.scheduling.scheduler import AuraScheduler class TestLogger(unittest.TestCase): aura_logger = None @@ -82,10 +87,58 @@ class TestTrackService(unittest.TestCase): self.track_service = TrackService() def test_track_service(self): - day = datetime.strptime('19.03.2018', '%d.%m.%Y') + day = datetime.strptime("19.03.2018", "%d.%m.%Y") entry = self.track_service.select_by_day(day) self.assertIsNotNone(entry) self.assertIsInstance(entry, list) + +class TestAuraUser(unittest.TestCase): + aura_user = None + + def setUp(self): + self.aura_user = AuraUser() + + def test_add_user(self): + username = "user" + password = "password" + role = "admin" + + login_cnt = len(self.aura_user.getLogins()) + + # insert user + key = self.aura_user.insertUser(username, password, role) + + self.assertGreaterEqual(len(self.aura_user.getLogins()), login_cnt) + + # selecting user and check data + user = self.aura_user.getUserByKey(key) + + self.assertEqual(user["username"], username) + # TODO: no encrypted storage.., but usermgm not really in use + self.assertEqual(user["password"], password) + self.assertEqual(user["role"], role) + + +class TestLQSComm(unittest.TestCase): + comm = None + + def setUp(self): + # wosn do passiert? + p = AuraConfig().config + + self.comm = LiquidSoapCommunicator(p) + self.comm.scheduler = AuraScheduler(p) + + self.comm.init_player() + + + def test_get_active_channel(self): + active_channel = self.comm.get_active_channel() + + print(active_channel) + + + if __name__ == '__main__': unittest.main() \ No newline at end of file