Ejemplo n.º 1
0
def start_timer():
    if variables.get("stop_timer", False):
        # A timer is already waiting to start
        return

    variables.put("stop_timer", True, False)
    variables.put("elapsed", 0, False)
    time.sleep(0.5)  # Wait to give the other timer time to stop
    variables.put("stop_timer", False, False)  # The timer starts

    playing = variables.get("playing", None)
    if playing is None:
        log("Audio.py: playing == None!")
        return

    song = library.get_song(playing[0], playing[1], playing[2])

    start_time = variables.get("song_start", None)
    if start_time is None:
        log("Audio.py: song_start = None!")
        return

    # Start counting
    while True:
        time_elapsed = time.time() - start_time

        if time_elapsed >= float(song.get_duration()):
            # Song is done playing, play next song
            queue = variables.get("queue", None)
            if queue is None:
                log("Audio.py: queue = None!")
                return
            # Play new song
            queue_nr = queue.index(playing)
            queue_nr += 1
            song = queue[queue_nr % len(queue)]  # Make dat shit loop

            song_obj = library.get_song(song[0], song[1], song[2])
            play(song_obj)
            return  # Stop this timer

        if variables.get("stop_timer", False):
            # A new timer is ready to go, stop this one
            return

        # If the music is paused
        if variables.get("status", -1) == variables.PAUSED:
            start_pause_time = time.time()
            while variables.get("status", -1) == variables.PAUSED:
                time.sleep(0.1)  # Wait for the music to be continued
            start_time += time.time() - start_pause_time

        variables.put("elapsed", int(time_elapsed*1000)/1000., False)
        time.sleep(0.1)  # Sleep for a bit
Ejemplo n.º 2
0
def get_playing():
    # Return songObject of song played
    ans = variables.get("playing", None)
    if ans is None:
        return ans
    artist, album, song = ans
    return library.get_song(artist, album, song)
Ejemplo n.º 3
0
def next_song():
    queue = variables.get("queue", None)
    playing = variables.get("playing", None)
    if queue is None or playing is None:
        return "Something went wrong"
    queue_nr = queue.index(playing)
    song = queue[(queue_nr + 1) % len(queue)]
    song_obj = library.get_song(song[0], song[1], song[2])
    server.audio.play(song_obj)
    return song[0] + ";" + song[1] + ";" + song[2]
Ejemplo n.º 4
0
def play_music_song(artist, album, song):
    artist = artist.replace("_", " ")
    album = album.replace("_", " ")
    song_name = song.replace("_", " ")

    song = library.get_song(artist, album, song_name)
    server.audio.play(song)
    return "Playing %s by %s : %s" % (song.get_title(),
                                      song.get_artist().get_name(),
                                      song.get_album().get_title())
Ejemplo n.º 5
0
def resume():
    status = variables.get("status", variables.STOPPED)

    if status == variables.PLAYING:
        return
    elif status == variables.STOPPED:
        # Music is stopped, play song from beginning
        playing = variables.get("playing", None)
        if playing is None:
            return
        song_obj = library.get_song(playing[0], playing[1], playing[2])
        play(song_obj)
    elif status == variables.PAUSED:
        os.system("pkill -CONT mpg123")

    variables.put("status", variables.PLAYING)
Ejemplo n.º 6
0
def previous_song():
    queue = variables.get("queue", None)
    playing = variables.get("playing", None)
    if queue is None or playing is None:
        return "Something went wrong"
    queue_nr = queue.index(playing)
    if variables.get("elapsed", 0) > 4:
        # Replay the song
        song = playing
        log("Replaying song from beginning:" + str(song))
    else:
        # Play the previous song
        song = queue[queue_nr - 1]
    song_obj = library.get_song(song[0], song[1], song[2])
    server.audio.play(song_obj)
    
    return song[0] + ";" + song[1] + ";" + song[2]
Ejemplo n.º 7
0
def play_music():
    """
    Play the song requested by POST request
    :return: Json of song information
    """
    if not valid_ip():
        block_user()

    data = request.data
    data = literal_eval(data)

    artist = lib.string.cleanJSON(data["artist"])
    album = lib.string.cleanJSON(data["album"])
    song = lib.string.cleanJSON(data["song"])

    songObj = library.get_song(artist, album, song)
    server.audio.play(songObj)
    return get_status()