Commit f32c72ed authored by David Trattnig's avatar David Trattnig
Browse files

Common model attribute for files and streams.

parent ace669ae
......@@ -419,7 +419,7 @@ class PlaylistEntry(DB.Model, AuraDatabaseModel):
uri = Column(String(1024))
duration = Column(BigInteger)
filename = Column(String(1024))
source = Column(String(1024))
entry_start = Column(DateTime)
queue_state = None # Assigned when entry is about to be queued
channel = None # Assigned when entry is actually played
......@@ -510,8 +510,8 @@ class PlaylistEntry(DB.Model, AuraDatabaseModel):
"""
time_start = SimpleUtil.fmt_time(self.start_unix)
time_end = SimpleUtil.fmt_time(self.end_unix)
track = self.filename[-25:]
return "PlaylistEntry #%s [%s - %s | %ssec | Track: ...%s]" % (str(self.artificial_id), time_start, time_end, self.duration, track)
track = self.source[-25:]
return "PlaylistEntry #%s [%s - %s | %ssec | Source: ...%s]" % (str(self.artificial_id), time_start, time_end, self.duration, track)
......@@ -715,7 +715,7 @@ class SingleEntry(DB.Model, AuraDatabaseModel):
# Data
uri = Column(String(1024))
duration = Column(BigInteger)
filename = Column(String(1024))
source = Column(String(1024))
entry_start = Column(DateTime)
......@@ -771,8 +771,8 @@ class SingleEntry(DB.Model, AuraDatabaseModel):
"""
time_start = SimpleUtil.fmt_time(self.start_unix)
time_end = SimpleUtil.fmt_time(self.end_unix)
track = self.filename[-25:]
return "SingleEntry #%s [%s - %s | %ssec | Track: ...%s]" % (str(self.id), time_start, time_end, self.duration, track)
track = self.source[-25:]
return "SingleEntry #%s [%s - %s | %ssec | Source: ...%s]" % (str(self.id), time_start, time_end, self.duration, track)
......@@ -895,7 +895,7 @@ class SingleEntryMetaData(DB.Model, AuraDatabaseModel):
#
# uri = Column(String(1024))
#
# filename = ""
# source = ""
# cleansource = ""
# cleanprotocol = ""
# type = None
......
......@@ -34,6 +34,7 @@ import logging
from mutagen.flac import FLAC
from datetime import datetime, timedelta
from modules.base.utils import SimpleUtil
from modules.database.model import Schedule, Playlist, PlaylistEntry, PlaylistEntryMetaData
from modules.communication.redis.messenger import RedisMessenger
from modules.scheduling.calender_fetcher import CalendarFetcher
......@@ -230,13 +231,13 @@ class AuraCalendarService(threading.Thread):
playlist_db.store(havetoadd, commit=True)
if playlist_db.entry_count > 0:
self.store_playlist_entries(playlist_db, fetched_playlist)
self.store_playlist_entries(schedule_db, playlist_db, fetched_playlist)
return playlist_db
def store_playlist_entries(self, playlist_db, fetched_playlist):
def store_playlist_entries(self, schedule_db, playlist_db, fetched_playlist):
"""
Stores the playlist entries to the database.
"""
......@@ -250,19 +251,32 @@ class AuraCalendarService(threading.Thread):
entry_db = PlaylistEntry()
havetoadd = True
# Nano-seconds to seconds
duration = int(float(entry["file"]["duration"]) / 1000000000)
entry_db.duration = duration
entry_db.entry_start = datetime.fromtimestamp(time_marker)
entry_db.artificial_playlist_id = playlist_db.artificial_id
entry_db.entry_num = entry_num
entry_db.uri = entry["uri"]
entry_db.filename = entry["filename"]
if "file" in entry and duration in entry["file"]:
# Convert nano-seconds to seconds
duration = int(float(entry["file"]["duration"]) / 1000000000)
# except Exception:
else:
# No duration means it's playing until the end of the schedule
self.logger.debug("Missing duration - setting duration of entry to end-of-schedule")
duration = SimpleUtil.timestamp(schedule_db.schedule_end) - time_marker
entry_db.duration = duration
if "uri" in entry:
# FIXME Refactor mix of uri/filename/file/source
entry_db.uri = entry["uri"]
entry_db.source = entry["uri"]
if "filename" in entry:
entry_db.source = entry["filename"]
entry_db.store(havetoadd, commit=True)
self.store_playlist_entry_metadata(entry_db, entry["file"]["metadata"])
if "file" in entry:
self.store_playlist_entry_metadata(entry_db, entry["file"]["metadata"])
entry_num = entry_num + 1
time_marker += duration
......@@ -282,7 +296,7 @@ class AuraCalendarService(threading.Thread):
metadata_db.artificial_entry_id = entry_db.artificial_id
if "artist" not in metadata:
self.logger.warning("Artist not found in metadata for track '%s'. Setting to ''" % entry_db.filename)
self.logger.warning("Artist not found in metadata for track '%s'. Setting to ''" % entry_db.source)
metadata_db.artist = ""
else:
metadata_db.artist = metadata["artist"]
......@@ -291,7 +305,7 @@ class AuraCalendarService(threading.Thread):
metadata_db.album = metadata["album"]
if "artist" not in metadata:
self.logger.warning("Title not found in metadata for track '%s'. Setting to 'n/a'" % entry_db.filename)
self.logger.warning("Title not found in metadata for track '%s'. Setting to 'n/a'" % entry_db.source)
metadata_db.artist = "n/a"
else:
metadata_db.artist = metadata["artist"]
......
......@@ -213,7 +213,7 @@ class FallbackManager:
playlist = playlist[0]
if playlist and playlist.entries:
for entry in playlist.entries:
playlist_files += entry.filename + "\n"
playlist_files += entry.source + "\n"
return playlist_files
......
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