Ejemplo n.º 1
0
def upload_http_fancy_receiver(request):
    logging.info("Got fancy receiver request.")
    audio = None
    # The key is generally 'Filedata' but this is just easier.
    for k, f in request.FILES.items():
        audio = f

    # SWFUpload does not properly fill out the song's mimetype, so
    # just use the extension.
    if audio is None:
        logging.error("Did not find any file uploaded.")
        return html_error(request, 'No file was uploaded.', 'HTTP Upload')

    logging.info("Received upload of %s" % audio.name)

    if not processing.valid_song(audio.name):
        logging.error("Rejecting upload due to unsupported filetype")
        return html_error(request, 'This filetype is unsupported.',
                          'HTTP Upload')

    # Save the song into the database -- we'll fix the tags in a moment.
    song, audio = processing.process_song(audio.name, audio)

    return render_html_template('aenclave/songlist_song_row.html',
                                request, {'song': song},
                                context_instance=RequestContext(request))
Ejemplo n.º 2
0
def upload_http_fancy_receiver(request):
    logging.info("Got fancy receiver request.")
    audio = None
    # The key is generally 'Filedata' but this is just easier.
    for k,f in request.FILES.items():
        audio = f

    # SWFUpload does not properly fill out the song's mimetype, so
    # just use the extension.
    if audio is None:
        logging.error("Did not find any file uploaded.")
        return html_error(request, 'No file was uploaded.', 'HTTP Upload')

    logging.info("Received upload of %s" % audio.name)

    if not processing.valid_song(audio.name):
        logging.error("Rejecting upload due to unsupported filetype")
        return html_error(request, 'This filetype is unsupported.',
                          'HTTP Upload')

    # Save the song into the database -- we'll fix the tags in a moment.
    song, audio = processing.process_song(audio.name, audio)

    return render_html_template('aenclave/songlist_song_row.html', request,
                                {'song': song},
                                context_instance=RequestContext(request))
Ejemplo n.º 3
0
def remove_from_playlist(request):
    # Get the playlist to be removed from.
    form = request.POST
    try: playlist = Playlist.objects.get(pk=get_integer(form, 'pid'))
    except Playlist.DoesNotExist:
        return html_error(request, 'That playlist does not exist.',
                          'Remove Songs')
    # Make sure the user is allowed to edit this playlist.
    if not playlist.can_edit(request.user):
        return html_error(request, 'You lack permission to edit this'
                          ' playlist.', 'Remove Songs')
    # Remove the songs and redirect to the detail page for this playlist.
    songs = get_song_list(form)
    PlaylistEntry.objects.filter(song__in=songs).delete()
    return HttpResponseRedirect(playlist.get_absolute_url())
Ejemplo n.º 4
0
def delete_playlist(request):
    # Get the playlist to be deleted.
    form = request.POST
    try: playlist = Playlist.objects.get(pk=get_integer(form, 'pid'))
    except Playlist.DoesNotExist:
        return html_error(request, 'That playlist does not exist.',
                          'Delete Playlist')
    # Make sure the user is allowed to delete the playlist.
    if not playlist.can_cede(request.user):
        return html_error(request, 'You may only delete your own playlists.',
                          'Delete Playlist')
    # Delete the playlist and redirect to the user's playlists page.
    playlist.delete()
    return HttpResponseRedirect(reverse('aenclave-user-playlist',
                                        args=[request.user.username]))
Ejemplo n.º 5
0
def add_to_playlist(request):
    # Get the playlist to be added to.
    form = request.POST
    try: playlist = Playlist.objects.get(pk=get_integer(form, 'pid'))
    except Playlist.DoesNotExist:
        return html_error(request, 'That playlist does not exist.',
                          'Add Songs')
    # Make sure the user is allowed to edit this playlist.
    if not playlist.can_edit(request.user):
        return html_error(request, 'You lack permission to edit this'
                          ' playlist.', 'Add Songs')
    # Add the songs and redirect to the detail page for this playlist.
    songs = get_song_list(form)
    playlist.append_songs(songs)
    return HttpResponseRedirect(playlist.get_absolute_url())
Ejemplo n.º 6
0
def delete_playlist(request):
    # Get the playlist to be deleted.
    form = request.POST
    try:
        playlist = Playlist.objects.get(pk=get_integer(form, 'pid'))
    except Playlist.DoesNotExist:
        return html_error(request, 'That playlist does not exist.',
                          'Delete Playlist')
    # Make sure the user is allowed to delete the playlist.
    if not playlist.can_cede(request.user):
        return html_error(request, 'You may only delete your own playlists.',
                          'Delete Playlist')
    # Delete the playlist and redirect to the user's playlists page.
    playlist.delete()
    return HttpResponseRedirect(
        reverse('aenclave-user-playlist', args=[request.user.username]))
