예제 #1
0
def console(request):
    console = VLCController()
    error = None;
    output = None;
    try:
        output = console.handshake().split("\n")[:-1]
        if (request.method == 'POST'):
            output = console.command(request.POST['command'].encode('utf-8')).split("\n")[:-1]
        console.close()

    except socket.error:
        error = "VLC is not running, run VLC via SSH."


    results = {
        'status' : ('error' if error else 'ok'),
        'output' : (('### ERROR ###',error,'### ERROR ###') if error else output),
            }

    if (request.method == 'POST'):
        return HttpResponse(json.dumps(results), mimetype="application/json")
    else:
        results['section'] = 'console'
        results['title'] = 'VLC Console'
        return render_to_response('console.html', results, context_instance=RequestContext(request))
예제 #2
0
def update(request):
    error = None
    playlist = PlaylistElement.objects.all().delete()
    for position, track_id in enumerate(request.POST.getlist('order')):
        track = Track.objects.get(pk=int(track_id))
        playlistElement = PlaylistElement.objects.create(position=position,
                                                         track=track)
        playlistElement.save()

    # UPDATE PLAYLIST
    playlist = [
        item.track for item in PlaylistElement.objects.all().order_by(
            'position').select_related()
    ]

    playlist_file = open(settings.CR_PLAYLIST_DIR + "playlist.m3u", "w")
    for track in playlist:
        playlist_file.write('{0}\n'.format(track.path.encode('utf-8')))
    playlist_file.close()

    # CONNECT WITH VLC AND PLAY THE PLAYLIST
    try:
        VLCController.update_and_play(settings.CR_PLAYLIST_DIR +
                                      "playlist.m3u")
    except socket.error:
        error = "VLC is not running, playlist cannot be updated."

    results = {'status': ('error' if error else 'ok'), 'content': error}
    return HttpResponse(json.dumps(results), mimetype="application/json")
예제 #3
0
def update(request):
    error = None
    playlist = PlaylistElement.objects.all().delete()
    for position, track_id in enumerate(request.POST.getlist('order')):
        track = Track.objects.get(pk=int(track_id))
        playlistElement = PlaylistElement.objects.create(position=position, track=track)
        playlistElement.save()

    # UPDATE PLAYLIST
    playlist = [item.track for item in PlaylistElement.objects.all().order_by('position').select_related()]

    playlist_file = open(settings.CR_PLAYLIST_DIR+"playlist.m3u", "w");
    for track in playlist:
        playlist_file.write('{0}\n'.format(track.path.encode('utf-8')))
    playlist_file.close()

    # CONNECT WITH VLC AND PLAY THE PLAYLIST
    try:
        VLCController.update_and_play(settings.CR_PLAYLIST_DIR+"playlist.m3u")
    except socket.error:
        error = "VLC is not running, playlist cannot be updated."

    results = {
        'status'  : ('error' if error else 'ok'),
        'content' : error
    }
    return HttpResponse(json.dumps(results), mimetype="application/json")
예제 #4
0
def console(request):
    console = VLCController()
    error = None
    output = None
    try:
        output = console.handshake().split("\n")[:-1]
        if (request.method == 'POST'):
            output = console.command(
                request.POST['command'].encode('utf-8')).split("\n")[:-1]
        console.close()

    except socket.error:
        error = "VLC is not running, run VLC via SSH."

    results = {
        'status': ('error' if error else 'ok'),
        'output':
        (('### ERROR ###', error, '### ERROR ###') if error else output),
    }

    if (request.method == 'POST'):
        return HttpResponse(json.dumps(results), mimetype="application/json")
    else:
        results['section'] = 'console'
        results['title'] = 'VLC Console'
        return render_to_response('console.html',
                                  results,
                                  context_instance=RequestContext(request))