diff --git a/libraries/database/broadcasts.py b/libraries/database/broadcasts.py index a93b8d11a8d31a1c313c6cf259926f0801d2bcd9..03f47cab52ec3b3023a3dc14429f41519c0f3a69 100644 --- a/libraries/database/broadcasts.py +++ b/libraries/database/broadcasts.py @@ -38,6 +38,8 @@ from sqlalchemy import create_engine from libraries.enum.auraenumerations import ScheduleEntryType from aura import DB +from modules.base.simpleutil import SimpleUtil + class AuraDatabaseModel(): @@ -218,11 +220,31 @@ class Schedule(DB.Model, AuraDatabaseModel): return all_entries + @hybrid_property + def start_unix(self): + """ + Start time of the schedule in UNIX time. + """ + return time.mktime(self.schedule_start.timetuple()) + + + @hybrid_property + def end_unix(self): + """ + End time of the schedule in UNIX time. + """ + return time.mktime(self.schedule_end.timetuple()) + + def __str__(self): """ String representation of the object. """ - return "ID#%s [Show: %s, ShowID: %s]" % (str(self.schedule_id), self.show_name, str(self.show_id)) + time_start = SimpleUtil.fmt_time(self.start_unix) + time_end = SimpleUtil.fmt_time(self.end_unix) + return "ID#%s [Show: %s, ShowID: %s | %s - %s ]" % (str(self.schedule_id), self.show_name, str(self.show_id), time_start, time_end) + + # ------------------------------------------------------------------------------------------ # class Playlist(DB.Model, AuraDatabaseModel): @@ -324,13 +346,12 @@ class Playlist(DB.Model, AuraDatabaseModel): """ String representation of the object. """ - time_start = self.fmt_time(self.start_unix) - time_end = self.fmt_time(self.end_unix) - return "ID#%s [items: %s, start: %s, end: %s]" % (str(self.playlist_id), str(self.entry_count), str(time_start), str(time_end)) + time_start = SimpleUtil.fmt_time(self.start_unix) + time_end = SimpleUtil.fmt_time(self.end_unix) + return "ID#%s [items: %s | %s - %s]" % (str(self.playlist_id), str(self.entry_count), str(time_start), str(time_end)) + - def fmt_time(self, timestamp): - return datetime.datetime.fromtimestamp(timestamp).strftime('%H:%M:%S') # ------------------------------------------------------------------------------------------ # class PlaylistEntry(DB.Model, AuraDatabaseModel): @@ -386,18 +407,30 @@ class PlaylistEntry(DB.Model, AuraDatabaseModel): elif self.cleansource == "4": return ScheduleEntryType.LIVE_4 + def get_next_entries(self): + """ + Retrieves all following entries as part of the current entries playlist. + + Returns: + (List): List of PlaylistEntry + """ + next_entries = [] + for entry in self.playlist.entries: + if entry.entry_start > self.entry_start: + next_entries.append(entry) + return next_entries + def __str__(self): """ String representation of the object. """ - time_start = self.fmt_time(self.start_unix) - time_end = self.fmt_time(self.end_unix) + time_start = SimpleUtil.fmt_time(self.start_unix) + time_end = SimpleUtil.fmt_time(self.end_unix) track = self.filename[-15:] return "PlaylistEntry ID#%s [%s - %s | %ssec | Track: ...%s]" % (str(self.artificial_id), time_start, time_end, self.duration, track) - def fmt_time(self, timestamp): - return datetime.datetime.fromtimestamp(timestamp).strftime('%H:%M:%S') + # ------------------------------------------------------------------------------------------ # class PlaylistEntryMetaData(DB.Model, AuraDatabaseModel):