Beispiel #1
0
def skip(request, username):
    current = QueueItem.current()
    if current != None:
        ChatItem(what="skip", info = current.what, who=username).save()
        print "saved item"
        player.next_track()
    return status_info(request)
Beispiel #2
0
def dequeue(request, username, trackId):
    queue = list(QueueItem.objects.all())[1:]
    for item in queue:
        if item.id == trackId:
            item.delete()
    reindex_queue()
    return status_info(request)
Beispiel #3
0
def reorder(request, trackId, new_position):
    queue = list(QueueItem.objects.all())[1:]
    length = len(queue)
    if new_position < 1:
        raise Exception("Cannot move items above position 1 in the queue")
    if new_position > length:
        new_position = length

    mover = QueueItem.objects.get(id=trackId)
    old_position = mover.index
    if old_position == 0:
        raise Exception("Cannot move the currently playing track")

    # Shuffle items that were previously below this item up to fill
    # the gap it left when it moved down
    if new_position > old_position:
        for _, item in enumerate(queue):
            if item.index > old_position and item.index <= new_position:
                item.index -= 1
                item.save()

    # Shuffle items that were previously above this item down to fill
    # the gap it left when it moved up
    if new_position < old_position:
        for _, item in enumerate(queue):
            if item.index >= new_position and item.index < old_position:
                item.index += 1
                item.save()

    mover.index = new_position
    mover.save()

    return status_info(request)
Beispiel #4
0
def skip(request, username):
    current = QueueItem.current()
    if current != None:
        ChatItem(what="skip", info=current.what, who=username).save()
        print "saved item"
        player.next_track()
    return status_info(request)
Beispiel #5
0
def dequeue(request, username, trackId):
    queue = list(QueueItem.objects.all())[1:]
    for item in queue:
        if item.id == trackId:
            item.delete()
    reindex_queue()
    return status_info(request)
Beispiel #6
0
def reorder(request, trackId, new_position):
    queue = list(QueueItem.objects.all())[1:]
    length = len(queue)
    if new_position < 1:
        raise Exception("Cannot move items above position 1 in the queue")
    if new_position > length:
        new_position = length
    
    mover = QueueItem.objects.get(id=trackId)
    old_position = mover.index
    if old_position == 0:
        raise Exception("Cannot move the currently playing track")

    # Shuffle items that were previously below this item up to fill
    # the gap it left when it moved down
    if new_position > old_position: 
        for _, item in enumerate(queue):
            if item.index > old_position and item.index <= new_position:
                item.index -= 1
                item.save()

    # Shuffle items that were previously above this item down to fill
    # the gap it left when it moved up
    if new_position < old_position: 
        for _, item in enumerate(queue):
            if item.index >= new_position and item.index < old_position:
                item.index += 1
                item.save()

    mover.index = new_position
    mover.save()

    return status_info(request)
Beispiel #7
0
def pause(request, shouldPause, username):
    current = QueueItem.current()
    if not shouldPause:
        if player.status == Status.idle and QueueItem.objects.count() > 0:
            from jukebox.cache import is_cached
            if is_cached(current.what):
                play_current(player)
        elif player.status == Status.paused:
            player.unpause()
            ChatItem(what="resume", info=current.what, who=username).save()
    else:
        if player.status == Status.playing:
            player.pause()
            ChatItem(what="pause", info=current.what, who=username).save()

    return status_info(request)
Beispiel #8
0
def pause(request, shouldPause, username):
    current = QueueItem.current()
    if not shouldPause:
        if player.status == Status.idle and QueueItem.objects.count()>0:
            from jukebox.cache import is_cached
            if is_cached(current.what):
                play_current(player)
        elif player.status == Status.paused:
            player.unpause()
            ChatItem(what="resume", info=current.what, who=username).save()
    else:
        if player.status == Status.playing:
            player.pause()
            ChatItem(what="pause", info=current.what, who=username).save()

    return status_info(request)
Beispiel #9
0
def enqueue(request, username, tracks, atTop):
    for t in tracks:
        q = QueueItem(who = username, what = MusicFile.objects.get(url=t['url']))
        cached(q.what)
        try:
            if atTop:
                items = QueueItem.objects.all().order_by("index")
                if len(items)> 1:
                    q.index = (items[0].index+items[1].index)/2
                else:
                    q.index = items[0].index + 1 # only current item in queue
            else:
                q.index = QueueItem.objects.order_by("-index")[0].index + 1 # only current item in queue
        except IndexError: # nothing else in queue
            q.index = 0
        q.save()
    return status_info(request)
Beispiel #10
0
def enqueue(request, username, tracks, atTop):
    for t in tracks:
        q = QueueItem(who=username, what=MusicFile.objects.get(url=t['url']))
        cached(q.what)
        try:
            if atTop:
                items = QueueItem.objects.all().order_by("index")
                if len(items) > 1:
                    q.index = (items[0].index + items[1].index) / 2
                else:
                    q.index = items[0].index + 1  # only current item in queue
            else:
                q.index = QueueItem.objects.order_by(
                    "-index")[0].index + 1  # only current item in queue
        except IndexError:  # nothing else in queue
            q.index = 0
        q.save()
    return status_info(request)
Beispiel #11
0
def pause(request, shouldPause, username):
    logger.debug("pause request: shouldPause %s, queueitems %s, status %s", shouldPause, QueueItem.objects.count(), player.status)
    current = QueueItem.current()
    if not shouldPause:
        if player.status == Status.idle and QueueItem.objects.count()>0:
            from jukebox.cache import is_cached
            if is_cached(current.what):
                play_current(player)
        elif player.status == Status.paused:
            player.unpause()
            ChatItem(what="resume", info=current.what, who=username).save()
        elif player.status == Status.playing and QueueItem.objects.count() == 0:
            logger.info("Weird playback, as we're playing but there's no queue items, so stopping")
            player.stop()
    else:
        if player.status == Status.playing:
            player.pause()
            ChatItem(what="pause", info=current.what, who=username).save()

    return status_info(request)
Beispiel #12
0
def enqueue(request, username, tracks, atTop):
    logger.debug("enqueue: %s", tracks)
    for t in tracks:
        q = QueueItem(who = username, what = MusicFile.objects.get(url=t['url']))
        cached(q.what)
        try:
            if atTop:
                items = QueueItem.objects.all().order_by("index")
                if len(items)> 1:
                    q.index = (items[0].index+items[1].index)/2
                else:
                    q.index = items[0].index + 1 # only current item in queue
            else:
                q.index = QueueItem.objects.order_by("-index")[0].index + 1 # only current item in queue
        except IndexError: # nothing else in queue
            q.index = 0
        q.save()

    # Newly queued items get automagically played if the player is idle. This is only needed if they're already cached
    if is_cached(QueueItem.current().what) and get_status() == Status.idle:
        play_current(player)
    return status_info(request)
Beispiel #13
0
def clear_queue(request, username):
    queue = list(QueueItem.objects.all())[1:]
    for item in queue:
        item.delete()
    return status_info(request)
Beispiel #14
0
def get_queue(request):
    return status_info(request)
Beispiel #15
0
def clear_queue(request, username):
    queue = list(QueueItem.objects.all())[1:]
    for item in queue:
        item.delete()
    return status_info(request)
Beispiel #16
0
def get_queue(request):
    return status_info(request)
Beispiel #17
0
def get_queue(request):
    logger.debug("get_queue")
    return status_info(request)