示例#1
0
 def add_song_by_path(self, path, **options):
     try:
         song = Song(track=0, time=0)
         song.audio = path
         audio = processing.annotate_metadata(song)
         song.save()
     except Exception, e:
         print "Got exception while adding orphan", e
示例#2
0
 def add_song_by_path(self, path, **options):
     try:
         song = Song(track=0, time=0)
         song.audio = path
         audio = processing.annotate_metadata(song)
         song.save()
     except Exception, e:
         print "Got exception while adding orphan", e
示例#3
0
def view_artist(request, artist_name):
    songs = Song.visibles.filter(artist__iexact=artist_name)
    songs = Song.annotate_favorited(songs, request.user)
    return render_html_template('aenclave/artist_detail.html', request,
                                {'artist_name': artist_name,
                                 'song_list': songs},
                                context_instance=RequestContext(request))
示例#4
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))
示例#5
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))
示例#6
0
def roulette(request):
    # Choose six songs randomly.
    queryset = Song.visibles.order_by('?')[:6]
    queryset = Song.annotate_favorited(queryset, request.user)
    return render_html_template('aenclave/roulette.html', request,
                                {'song_list': queryset},
                                context_instance=RequestContext(request))
示例#7
0
def roulette(request):
    # Choose six songs randomly.
    queryset = Song.visibles.order_by("?")[:6]
    queryset = Song.annotate_favorited(queryset, request.user)
    return render_html_template(
        "aenclave/roulette.html", request, {"song_list": queryset}, context_instance=RequestContext(request)
    )
示例#8
0
def view_artist(request, artist_name):
    songs = Song.visibles.filter(artist__iexact=artist_name)
    songs = Song.annotate_favorited(songs, request.user)
    return render_html_template('aenclave/artist_detail.html',
                                request, {
                                    'artist_name': artist_name,
                                    'song_list': songs
                                },
                                context_instance=RequestContext(request))
示例#9
0
def playlist_detail(request, playlist_id):
    try: playlist = Playlist.objects.get(pk=playlist_id)
    except Playlist.DoesNotExist: raise Http404
    can_cede = playlist.can_cede(request.user)
    can_edit = playlist.can_edit(request.user)
    # Using the PlaylistEntry default order_by makes a godawful query.
    songs = playlist.songs.order_by('playlistentry__position')
    songs = Song.annotate_favorited(songs, request.user)
    groups = Group.objects.all()
    return render_html_template('aenclave/playlist_detail.html', request,
                                {'playlist': playlist,
                                 'song_list': songs,
                                 'force_actions_bar': can_cede,
                                 'allow_cede': can_cede,
                                 'allow_edit': can_edit,
                                 'allow_dragging': can_edit,
                                 'groups': groups},
                                context_instance=RequestContext(request))
示例#10
0
def playlist_detail(request, playlist_id):
    try:
        playlist = Playlist.objects.get(pk=playlist_id)
    except Playlist.DoesNotExist:
        raise Http404
    can_cede = playlist.can_cede(request.user)
    can_edit = playlist.can_edit(request.user)
    # Using the PlaylistEntry default order_by makes a godawful query.
    songs = playlist.songs.order_by('playlistentry__position')
    songs = Song.annotate_favorited(songs, request.user)
    groups = Group.objects.all()
    return render_html_template('aenclave/playlist_detail.html',
                                request, {
                                    'playlist': playlist,
                                    'song_list': songs,
                                    'force_actions_bar': can_cede,
                                    'allow_cede': can_cede,
                                    'allow_edit': can_edit,
                                    'allow_dragging': can_edit,
                                    'groups': groups
                                },
                                context_instance=RequestContext(request))
示例#11
0
def list_songs(request):
    songs = get_song_list(request.REQUEST)
    songs = Song.annotate_favorited(songs, request.user)
    return render_html_template('aenclave/list_songs.html', request,
                                {'song_list': songs},
                                context_instance=RequestContext(request))
示例#12
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))
示例#13
0
import urlparse

#--------------------------------- Channels ----------------------------------#

def channel_detail(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)
    songs = Song.annotate_favorited(snapshot.song_queue, request.user)
    return render_html_template('aenclave/channels.html', request,
                                {'channel': channel,
                                 'current_song': snapshot.current_song,
                                 'song_list': songs,
                                 'force_actions_bar': True,
                                 'elapsed_time': snapshot.time_elapsed,
                                 'playing': snapshot.status == 'playing',
                                 'no_queuing': True,
                                 'allow_dragging': True},
                                context_instance=RequestContext(request))

def channel_history(request, channel_id=1):
    try:
        channel = Channel.objects.get(pk=channel_id)
    except Channel.DoesNotExist:
示例#14
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))
示例#15
0
def list_songs(request):
    songs = get_song_list(request.REQUEST)
    songs = Song.annotate_favorited(songs, request.user)
    return render_html_template('aenclave/list_songs.html',
                                request, {'song_list': songs},
                                context_instance=RequestContext(request))
示例#16
0
import urlparse

#--------------------------------- Channels ----------------------------------#


def channel_detail(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)
    songs = Song.annotate_favorited(snapshot.song_queue, request.user)
    return render_html_template('aenclave/channels.html',
                                request, {
                                    'channel': channel,
                                    'current_song': snapshot.current_song,
                                    'song_list': songs,
                                    'force_actions_bar': True,
                                    'elapsed_time': snapshot.time_elapsed,
                                    'playing': snapshot.status == 'playing',
                                    'no_queuing': True,
                                    'allow_dragging': True
                                },
                                context_instance=RequestContext(request))


def channel_history(request, channel_id=1):