示例#1
0
文件: queue.py 项目: imbstack/partify
def reorder_queue():
    """Reorders the user's play queue.

    I *think* for right now this can essentially take a list of PlayQueueEntry IDs and new priorities and write to the DB.
    I guess then track order ends up being ensured as part of the consistency function...? In which case the first comment is no longer true."""
    # I think this logic will probably change based on plug-and-play queue management schemes...

    new_order_list = request.form.get('track_list')

    # expecting a dictionary of request parameters with the key as the PQE id and the value as the new priority
    # Note that I'm not doing any error checking here because 500ing is good enough right now
    # Should probably put a try...catch block around the cast to int
    for pqe_id, new_priority in request.form.iteritems():
        pqe = PlayQueueEntry.query.get(pqe_id)

        # TODO: This auth checking should move into its own function!
        if pqe.user.id != session['user']['id']:
            return jsonify(status='error', message="You are not authorized to modify this track!")

        pqe.user_priority = new_priority

        db.session.commit()

    ensure_mpd_playlist_consistency()

    # TODO: This returning the queue thing should probably get moved to a decorator or something
    return jsonify(status='ok', queue=get_user_queue(session['user']['id']))
示例#2
0
def remove_from_queue(mpd):
    """Removes the specified track from the user's play queue.
    
    :param track_id: The ID of :class:`PlayQueueEntry` to remove
    :type track_id: integer
    :returns: The status of the request and the user's queue
    :rtype: JSON string
    """
    track_id = request.form.get('track_id', None)

    if track_id is None:
        return jsonify(status='error', message="No track specified for removal!")
    
    try:
        track_id = int(track_id)
    except ValueError:
        return jsonify(status='error', message="Not a valid track ID!")

    # Pull the track from the play queue
    track = PlayQueueEntry.query.filter(PlayQueueEntry.mpd_id == track_id).first()
    if track is None:
        return jsonify(status='error', message="Could not find track with id %d" % track_id)

    if track.user.id != session['user']['id']:
        return jsonify(status='error', message="You are not authorized to remove this track!")
    
    # Remove the track! All of the details will follow for now.... later we'll need to be watching the reordering of tracks (#20)
    mpd.deleteid(track_id)

    return jsonify(status='ok', queue=get_user_queue(session['user']['id']))
示例#3
0
def reorder_queue():
    """Reorders the user's play queue.

    :param track_list: A dictionary with keys of :class:`partify.models.PlayQueueEntry` to be moved and
        values that are the positions to move the queue entry to.
    :type track_list: dictionary(integer, integer)
    :returns: The status of the request and the user's queue
    :rtype: JSON String
    """
    new_order_list = request.form.get('track_list')

    # expecting a dictionary of request parameters with the key as the PQE id and the value as the new priority
    # Note that I'm not doing any error checking here because 500ing is good enough right now
    # Should probably put a try...catch block around the cast to int
    for pqe_id, new_priority in request.form.iteritems():
        pqe = PlayQueueEntry.query.get(pqe_id)

        # TODO: This auth checking should move into its own function!
        if pqe.user.id != session['user']['id']:
            return jsonify(status='error', message="You are not authorized to modify this track!")

        pqe.user_priority = new_priority

        db.session.commit()

    ensure_mpd_playlist_consistency()

    # TODO: This returning the queue thing should probably get moved to a decorator or something
    return jsonify(status='ok', queue=get_user_queue(session['user']['id']))
示例#4
0
文件: queue.py 项目: zippyy/partify
def reorder_queue():
    """Reorders the user's play queue.

    :param track_list: A dictionary with keys of :class:`partify.models.PlayQueueEntry` to be moved and
        values that are the positions to move the queue entry to.
    :type track_list: dictionary(integer, integer)
    :returns: The status of the request and the user's queue
    :rtype: JSON String
    """
    new_order_list = request.form.get('track_list')

    # expecting a dictionary of request parameters with the key as the PQE id and the value as the new priority
    # Note that I'm not doing any error checking here because 500ing is good enough right now
    # Should probably put a try...catch block around the cast to int
    for pqe_id, new_priority in request.form.iteritems():
        pqe = PlayQueueEntry.query.get(pqe_id)

        # TODO: This auth checking should move into its own function!
        if pqe.user.id != session['user']['id']:
            return jsonify(
                status='error',
                message="You are not authorized to modify this track!")

        pqe.user_priority = new_priority

        db.session.commit()

    ensure_mpd_playlist_consistency()

    # TODO: This returning the queue thing should probably get moved to a decorator or something
    return jsonify(status='ok', queue=get_user_queue(session['user']['id']))
