]> git.0d.be Git - django-panik-nonstop.git/blob - nonstop/utils.py
f44895b01f9ca5cd12ca1ca321576369e18b3ebc
[django-panik-nonstop.git] / nonstop / utils.py
1 import datetime
2
3 from .models import Track, SomaLogLine
4
5
6 def get_current_nonstop_track():
7     try:
8         soma_log_line = SomaLogLine.objects.select_related().order_by('-play_timestamp')[0]
9     except IndexError:
10         # nothing yet
11         return {}
12     if soma_log_line.play_timestamp < (datetime.datetime.now() - datetime.timedelta(hours=1)):
13         # last known line is way too old
14         return {}
15     if not soma_log_line.on_air:
16         # nonstop should be on air but it's not :/
17         return {}
18     d = {}
19     current_nonstop_file = soma_log_line.filepath
20     if not 'Tranches/' in current_nonstop_file.filepath and (
21             not 'tracks/' in current_nonstop_file.filepath):
22         # nonstop is playing but it's not a nonstop track :/
23         return {}
24     current_track = soma_log_line.filepath.track
25     if current_track is None:
26         # nonstop is playing a nonstop track, but it's unknown :/
27         return {}
28     d = {'track_title': current_track.title}
29     if current_track.artist:
30         d['track_artist'] = current_track.artist.name
31     return d