Skip to content
Snippets Groups Projects
Commit 021201e2 authored by David Trattnig's avatar David Trattnig
Browse files

Query current trackservice entry.

parent 74f27c7f
No related branches found
No related tags found
No related merge requests found
......@@ -380,6 +380,10 @@ class PlaylistEntry(DB.Model, AuraDatabaseModel):
def select_playlistentry_for_playlist(artificial_playlist_id, entry_num):
return DB.session.query(PlaylistEntry).filter(PlaylistEntry.artificial_playlist_id == artificial_playlist_id, PlaylistEntry.entry_num == entry_num).first()
@hybrid_property
def entry_end(self):
return self.entry_start + datetime.timedelta(seconds=self.duration)
@hybrid_property
def start_unix(self):
return time.mktime(self.entry_start.timetuple())
......@@ -501,6 +505,7 @@ class TrackService(DB.Model, AuraDatabaseModel):
# Foreign keys
track_start = Column(DateTime)
track_end = Column(DateTime)
artificial_schedule_id = Column(Integer, ForeignKey("schedule.id"))
artificial_playlist_entry_id = Column(Integer, ForeignKey("playlist_entry.artificial_id"), nullable=True)
single_entry_id = Column(Integer, ForeignKey("single_entry.id"), nullable=True)
......@@ -518,6 +523,8 @@ class TrackService(DB.Model, AuraDatabaseModel):
Initializes a trackservice entry based on a playlist entry.
"""
self.track_start = datetime.datetime.now()
if entry.duration:
self.track_end = self.track_start + datetime.timedelta(seconds=entry.duration)
self.fallback_type = fallback_type
if fallback_type < 4:
......@@ -563,8 +570,11 @@ class TrackService(DB.Model, AuraDatabaseModel):
"""
Selects the currently playing track.
"""
now = datetime.datetime.now()
DB.session.commit() # Required since independend session is used.
track = DB.session.query(TrackService).filter(func.max(TrackService.id)).first()
track = DB.session.query(TrackService).\
filter(TrackService.track_start <= str(now), TrackService.track_end > str(now)).\
order_by(TrackService.track_start.desc()).first()
return track
......@@ -640,6 +650,10 @@ class SingleEntry(DB.Model, AuraDatabaseModel):
entry_start = Column(DateTime)
@hybrid_property
def entry_end(self):
return self.entry_start + datetime.timedelta(seconds=self.duration)
@hybrid_property
def start_unix(self):
return time.mktime(self.entry_start.timetuple())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment