Example #1
0
def ajax_createblock(request):
    songfiles = json.loads(request.raw_post_data)
    b = Block(length=0, author=request.user.username)
    b.save()
    i=0

    if len(songfiles) == 0:
        return HttpResponse("No Songs. Wtf mate?")

    for s in songfiles:
        dat = MPC().search('file', str(s))[0]
        if 'album' not in dat:
            dat['album'] = ''
        if 'artist' not in dat:
            dat['artist'] = ''
        if 'title' not in dat:
            dat['title'] = ''
        Track(block=b, filename=s, track_number=i, artist=dat['artist'], album=dat['album'], title=dat['title']).save()
        i=i+1
    b.update_length()
    Vote(block=b, user=request.user.username).save()
    Queue().save_queue()
    if MPC().status()['state'] == 'stop':
        MPC().play()
    return HttpResponse("OK")
Example #2
0
    def compute_queue(self):
        # 1. determine current block
        # 2. calculate scores for all other blocks
        # 3. output tracks in order: current block, then remaining blocks by descending score

        play_queue = []
        blocks_to_score = []
        cursong_id = self.__clean_playlist()

        if cursong_id == None:
            # play queue has never been saved to mpd
            # calculate scores for all blocks
            blocks_to_score = list(Block.objects.all())
        else:
            # add tracks in the current block to the queue
            curblock = Track.objects.filter(playlist_id = cursong_id)[0].block
            curblock_tracks = curblock.track_set.all().order_by('track_number')
            play_queue += list(curblock.track_set.all().order_by('track_number'))
            # and score the rest...
            blocks_to_score = list(Block.objects.exclude(id = curblock.id))

        # sort them by score
        d = datetime.now()
        blocks_to_score.sort(key=lambda x : Block.priority_score(x, d))

        # add remaining tracks to the queue
        for b in blocks_to_score:
            if b.track_set.count() == 0:
                b.delete()
            else:
                play_queue += list(b.track_set.all().order_by('track_number'))

        return play_queue
Example #3
0
def ajax_createblock(request):
    songfiles = json.loads(request.raw_post_data)
    b = Block(length=0, author=request.user.username)
    b.save()
    i = 0

    if len(songfiles) == 0:
        return HttpResponse("No Songs. Wtf mate?")

    for s in songfiles:
        dat = MPC().search('file', str(s))[0]
        if 'album' not in dat:
            dat['album'] = ''
        if 'artist' not in dat:
            dat['artist'] = ''
        if 'title' not in dat:
            dat['title'] = ''
        Track(block=b,
              filename=s,
              track_number=i,
              artist=dat['artist'],
              album=dat['album'],
              title=dat['title']).save()
        i = i + 1
    b.update_length()
    Vote(block=b, user=request.user.username).save()
    Queue().save_queue()
    if MPC().status()['state'] == 'stop':
        MPC().play()
    return HttpResponse("OK")