Exemplo n.º 1
0
def normal_search(request):
    # Get the query.
    query_string = request.GET.get('q','')
    select_from = request.GET.get('from', 'all_songs')
    # Get the result set.
    queryset = get_search_results(query_string, request.user, select_from)
    # If we're feeling lucky, queue a random result.
    if request.GET.get('lucky', False):
        if queryset is ():
            queryset = Song.visibles
        song_id = queryset.order_by('?').values('id')[0]['id']
        song = Song.objects.get(pk=song_id)
        channel = Channel.default()
        ctrl = channel.controller()
        ctrl.add_song(song)
        # Redirect to the channels page.
        return HttpResponseRedirect(reverse('aenclave-default-channel'))
    # Otherwise, display the search results.  Limit to 500, and add favorite
    # hearts.
    queryset = Song.annotate_favorited(queryset[:500], request.user)
    return render_html_template('aenclave/search_results.html', request,
                                {'song_list': queryset,
                                 'search_query': query_string,
                                 'select_from': select_from},
                                context_instance=RequestContext(request))
Exemplo n.º 2
0
def normal_search(request):
    # Get the query.
    query_string = request.GET.get('q', '')
    select_from = request.GET.get('from', 'all_songs')
    # Get the result set.
    queryset = get_search_results(query_string, request.user, select_from)
    # If we're feeling lucky, queue a random result.
    if request.GET.get('lucky', False):
        if queryset is ():
            queryset = Song.visibles
        song_id = queryset.order_by('?').values('id')[0]['id']
        song = Song.objects.get(pk=song_id)
        channel = Channel.default()
        ctrl = channel.controller()
        ctrl.add_song(song)
        # Redirect to the channels page.
        return HttpResponseRedirect(reverse('aenclave-default-channel'))
    # Otherwise, display the search results.  Limit to 500, and add favorite
    # hearts.
    queryset = Song.annotate_favorited(queryset[:500], request.user)
    return render_html_template('aenclave/search_results.html',
                                request, {
                                    'song_list': queryset,
                                    'search_query': query_string,
                                    'select_from': select_from
                                },
                                context_instance=RequestContext(request))
Exemplo n.º 3
0
def render_html_template(template, request, options=None, *args, **kwargs):
    """Render a template response with some extra parameters."""
    # This exists so that if we need to, we can hook all of our template
    # rendering calls very easily.
    if options is None: options = {}
    options['dl'] = 'dl' in request.REQUEST
    options['playlist_info'] = json_channel_info(request, Channel.default())
    return render_to_response(template, options, *args, **kwargs)
Exemplo n.º 4
0
def announce(string):
    pid = os.fork()
    if not pid:
        channel = Channel.default()
        controller = channel.controller()
        controller.pause()
        os.system('echo "' + string + '" | festival --tts')
        controller.unpause()
    return
Exemplo n.º 5
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')
Exemplo n.º 6
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')
Exemplo n.º 7
0
def dequeue_songs(request):
    form = request.POST
    # Get the selected playids.
    playids = get_int_list(form, 'playids')
    # Dequeue the songs.
    channel = Channel.default()
    ctrl = channel.controller()
    try:
        ctrl.remove_songs(playids)
    except ControlError, err:
        return html_error(request, str(err))
Exemplo n.º 8
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))
Exemplo n.º 9
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))
Exemplo n.º 10
0
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()
        else: return json_error('invalid action: ' + action)
    except ControlError, err:
        return json_error(str(err))
Exemplo n.º 11
0
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()
        else: return json_error('invalid action: ' + action)
    except ControlError, err:
        return json_error(str(err))
Exemplo n.º 12
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')
Exemplo n.º 13
0
def queue_songs(request):
    form = request.REQUEST
    # Get the selected songs.
    songs = get_song_list(form)
    # Queue the songs.
    channel = Channel.default()
    ctrl = channel.controller()
    referrer = request.META.get('HTTP_REFERER', '')
    referrer_path = urlparse.urlparse(referrer).path
    if 'recommendations' in referrer_path:
        good_recommendations(request)
    try:
        ctrl.add_songs(songs)
    except ControlError, err:
        if 'getupdate' in form:
            return json_error(str(err))
        else:
            return html_error(request, str(err))
Exemplo n.º 14
0
def queue_to_front(request):
    form = request.REQUEST
    songs = get_song_list(form)
    if len(songs) != 1:
        raise json_error("Can only queue one song to front")

    song = songs[0]
    channel = Channel.default()
    ctrl = channel.controller()

    try:
        ctrl.queue_to_front(song)

    except ControlError, err:
        if 'getupdate' in form:
            return json_error(str(err))
        else:
            return html_error(request, str(err))
Exemplo n.º 15
0
def queue_songs(request):
    form = request.REQUEST
    # Get the selected songs.
    songs = get_song_list(form)
    # Queue the songs.
    channel = Channel.default()
    ctrl = channel.controller()
    referrer = request.META.get('HTTP_REFERER', '')
    referrer_path = urlparse.urlparse(referrer).path
    if 'recommendations' in referrer_path:
        good_recommendations(request)
    try:
        ctrl.add_songs(songs)
    except ControlError, err:
        if 'getupdate' in form:
            return json_error(str(err))
        else:
            return html_error(request, str(err))
Exemplo n.º 16
0
def queue_to_front(request):
    form = request.REQUEST
    songs = get_song_list(form)
    if len(songs) != 1:
        raise json_error("Can only queue one song to front")

    song = songs[0]
    channel = Channel.default()
    ctrl = channel.controller()

    try:
        ctrl.queue_to_front(song)

    except ControlError, err:
        if 'getupdate' in form:
            return json_error(str(err))
        else:
            return html_error(request, str(err))