示例#1
0
def append_song_to_playlist(song):
    global sleeper
    current, playlist = get_playlist()
    if not playlist and not current:
        path = get_path_from_song(song)
        player.loadfile(path)
        song.plays += 1
        current = song.id
        sleeper = start_sleeper(song.length)
    else:
        playlist = playlist + [song.id]
    cache.set('playlist', playlist)
    cache.set('current', current)
    return current, playlist
示例#2
0
def append_song_to_playlist(song):
    """Append a song to the playlist and play it if the playlist is empty."""
    global sleeper
    current, playlist = get_playlist()
    if not playlist and not current:
        path = get_path_from_song(song)
        player.loadfile(path)
        song.plays += 1
        current = song.id
        sleeper = start_sleeper(song.length)
    else:
        playlist = playlist + [song.id]
    cache.set("playlist", playlist)
    cache.set("current", current)
    return current, playlist
示例#3
0
def next_song():
    global sleeper
    old_sleeper = sleeper
    current, playlist = get_playlist()
    try:
        current = playlist.pop(0)
        song = Song.query.filter_by(id=current).first()
        song.plays += 1
        path = get_path_from_song(song)
        player.loadfile(path)
        db.session.commit()
        sleeper = start_sleeper(song.length)
    except:
        current = None;
        player.stop();
    cache.set('current',current)
    cache.set('playlist', playlist)
    sockets.UpdateNamespace.broadcast('update', {'current':current, 'playlist':playlist})
    old_sleeper.kill()
示例#4
0
def next_song():
    """Start the next song playing and update the playlist."""
    global sleeper
    old_sleeper = sleeper
    current, playlist = get_playlist()
    try:
        current = playlist.pop(0)
        song = Song.query.filter_by(id=current).first()
        song.plays += 1
        path = get_path_from_song(song)
        player.loadfile(path)
        db.session.commit()
        sleeper = start_sleeper(song.length)
    except:
        current = None
        player.stop()
    cache.set("current", current)
    cache.set("playlist", playlist)
    sockets.UpdateNamespace.broadcast("update", {"current": current, "playlist": playlist})
    old_sleeper.kill()