Commit 28778a46 authored by David Trattnig's avatar David Trattnig
Browse files

Trackservice: Fallback updates.

parent 97c37997
......@@ -54,6 +54,7 @@ class RedisChannel(Enum):
GNF_REPLY = "get_next_file_reply"
IPE_REPLY = "insert_playlist_entry_reply"
IP_REPLY = "init_player_reply"
TS_REPLY = "track_service_reply"
MPE_REPLY = "move_playlist_entry_reply"
PMQ_REPLY = "print_message_queue_reply"
RDB_REPLY = "recreate_database_reply"
......@@ -73,8 +74,9 @@ class ScheduleEntryType(Enum):
class FallbackType(Enum):
SHOW = "show" # the first played when the show playlist fails
TIMESLOT = "timeslot" # the second played when timeslot fallback fails
STATION = "station" # the last played when everything else fails
TIMESLOT = "timeslot" # the second played when show fallback fails
class TimerType(Enum):
......
......@@ -91,6 +91,9 @@ class Padavan:
elif self.args.init_player:
self.init_player()
elif self.args.adapt_trackservice_title:
self.adapt_trackservice_title(self.args.adapt_trackservice_title)
elif self.args.recreatedb:
self.recreatedb()
......@@ -203,9 +206,23 @@ class Padavan:
self.stringreply += "\nConnection to redis: " + TerminalColors.RED.value + " " + str(connection_status["redis"]) + TerminalColors.ENDC.value
# ------------------------------------------------------------------------------------------ #
def init_player(self):
"""
Initializes the player on Liquidsaop startup.
"""
self.stringreply = self.send_and_wait_redis("aura", "init_player", RedisChannel.IP_REPLY)
def adapt_trackservice_title(self, info):
"""
Updates the tracks-service with the info on currently played fallback track.
"""
self.stringreply = self.send_and_wait_redis("aura", "adapt_trackservice_title " + info, RedisChannel.GNF_REPLY)
# ------------------------------------------------------------------------------------------ #
def recreatedb(self):
print("YOU WILL GET PROBLEMS DUE TO DATABASE BLOCKING IF aura.py IS RUNNING! NO CHECKS IMPLEMENTED SO FAR!")
......
......@@ -174,6 +174,15 @@ class ServerRedisAdapter(threading.Thread, RedisMessenger):
#playlist = playlist[0:len(playlist)-8]
self.execute(RedisChannel.GNF_REPLY.value, self.scheduler.get_next_file_for, playlist)
elif item["data"].find("adapt_trackservice_title") >= 0:
artist = item["data"].split("|+|+|")[1]
title = item["data"].split("|+|+|")[2]
if not artist:
artist = "n/a"
if not title:
title = "n/a"
self.execute(RedisChannel.TS_REPLY.value, self.scheduler.adapt_trackservice_title, artist, title)
elif item["data"] == "recreate_db":
self.execute(RedisChannel.RDB_REPLY.value, self.scheduler.recreate_database)
......@@ -184,9 +193,12 @@ class ServerRedisAdapter(threading.Thread, RedisMessenger):
raise RedisConnectionException("ServerRedisAdapter Cannot understand command: " + item["data"])
# ------------------------------------------------------------------------------------------ #
def execute(self, channel, f, param=None):
if param:
reply = f(param)
def execute(self, channel, f, param1=None, param2=None):
if param1:
if param2:
reply = f(param1, param2)
else:
reply = f(param1)
else:
reply = f()
......
......@@ -298,6 +298,15 @@ class RedisMessenger():
return next.decode('utf-8')
# ------------------------------------------------------------------------------------------ #
def adapt_trackservice_title(self, info):
result = self.rstore.db.get('adapt_trackservice_title')
if result is None:
result = b""
return result.decode('utf-8')
# ------------------------------------------------------------------------------------------ #
def set_next_file_for(self, playlisttype, file):
self.rstore.db.set("next_" + playlisttype + "file", file)
......
......@@ -299,6 +299,20 @@ class AuraScheduler(ExceptionLogger, threading.Thread):
return file
def adapt_trackservice_title(self, artist, title):
"""
Updates the track-service entry with the info from a fallback track/playlist.
"""
scheduled_entry = self.get_active_entry()
# TODO UPDATE LOGIC
msg = "Track Service active track '%s' updated with fallback source '%s - %s'!" % (scheduled_entry, artist, title)
self.logger.info(msg)
return msg
#
# PRIVATE METHODS
......
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