Ejemplo n.º 7
0
def remove_from_playlist(request):
    # Get the playlist to be removed from.
    form = request.POST
    try:
        playlist = Playlist.objects.get(pk=get_integer(form, 'pid'))
    except Playlist.DoesNotExist:
        return html_error(request, 'That playlist does not exist.',
                          'Remove Songs')
    # Make sure the user is allowed to edit this playlist.
    if not playlist.can_edit(request.user):
        return html_error(request, 'You lack permission to edit this'
                          ' playlist.', 'Remove Songs')
    # Remove the songs and redirect to the detail page for this playlist.
    songs = get_song_list(form)
    PlaylistEntry.objects.filter(song__in=songs).delete()
    return HttpResponseRedirect(playlist.get_absolute_url())
Ejemplo n.º 8
0
def add_to_playlist(request):
    # Get the playlist to be added to.
    form = request.POST
    try:
        playlist = Playlist.objects.get(pk=get_integer(form, 'pid'))
    except Playlist.DoesNotExist:
        return html_error(request, 'That playlist does not exist.',
                          'Add Songs')
    # Make sure the user is allowed to edit this playlist.
    if not playlist.can_edit(request.user):
        return html_error(request, 'You lack permission to edit this'
                          ' playlist.', 'Add Songs')
    # Add the songs and redirect to the detail page for this playlist.
    songs = get_song_list(form)
    playlist.append_songs(songs)
    return HttpResponseRedirect(playlist.get_absolute_url())
Ejemplo n.º 9
0
def upload_youtube_receiver(request):
    url = request.POST.get('youtube-url', '')
    if not url:
        return html_error(request, "URL required.")
    #try:
        #audio_pp = youtuberip.rip_video(url, path="/tmp/")
    #except Exception, e:
        #return html_error(request, e.message)
    audio_pp = youtuberip.rip_video(url, path="/tmp/")
    audio_file = audio_pp.audio_file
    song, audio = processing.process_song(audio_file, File(open(audio_file)))
    try:
        sketchy = audio.info.sketchy
    except AttributeError:
        sketchy = True

    # Fill in these defaults on the tags.  It would be better to tag the file
    # as we rip it, but then we'd have to deal with teaching gstreamer to tag
    # MP3 and M4As.
    song.title = audio_pp.title
    song.artist = audio_pp.uploader
    song.album = 'YouTube'
    song.save()

    return render_html_template('aenclave/upload_http.html', request,
                                {'song_list': [song],
                                 'sketchy_upload': sketchy},
                                context_instance=RequestContext(request))
Ejemplo n.º 10
0
def upload_http(request):
    # Nab the file and make sure it's legit.
    audio = request.FILES.get('audio', None)
    if audio is None:
        return html_error(request, 'No file was uploaded.', 'HTTP Upload')

    try:
        song, audio = processing.process_song(audio.name, audio)
    except processing.BadContent:
        return html_error(request, "You may only upload audio files.",
                          "HTTP Upload")

    return render_html_template('aenclave/upload_http.html', request,
                                {'song_list': [song],
                                 'sketchy_upload': audio.info.sketchy},
                                context_instance=RequestContext(request))
Ejemplo n.º 11
0
def upload_youtube_receiver(request):
    url = request.POST.get('youtube-url', '')
    if not url:
        return html_error(request, "URL required.")
    #try:
    #audio_pp = youtuberip.rip_video(url, path="/tmp/")
    #except Exception, e:
    #return html_error(request, e.message)
    audio_pp = youtuberip.rip_video(url, path="/tmp/")
    audio_file = audio_pp.audio_file
    song, audio = processing.process_song(audio_file, File(open(audio_file)))
    try:
        sketchy = audio.info.sketchy
    except AttributeError:
        sketchy = True

    # Fill in these defaults on the tags.  It would be better to tag the file
    # as we rip it, but then we'd have to deal with teaching gstreamer to tag
    # MP3 and M4As.
    song.title = audio_pp.title
    song.artist = audio_pp.uploader
    song.album = 'YouTube'
    song.save()

    return render_html_template('aenclave/upload_http.html',
                                request, {
                                    'song_list': [song],
                                    'sketchy_upload': sketchy
                                },
                                context_instance=RequestContext(request))
