Пример #1
0
def next_track():
    if QueueItem.objects.all().count() > 0:
        QueueItem.current().delete() # remove current first item from queue
        player.stop()
        reindex_queue()
    if QueueItem.objects.all().count()>0:
        play_current(player)
    elif player.status != Status.idle:
        player.stop()
Пример #2
0
def next_track():
    logger.debug("Next track. Count %d, Status %s", QueueItem.objects.count(), player.status)
    if QueueItem.objects.all().count() > 0:
        QueueItem.current().delete() # remove current first item from queue
        player.stop()
        reindex_queue()
    if QueueItem.objects.all().count()>0:
        play_current(player)
    elif player.status != Status.idle:
        player.stop()
Пример #3
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)
Пример #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)
Пример #5
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)
Пример #6
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)
Пример #7
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)
Пример #8
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)
Пример #9
0
def play_current(player):
    toplay = QueueItem.current()
    f = cached(toplay.what)
    logging.debug("toplay %s", f)
    if f != None:
        player.play(f)
        song = toplay.what
        track = dict(artist_name=song.artist,
                 song_title=song.title,
                 length=int(song.trackLength),
                 date_played=strftime("%Y-%m-%d %H:%M:%S", gmtime()), 
                 album=song.album,
                 mbid=""
                )
        logging.debug("track %s", track)
        post(**track)
        ChatItem(what="play", info=song, who=toplay.who).save()
    else:
        player.stop()
        ChatItem(what="stop", who=None).save()
Пример #10
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)
Пример #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)
Пример #12
0
def get_state():    
    current = QueueItem.current()
    if current!=None and current.what in downloader.downloads():
        return "caching"
    else:
        return player.status.name()
Пример #13
0
def get_state():
    current = QueueItem.current()
    if current != None and current.what in downloader.downloads():
        return "caching"
    else:
        return player.status.name()