示例#5
0
文件: queue.py 项目: zippyy/partify
def remove_from_queue(mpd):
    """Removes the specified track from the user's play queue.
    
    :param track_id: The ID of :class:`PlayQueueEntry` to remove
    :type track_id: integer
    :returns: The status of the request and the user's queue
    :rtype: JSON string
    """
    track_id = request.form.get('track_id', None)

    if track_id is None:
        return jsonify(status='error',
                       message="No track specified for removal!")

    try:
        track_id = int(track_id)
    except ValueError:
        return jsonify(status='error', message="Not a valid track ID!")

    # Pull the track from the play queue
    track = PlayQueueEntry.query.filter(
        PlayQueueEntry.mpd_id == track_id).first()
    if track is None:
        return jsonify(status='error',
                       message="Could not find track with id %d" % track_id)

    if track.user.id != session['user']['id']:
        return jsonify(status='error',
                       message="You are not authorized to remove this track!")

    # Remove the track! All of the details will follow for now.... later we'll need to be watching the reordering of tracks (#20)
    mpd.deleteid(track_id)

    return jsonify(status='ok', queue=get_user_queue(session['user']['id']))
示例#6
0
def list_user_queue():
    """Gets the user's queue.

    :returns: The status of the request and the user's queue.
    :rtype: JSON string
    """
    user_queue = get_user_queue(session['user']['id'])
    return jsonify(status="ok", result=user_queue)
示例#7
0
文件: queue.py 项目: zippyy/partify
def list_user_queue():
    """Gets the user's queue.

    :returns: The status of the request and the user's queue.
    :rtype: JSON string
    """
    user_queue = get_user_queue(session['user']['id'])
    return jsonify(status="ok", result=user_queue)
示例#8
0
def add_to_queue(mpd):
    """Takes a Spotify URL and adds it to the current play queue.

    :param spotify_uri: The spotify URI of the track to add
    :type spotify_uri: string
    :returns: The status of the request, the user's queue, and the spotify url of the track added.
    :rtype: JSON string
    """

    spotify_uri = request.form['spotify_uri']
    
    result = add_track_from_spotify_url(mpd, spotify_uri)

    if result is None:
        return jsonify(status='error', message='The Spotify URL you specified is invalid.')
    
    return jsonify(status='ok', queue=get_user_queue(session['user']['id']), file=spotify_uri)
示例#9
0
def add_album_from_track(mpd):
    """Takes a list of Spotify track URLs corresponding to an album and adds them to the user's play queue.

    :param spotify_files: a list of spotify urls of the tracks in the album to add
    :type spotify_files: list of strings
    :returns: The status of the request and the user's queue.
    :rtype: JSON string
    """

    spotify_files = request.form.getlist('spotify_files')

    if spotify_files is None or len(spotify_files) == 0:
        return jsonify(status='error', message='The Spotify URL you specified is invalid.')

    for spotify_url in spotify_files:
        result = add_track_from_spotify_url(mpd, spotify_url)

    return jsonify(status='ok', queue=get_user_queue(session['user']['id']))
示例#10
0
文件: queue.py 项目: imbstack/partify
def add_to_queue(mpd):
    """Takes a Spotify URL and adds it to the current play queue."""

    spotify_uri = request.form['spotify_uri']
    
    track = track_from_spotify_url(spotify_uri)

    if track is None:
        return jsonify(status='error', message='The Spotify URL you specified is invalid.')
    
    mpd_id = mpd.addid(spotify_uri)

    # Add the track to the play queue
    # Disabling this for now since the playlist consistency function should figure it out
    db.session.add( PlayQueueEntry(track=track, user_id=session['user']['id'], mpd_id=mpd_id) )
    db.session.commit()

    return jsonify(status='ok', queue=get_user_queue(session['user']['id']), file=spotify_uri)
示例#11
0
文件: queue.py 项目: zippyy/partify
def add_album_from_track(mpd):
    """Takes a list of Spotify track URLs corresponding to an album and adds them to the user's play queue.

    :param spotify_files: a list of spotify urls of the tracks in the album to add
    :type spotify_files: list of strings
    :returns: The status of the request and the user's queue.
    :rtype: JSON string
    """

    spotify_files = request.form.getlist('spotify_files')

    if spotify_files is None or len(spotify_files) == 0:
        return jsonify(status='error',
                       message='The Spotify URL you specified is invalid.')

    for spotify_url in spotify_files:
        result = add_track_from_spotify_url(mpd, spotify_url)

    return jsonify(status='ok', queue=get_user_queue(session['user']['id']))
示例#12
0
文件: queue.py 项目: zippyy/partify
def add_to_queue(mpd):
    """Takes a Spotify URL and adds it to the current play queue.

    :param spotify_uri: The spotify URI of the track to add
    :type spotify_uri: string
    :returns: The status of the request, the user's queue, and the spotify url of the track added.
    :rtype: JSON string
    """

    spotify_uri = request.form['spotify_uri']

    result = add_track_from_spotify_url(mpd, spotify_uri)

    if result is None:
        return jsonify(status='error',
                       message='The Spotify URL you specified is invalid.')

    return jsonify(status='ok',
                   queue=get_user_queue(session['user']['id']),
                   file=spotify_uri)
示例#13
0
文件: queue.py 项目: imbstack/partify
def list_user_queue():
    user_queue = get_user_queue(session['user']['id'])
    return jsonify(status="ok", result=user_queue)