Esempio n. 1
0
def status(mpd):
    """An endpoint for poll-based player status updates.

    :param current: The timestamp in seconds of the last time the client got a playlist update.
        Useful for minimizing responses so that the entire party queue isn't being shuffled around
        every time an update is requested.
    :type current: float or string
    :returns: A structure containing the current MPD status. Contains the ``global_queue``,
        ``user_queue``, and ``last_global_playlist_update`` keys if ``current`` was not specified
        or was before the time of the last playlist update.
    :rtype: JSON string
    """
    client_current = request.args.get('current', None)
    if client_current is not None:
        client_current = float(client_current)

    response = _get_status(mpd)

    playlist_last_updated = ipc.get_time('playlist')
    if client_current is None or client_current < playlist_last_updated:
        response['global_queue'] = get_global_queue()
        response['user_queue'] = get_user_queue(session['user']['id'])
        response['last_global_playlist_update'] = playlist_last_updated
    else:
        if response['state'] == 'play':
            del response['elapsed']

    return jsonify(response)
Esempio n. 2
0
def on_playlist_update(mpd):
    """The subprocess that continuously IDLEs against the Mopidy server and ensures playlist consistency on playlist update."""
    while True:
        changed = mpd.idle()
        app.logger.debug("Received change event from Mopidy: %s" % changed)
        if 'playlist' in changed:
            _ensure_mpd_playlist_consistency(mpd)
        if 'options' in changed:
            _ensure_mpd_player_state_consistency(mpd)

        # Update the dict which assists caching
        for changed_system in changed:
            ipc.update_time('playlist', time.time())
            app.logger.debug(ipc.get_time('playlist'))
Esempio n. 3
0
def status(mpd):
    """An endpoint for poll-based player status updates."""
    client_current = request.args.get('current', None)
    if client_current is not None:
        client_current = float(client_current)

    response = _get_status(mpd)

    playlist_last_updated = ipc.get_time('playlist')
    if client_current is None or client_current < playlist_last_updated:
        response['global_queue'] = get_global_queue()
        response['user_queue'] = get_user_queue(session['user']['id'])
        response['last_global_playlist_update'] = playlist_last_updated
    else:
        del response['elapsed']

    return jsonify(response)