Commit d2d1bd61 authored by fred's avatar fred

add utility function to get currently playing track

parent 0497e624
import datetime
from .models import Track, SomaLogLine
def get_current_nonstop_track():
try:
soma_log_line = SomaLogLine.objects.select_related().order_by('-play_timestamp')[0]
except IndexError:
# nothing yet
return {}
if soma_log_line.play_timestamp < (datetime.datetime.now() - datetime.timedelta(hours=1)):
# last known line is way too old
return {}
if not soma_log_line.on_air:
# nonstop should be on air but it's not :/
return {}
d = {}
current_nonstop_file = soma_log_line.filepath
if not 'Tranches/' in current_nonstop_file.filepath:
# nonstop is playing but it's not a nonstop track :/
return {}
current_track = soma_log_line.filepath.track
if current_track is None:
# nonstop is playing a nonstop track, but it's unknown :/
return {}
d = {'track_title': current_track.title}
if current_track.artist:
d['track_artist'] = current_track.artist.name
return d
Markdown is supported
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