Example #1
0
File: queue.py Project: palfrey/nih
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)
Example #2
0
File: queue.py Project: palfrey/nih
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)
Example #3
0
File: queue.py Project: Ferada/nih
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)
Example #4
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()