Ejemplo n.º 12
0
def upload_http(request):
    # Nab the file and make sure it's legit.
    audio = request.FILES.get('audio', None)
    if audio is None:
        return html_error(request, 'No file was uploaded.', 'HTTP Upload')

    try:
        song, audio = processing.process_song(audio.name, audio)
    except processing.BadContent:
        return html_error(request, "You may only upload audio files.",
                          "HTTP Upload")

    return render_html_template('aenclave/upload_http.html',
                                request, {
                                    'song_list': [song],
                                    'sketchy_upload': audio.info.sketchy
                                },
                                context_instance=RequestContext(request))
Ejemplo n.º 13
0
def create_playlist(request):
    form = request.POST
    name = get_unicode(form, 'name')
    if not name:
        return html_error(request,'No name provided.')  # TODO better feedback
    # Make sure that we can create the playlist.
    # WTF In fact, we can't use playlist.songs until playlist has been saved.
    playlist = Playlist(name=name, owner=request.user)
    try:
        playlist.save()  # BTW This will fail if (name,owner) is not unique.
    except:
        return html_error(request, 'A playlist of that name already exists.')
    #    return error(request,'Nonunique name/owner.')  # TODO better feedback
    # Add the specified songs to the playlist.
    songs = get_song_list(form)
    playlist.set_songs(songs)
    playlist.save()
    # Redirect to the detail page for the newly created playlist.
    return HttpResponseRedirect(playlist.get_absolute_url())
Ejemplo n.º 14
0
def channel_history(request, channel_id=1):
    try:
        channel = Channel.objects.get(pk=channel_id)
    except Channel.DoesNotExist:
        raise Http404
    try:
        snapshot = request.get_channel_snapshot(channel)
    except ControlError, e:
        msg = "Error while connecting to player: %s" % e.message
        return html_error(request, msg)
Ejemplo n.º 15
0
def channel_history(request, channel_id=1):
    try:
        channel = Channel.objects.get(pk=channel_id)
    except Channel.DoesNotExist:
        raise Http404
    try:
        snapshot = request.get_channel_snapshot(channel)
    except ControlError, e:
        msg = "Error while connecting to player: %s" % e.message
        return html_error(request, msg)
Ejemplo n.º 16
0
def create_playlist(request):
    form = request.POST
    name = get_unicode(form, 'name')
    if not name:
        return html_error(request, 'No name provided.')  # TODO better feedback
    # Make sure that we can create the playlist.
    # WTF In fact, we can't use playlist.songs until playlist has been saved.
    playlist = Playlist(name=name, owner=request.user)
    try:
        playlist.save()  # BTW This will fail if (name,owner) is not unique.
    except:
        return html_error(request, 'A playlist of that name already exists.')
    #    return error(request,'Nonunique name/owner.')  # TODO better feedback
    # Add the specified songs to the playlist.
    songs = get_song_list(form)
    playlist.set_songs(songs)
    playlist.save()
    # Redirect to the detail page for the newly created playlist.
    return HttpResponseRedirect(playlist.get_absolute_url())
Ejemplo n.º 17
0
def edit_group_playlist(request, playlist_id):
    # Get the playlist.
    form = request.POST
    try: playlist = Playlist.objects.get(pk=playlist_id)
    except Playlist.DoesNotExist:
        return html_error('That playlist does not exist.')
    # Check that they can edit it.
    if not playlist.can_edit(request.user):
        return html_error('You are not authorized to edit this playlist.')
    # Set the group.
    group_id = form.get('group', '')
    try:
        group = Group.objects.get(pk=int(group_id))
    except (Group.DoesNotExist, TypeError, ValueError):
        playlist.group = None
    else:
        playlist.group = group
    playlist.save()
    return HttpResponseRedirect(reverse('aenclave-playlist',
                                        args=[playlist_id]))
Ejemplo n.º 18
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))
Ejemplo n.º 19
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))
Ejemplo n.º 20
0
 def func(request, *args, **kwargs):
     session_key = request.REQUEST.get(settings.SESSION_COOKIE_NAME, None)
     if not session_key:
         # TODO(rnk): Do something more sane like ask the user if their
         #            session is expired or some other weirdness.
         raise Http404()
     # This is how SessionMiddleware does it.
     session_engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])
     try:
         request.session = session_engine.SessionStore(session_key)
     except Exception, e:
         return html_error(e)
