Esempio n. 1
0
def djpandora_vote(request):
    """
    Receives a vote, returns JSON status

    Creates a vote object and applies it to a song. If it's a duplicate we check
    to see if our value reverses our vote, and applies that to the existing
    vote object. This prevents a user from repeatedly voting on a song.
    """
    song = get_object_or_404(models.Song, id=request.GET.get('song_id'))
    s = utils.get_pandora_rpc_conn()
    if request.GET.get('vote') == 'like':
        vote = 1
        s.play_sound('upvote')
    else:
        vote = -1
        s.play_sound('downvote')
    instance = models.Vote(user=request.user)
    post = {
        u'station': song.station_id, u'value': vote, 
        u'song': song.id
    }
    vote_obj, created = models.Vote.objects.get_or_create(user=request.user,
        station=song.station, song=song
    )
    vote_obj.value = vote
    vote_obj.save()
    form = forms.Vote(post, instance=instance)
    json_status = {'status': 'success'}
    return HttpResponse(json.dumps(json_status), 
                mimetype='application/json'
    )
Esempio n. 2
0
def control_player(request):
    control_type = request.GET.get('control_type', False)
    if not control_type:
        return HttpResponseNotFound()

    s = utils.get_pandora_rpc_conn()
    station = models.Station.objects.get(current=True)
    json_data = {'status': 'success', 'control_type': control_type}

    if control_type == 'play':
        if station.status != models.Station.PLAY:
            s.pause_song(False)
            station.control(models.Station.PLAY)
        else:
            s.play_station(station.pandora_id)
    elif control_type == 'pause':
        if station.status != models.Station.PAUSE:
            s.pause_song(True)
            station.control(models.Station.PAUSE)
            station.save()
    elif control_type == 'stop':
        if station.status != models.Station.STOP:
            s.stop_song()
            station.control(models.Station.STOP)
    else:
        json_data['status'] = 'failure'
        json_data['error'] = 'Invalid control type'
    return HttpResponse(json.dumps(json_data), mimetype='application/json')
Esempio n. 3
0
def volume_control(request):
    volume = request.GET.get('volume', 0)
    s = utils.get_pandora_rpc_conn()
    if volume == 0:
        s.set_volume(0)
    else:
        level = float(volume) / 100.0
        s.set_volume(level)
    json_data = {'status': 'success'}
    return HttpResponse(json.dumps(json_data), mimetype='application/json')
Esempio n. 4
0
def start_station_vote(request):
    """
    Starts a station voting poll. If one is already in progress, we fail out.
    Only one poll can be going on at a time.
    """
    json_data = {
        'status': 'success'
    }
    station = get_object_or_404(models.Station, id=request.GET.get('station_id'))
    station_polls = models.StationPoll.objects.filter(active=True)
    if station_polls:
        json_data['status'] = 'failed'
    else:
        s = utils.get_pandora_rpc_conn()
        s.play_sound('station')
        poll = models.StationPoll(station=station, active=True)
        poll.save()
        json_data['vote_total'] = poll.vote_total
    
    json_data['pk'] = station.id
    json_data['name'] = station.name
    return HttpResponse(json.dumps(json_data), mimetype='application/json')