def commit_queued_song(song_id): cur_song = _session.query(Playlist).filter(Playlist.song_id == song_id, Playlist.queued == False).order_by("id asc").first() if (cur_song != None): cur_song.queued = True _session.add(cur_song) _session.commit() else: sys.stderr.write("commit_playing_song: INVALID SONG COMMITED!\n")
def initialize_playlist(): queued_but_not_played_songs = ( _session.query(Playlist).filter(Playlist.play_time == None, Playlist.queued == True).all() ) for song in queued_but_not_played_songs: song.queued = False _session.add(song) _session.commit()
def run(): try: # pesnicke, co sa prave prehrava nastavime cas, kedy sa zacala prehravat, cize aktualny cas cur_song = ( _session.query(Playlist) .filter(Playlist.song_id == sys.argv[1], Playlist.play_time == None) .order_by("id asc") .first() ) cur_song.play_time = datetime.datetime.now() _session.add(cur_song) _session.commit() except: print("FAILED TO UPDATE RECORD IN TABLE PLAYLIST", sys.exc_info()[0])
def generate_next_song(): songs = [] try: songs = _session.query(Playlist.song_id).filter(Playlist.queued == False).order_by("id asc").all() songs = [song_id for (song_id,) in songs] except: print("failed to connect to db") finally: while (len(songs) < playlist_length): #naplnenie playlistu next_song = pick_next_song() songs.append(next_song.id) _session.add(Playlist(next_song,None,False)) #pridanie songu do databazy bez casu prehrania, kedze este sa len ide prehrat update_current_rating() _session.commit() commit_queued_song(songs[0]) #nastavime danemu songu, ze je uz zaradeny vo fronte, kedze sme ho poslali printom do liquidsoapu print(path_to_song(songs[0]))
def update_current_rating(): try: songs = _session.query(Song).all() for song in songs: if (song.current_rating < song.rating_max): #keby requesty sposobili, ze current_rating bude vacsi ako rating_max song.current_rating = (9 * song.current_rating + song.rating_max * song.factor_age) / 10 _session.add(song) _session.commit() except: print("Failed to update song ratings") #vynulujeme rating songom v playliste, co sa este len chystaju prehrat, ale vieme, ze sa prehraju try: songs_to_be_played = _session.query(Song).join(Playlist).filter(Playlist.play_time == None).all() #print(songs_to_be_played) for song in songs_to_be_played: delete_request_to_play(song) song.current_rating = 0 _session.add(song) _session.commit() except: print("failed to set song ratings to 0") finally: update_factor_age()
def update_factor_age(): songs = _session.query(Song).all() for song in songs: song.factor_age = determine_factor_age(song) _session.add(song) _session.commit()