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()
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()
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)
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)
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)
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)
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)
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)
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()
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)
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)
def get_state(): current = QueueItem.current() if current!=None and current.what in downloader.downloads(): return "caching" else: return player.status.name()
def get_state(): current = QueueItem.current() if current != None and current.what in downloader.downloads(): return "caching" else: return player.status.name()