Exemple #1
0
    def play_next(self, skip=False):
        if self.empty():
            random_song = song.random_songs(limit=1)['results']
            if len(random_song) == 1:
                self.vote_song('RANDOM', random_song[0]['id'])

        if not self.empty():
            if player.now_playing:
                if isinstance(player.now_playing, YouTubeVideo):
                    self.remove_video(player.now_playing.url, skip=skip)
                elif isinstance(player.now_playing, SoundCloudMusic):
                    self.remove_video(player.now_playing.url, skip=skip)
                else:
                    self.remove_song(player.now_playing.id, skip=skip)
            session = Session()
            next_packet = (session.query(Packet).filter_by(
                player_name=PLAYER_NAME).order_by(Packet.finish_time).first())
            if next_packet:
                if next_packet.stream_url and 'www.youtube.com' in next_packet.stream_url:
                    video = YouTubeVideo(next_packet)
                    player.play_media(video)
                    session.commit()
                    return video.dictify()
                elif next_packet.stream_url and 'soundcloud.com' in next_packet.stream_url:
                    video = SoundCloudMusic(next_packet)
                    player.play_media(video)
                    session.commit()
                else:
                    next_song = session.query(Song).get(next_packet.song_id)
                    player.play_media(next_song)
                    next_song.history.append(
                        PlayHistory(user=next_packet.user,
                                    player_name=PLAYER_NAME))
                    session.commit()
                    return next_song.dictify()
Exemple #2
0
    def play_next(self, skip=False):
        if self.empty():
            random_song = random_songs(1)['results']
            if len(random_song) == 1:
                self.vote_song('RANDOM', random_song[0]['id'])

        if not self.empty():
            if player.now_playing:
                if isinstance(player.now_playing, YouTubeVideo):
                    self.remove_video(player.now_playing.url, skip=skip)
                else:
                    self.remove_song(player.now_playing.id, skip=skip)
            session = Session()
            next_packet = session.query(Packet).order_by(Packet.finish_time).first()
            if next_packet:
                if next_packet.video_url:
                    video = YouTubeVideo(next_packet)
                    player.play_media(video)
                    session.commit()
                    return video.dictify()
                else:
                    next_song = session.query(Song).get(next_packet.song_id)
                    player.play_media(next_song)
                    next_song.history.append(PlayHistory(user=next_packet.user))
                    session.commit()
                    return next_song.dictify()
Exemple #3
0
    def get_queue(user=None):
        """
        Returns the current ordering of songs

        If there is a song currently playing, puts it at the front of the list.
        If user is specified, returns whether or not the user has voted for
        each song.
        """
        session = Session()
        packets = (session.query(Packet).filter_by(player_name=PLAYER_NAME)
                   .order_by(Packet.finish_time).all())
        session.commit()

        queue = []
        for packet in packets:
            if packet.video_url:
                video = YouTubeVideo(packet)
                video_obj = video.dictify()
                video_obj['packet'] = {
                    'num_votes': packet.num_votes(),
                    'user': packet.user,
                    'has_voted': packet.has_voted(user),
                }
                queue.append(video_obj)
            else:
                song = session.query(Song).get(packet.song_id)
                song_obj = song.dictify()
                song_obj['packet'] = {
                    'num_votes': packet.num_votes(),
                    'user': packet.user,
                    'has_voted': packet.has_voted(user),
                }
                queue.append(song_obj)

        # Put now playing song at front of list
        if player.now_playing:
            for i, song in enumerate(queue):
                try:
                    if player.now_playing.id == song['id']:
                        return {'queue': [queue[i]] + queue[:i] + queue[i+1:]}
                except:
                    pass
                try:
                    if player.now_playing.url == song['url']:
                        return {'queue': [queue[i]] + queue[:i] + queue[i+1:]}
                except:
                    pass

        return {'queue': queue}
Exemple #4
0
    def get_queue(user=None):
        """
        Returns the current ordering of songs

        If there is a song currently playing, puts it at the front of the list.
        If user is specified, returns whether or not the user has voted for
        each song.
        """
        session = Session()
        packets = (session.query(Packet).filter_by(
            player_name=PLAYER_NAME).order_by(Packet.finish_time).all())
        session.commit()

        queue = []
        for packet in packets:
            if packet.stream_url and 'www.youtube.com' in packet.stream_url:
                video = YouTubeVideo(packet)
                video_obj = video.dictify()
                video_obj['packet'] = {
                    'num_votes': packet.num_votes(),
                    'user': packet.user,
                    'has_voted': packet.has_voted(user),
                }
                queue.append(video_obj)
            elif packet.stream_url and 'soundcloud.com' in packet.stream_url:
                sc = SoundCloudMusic(packet)
                sc_obj = sc.dictify()
                sc_obj['packet'] = {
                    'num_votes': packet.num_votes(),
                    'user': packet.user,
                    'has_voted': packet.has_voted(user)
                }
                queue.append(sc_obj)
            else:
                song = session.query(Song).get(packet.song_id)
                song_obj = song.dictify()
                song_obj['packet'] = {
                    'num_votes': packet.num_votes(),
                    'user': packet.user,
                    'has_voted': packet.has_voted(user),
                }
                queue.append(song_obj)

        # Put now playing song at front of list
        if player.now_playing:
            for i, song in enumerate(queue):
                try:
                    if player.now_playing.id == song['id']:
                        return {
                            'queue': [queue[i]] + queue[:i] + queue[i + 1:]
                        }
                except:
                    pass
                try:
                    if player.now_playing.url == song['url']:
                        return {
                            'queue': [queue[i]] + queue[:i] + queue[i + 1:]
                        }
                except:
                    pass

        return {'queue': queue}