Ejemplo n.º 21
0
def edit_group_playlist(request, playlist_id):
    # Get the playlist.
    form = request.POST
    try:
        playlist = Playlist.objects.get(pk=playlist_id)
    except Playlist.DoesNotExist:
        return html_error('That playlist does not exist.')
    # Check that they can edit it.
    if not playlist.can_edit(request.user):
        return html_error('You are not authorized to edit this playlist.')
    # Set the group.
    group_id = form.get('group', '')
    try:
        group = Group.objects.get(pk=int(group_id))
    except (Group.DoesNotExist, TypeError, ValueError):
        playlist.group = None
    else:
        playlist.group = group
    playlist.save()
    return HttpResponseRedirect(
        reverse('aenclave-playlist', args=[playlist_id]))
Ejemplo n.º 22
0
 def func(request, *args, **kwargs):
     session_key = request.REQUEST.get(settings.SESSION_COOKIE_NAME, None)
     if not session_key:
         # TODO(rnk): Do something more sane like ask the user if their
         #            session is expired or some other weirdness.
         raise Http404()
     # This is how SessionMiddleware does it.
     session_engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])
     try:
         request.session = session_engine.SessionStore(session_key)
     except Exception, e:
         return html_error(e)
Ejemplo n.º 23
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))
Ejemplo n.º 24
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))
Ejemplo n.º 25
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))
Ejemplo n.º 26
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))
Ejemplo n.º 27
0
def filter_search(request):
    try:
        (tree, total, errors) = _build_filter_tree(request.GET, 'k')
    except KeyError, err:
        return html_error(request, message=str(err))
Ejemplo n.º 28
0
            elif unit == 'month': delta = datetime.timedelta(30.43685)
            elif unit == 'year': delta = datetime.timedelta(365.24220)
            date = datetime.datetime.now() - number * delta
            if rule == 'last': return Qu(kind, 'gte', date)
            else: return Qu(kind, 'lt', date)
        else:
            if rule == 'before': return Qu(kind, 'lt', data)
            elif rule == 'after': return Qu(kind, 'gt', data)
            elif rule == 'inside': return Qu(kind, 'range', data)
            elif rule == 'outside':
                return Qu(kind, 'lt', data[0]) | Qu(kind, 'gt', data[1])


def filter_search(request):
    try:
        (tree, total, errors) = _build_filter_tree(request.GET, 'k')
    except KeyError, err:
        return html_error(request, message=str(err))
    # TODO error (human's fault)
    if errors:
        return html_error(request, message=str(errors))
    if total == 0: queryset = ()
    else: queryset = Song.visibles.filter(_build_filter_query(tree))
    queryset = Song.annotate_favorited(queryset, request.user)
    return render_html_template('aenclave/filter_results.html',
                                request, {
                                    'song_list': queryset[:500],
                                    'criterion_count': total
                                },
                                context_instance=RequestContext(request))
Ejemplo n.º 29
0
            if unit == 'hour': delta = datetime.timedelta(0, 3600)
            elif unit == 'day': delta = datetime.timedelta(1)
            elif unit == 'week': delta = datetime.timedelta(7)
            elif unit == 'month': delta = datetime.timedelta(30.43685)
            elif unit == 'year': delta = datetime.timedelta(365.24220)
            date = datetime.datetime.now() - number * delta
            if rule == 'last': return Qu(kind, 'gte', date)
            else: return Qu(kind, 'lt', date)
        else:
            if rule == 'before': return Qu(kind, 'lt', data)
            elif rule == 'after': return Qu(kind, 'gt', data)
            elif rule == 'inside': return Qu(kind, 'range', data)
            elif rule == 'outside':
                return Qu(kind, 'lt', data[0]) | Qu(kind, 'gt', data[1])

def filter_search(request):
    try:
        (tree, total, errors) = _build_filter_tree(request.GET, 'k')
    except KeyError, err:
        return html_error(request, message=str(err))
    # TODO error (human's fault)
    if errors:
        return html_error(request, message=str(errors))
    if total == 0: queryset = ()
    else: queryset = Song.visibles.filter(_build_filter_query(tree))
    queryset = Song.annotate_favorited(queryset, request.user)
    return render_html_template('aenclave/filter_results.html', request,
                                {'song_list':queryset[:500],
                                 'criterion_count':total},
                                context_instance=RequestContext(request))
Ejemplo n.º 30
0
def filter_search(request):
    try:
        (tree, total, errors) = _build_filter_tree(request.GET, 'k')
    except KeyError, err:
        return html_error(request, message=str(err))