Esempio n. 1
0
def xml_dequeue(request):
    form = request.POST
    # Get the selected songs.
    playids = get_int_list(form, 'playids')
    # Dequeue the songs.
    channel = Channel.default()
    ctrl = channel.controller()
    try: ctrl.remove_songs(playids)
    except ControlError, err: return xml_error(str(err))
    else: return simple_xml_response('success')
Esempio n. 2
0
def xml_queue(request):
    form = request.POST
    # Get the selected songs.
    songs = get_song_list(form)
    # Queue the songs.
    channel = Channel.default()
    ctrl = channel.controller()
    try: ctrl.add_songs(songs)
    except ControlError, err: return xml_error(str(err))
    else: return simple_xml_response('success')
Esempio n. 3
0
def xml_update(request):
    # TODO(rnk): This code is dead and untested.
    form = request.POST
    channel_id = get_integer(form, 'channel', 1)
    try: channel = Channel.objects.get(pk=channel_id)
    except Channel.DoesNotExist:
        return xml_error('invalid channel id: ' + repr(channel_id))
    timestamp = get_integer(form, 'timestamp', None)
    if timestamp is None: return xml_error('invalid timestamp')
    elif timestamp >= channel.last_touched_timestamp():  # up-to-date timestamp
        try:
            snapshot = request.get_channel_snapshot(channel)
            if snapshot.status != "playing":
                return simple_xml_response('continue')
            elapsed_time = snapshot.time_elapsed
            total_time = snapshot.current_song.time
            return render_xml_to_response('aenclave/update.xml',
                                          {'elapsed_time':elapsed_time,
                                           'total_time':total_time})
        except ControlError, err: return xml_error(str(err))
    else:
        return simple_xml_response('reload')  # old timestamp
Esempio n. 4
0
def xml_control(request):
    form = request.POST
    action = form.get('action','')
    channel = Channel.default()
    ctrl = channel.controller()
    try:
        if action == 'play': ctrl.unpause()
        elif action == 'pause': ctrl.pause()
        elif action == 'skip': ctrl.skip()
        elif action == 'shuffle': ctrl.shuffle()
        else: return xml_error('invalid action: ' + action)
    except ControlError, err: return xml_error(str(err))
    else: return simple_xml_response('success')
Esempio n. 5
0
def xml_update(request):
    # TODO(rnk): This code is dead and untested.
    form = request.POST
    channel_id = get_integer(form, 'channel', 1)
    try:
        channel = Channel.objects.get(pk=channel_id)
    except Channel.DoesNotExist:
        return xml_error('invalid channel id: ' + repr(channel_id))
    timestamp = get_integer(form, 'timestamp', None)
    if timestamp is None: return xml_error('invalid timestamp')
    elif timestamp >= channel.last_touched_timestamp():  # up-to-date timestamp
        try:
            snapshot = request.get_channel_snapshot(channel)
            if snapshot.status != "playing":
                return simple_xml_response('continue')
            elapsed_time = snapshot.time_elapsed
            total_time = snapshot.current_song.time
            return render_xml_to_response('aenclave/update.xml', {
                'elapsed_time': elapsed_time,
                'total_time': total_time
            })
        except ControlError, err:
            return xml_error(str(err))
Esempio n. 6
0
    if timestamp is None: return xml_error('invalid timestamp')
    elif timestamp >= channel.last_touched_timestamp():  # up-to-date timestamp
        try:
            snapshot = request.get_channel_snapshot(channel)
            if snapshot.status != "playing":
                return simple_xml_response('continue')
            elapsed_time = snapshot.time_elapsed
            total_time = snapshot.current_song.time
            return render_xml_to_response('aenclave/update.xml', {
                'elapsed_time': elapsed_time,
                'total_time': total_time
            })
        except ControlError, err:
            return xml_error(str(err))
    else:
        return simple_xml_response('reload')  # old timestamp


#---------------------------------- Control ----------------------------------#


# @permission_required_json('aenclave.can_control')
def json_control(request):
    action = request.POST.get('action', '')
    channel = Channel.default()
    ctrl = channel.controller()
    try:
        if action == 'play': ctrl.unpause()
        elif action == 'pause': ctrl.pause()
        elif action == 'skip': ctrl.skip()
        elif action == 'shuffle': ctrl.shuffle()