Commit 13588aaf authored by David Trattnig's avatar David Trattnig
Browse files

No caching of current playlist. engine-clock#1

parent 57ba7f64
......@@ -23,6 +23,7 @@ import requests
from modules.base.utils import SimpleUtil as SU
from modules.base.models import Playlist
class TrackServiceHandler():
......@@ -32,7 +33,6 @@ class TrackServiceHandler():
logger = None
config = None
soundsystem = None
last_playlist = None
def __init__(self, config, soundsystem):
......@@ -85,64 +85,60 @@ class TrackServiceHandler():
"""
Posts the current and next show information to the Engine API.
"""
current_playlist = entry.playlist
if current_playlist == self.last_playlist:
self.logger.info("Playlist didn't change since last update.")
else:
self.last_playlist = current_playlist
current_schedule = current_playlist.schedule
next_schedule = self.soundsystem.scheduler.get_next_schedules(1)
if next_schedule: next_schedule = next_schedule[0]
data = dict()
data["engine_source"] = self.config.get("api_engine_number")
if current_playlist:
data["current_playlist"] = dict()
data["current_playlist"]["playlist_id"] = current_playlist.playlist_id
data["current_playlist"]["entries"] = []
for e in current_playlist.entries:
entry = dict()
entry["track_start"] = e.entry_start
entry["track_artist"] = e.meta_data.artist
entry["track_album"] = e.meta_data.album
entry["track_title"] = e.meta_data.title
entry["track_num"] = e.entry_num
entry["track_duration"] = e.duration
entry["track_type"] = e.get_type().numeric
entry = SU.clean_dictionary(entry)
data["current_playlist"]["entries"].append(entry)
if current_schedule:
cs = dict()
cs["schedule_id"] = current_schedule.schedule_id
cs["schedule_start"] = current_schedule.schedule_start
cs["schedule_end"] = current_schedule.schedule_end
cs["show_id"] = current_schedule.show_id
cs["show_name"] = current_schedule.show_name
cs["playlist_id"] = current_schedule.playlist_id
cs["fallback_type"] = current_schedule.fallback_state.id
cs = SU.clean_dictionary(cs)
data["current_schedule"] = cs
if next_schedule:
ns = dict()
ns["schedule_id"] = next_schedule.schedule_id
ns["schedule_start"] = next_schedule.schedule_start
ns["schedule_end"] = next_schedule.schedule_end
ns["show_id"] = next_schedule.show_id
ns["show_name"] = next_schedule.show_name
ns["playlist_id"] = next_schedule.playlist_id
ns["fallback_type"] = next_schedule.fallback_state.id
ns = SU.clean_dictionary(ns)
data["next_schedule"] = ns
data = SU.clean_dictionary(data)
self.logger.info("Posting clock info update to Engine API...")
url = self.config.get("api_engine_store_clock")
headers = {'content-type': 'application/json'}
body = json.dumps(data, indent=4, sort_keys=True, default=str)
response = requests.put(url, data=body, headers=headers)
self.logger.info("Engine API response: %s" % response.status_code)
\ No newline at end of file
current_playlist = self.soundsystem.scheduler.get_active_playlist()
current_schedule = current_playlist.schedule
next_schedule = self.soundsystem.scheduler.get_next_schedules(1)
if next_schedule: next_schedule = next_schedule[0]
data = dict()
data["engine_source"] = self.config.get("api_engine_number")
if current_playlist:
data["current_playlist"] = dict()
data["current_playlist"]["playlist_id"] = current_playlist.playlist_id
data["current_playlist"]["entries"] = []
for e in current_playlist.entries:
entry = dict()
entry["track_start"] = e.entry_start
entry["track_artist"] = e.meta_data.artist
entry["track_album"] = e.meta_data.album
entry["track_title"] = e.meta_data.title
entry["track_num"] = e.entry_num
entry["track_duration"] = e.duration
entry["track_type"] = e.get_type().numeric
entry = SU.clean_dictionary(entry)
data["current_playlist"]["entries"].append(entry)
if current_schedule:
cs = dict()
cs["schedule_id"] = current_schedule.schedule_id
cs["schedule_start"] = current_schedule.schedule_start
cs["schedule_end"] = current_schedule.schedule_end
cs["show_id"] = current_schedule.show_id
cs["show_name"] = current_schedule.show_name
cs["playlist_id"] = current_schedule.playlist_id
cs["fallback_type"] = current_schedule.fallback_state.id
cs = SU.clean_dictionary(cs)
data["current_schedule"] = cs
if next_schedule:
ns = dict()
ns["schedule_id"] = next_schedule.schedule_id
ns["schedule_start"] = next_schedule.schedule_start
ns["schedule_end"] = next_schedule.schedule_end
ns["show_id"] = next_schedule.show_id
ns["show_name"] = next_schedule.show_name
ns["playlist_id"] = next_schedule.playlist_id
ns["fallback_type"] = next_schedule.fallback_state.id
ns = SU.clean_dictionary(ns)
data["next_schedule"] = ns
data = SU.clean_dictionary(data)
self.logger.info("Posting clock info update to Engine API...")
url = self.config.get("api_engine_store_clock")
headers = {'content-type': 'application/json'}
body = json.dumps(data, indent=4, sort_keys=True, default=str)
response = requests.put(url, data=body, headers=headers)
self.logger.info("Engine API response: %s" % response.status_code)
\ No newline at end of file
......@@ -343,6 +343,17 @@ class AuraScheduler(threading.Thread):
return next_schedules
def get_active_playlist(self):
"""
Retrieves the currently playing playlist.
Returns:
(Playlist): The resolved playlist
"""
schedule = self.get_active_schedule()
playlist = self.fallback_manager.resolve_playlist(schedule)
return playlist
# FIXME Review relevance.
def get_act_programme_as_string(self):
......
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