Exemple #1
0
 def on_add(self, data):
     current, playlist = get_playlist()
     if int(data['who']) not in playlist + [current]:
         current, playlist = music.append_song_to_playlist(Song.query.filter_by(id=int(data['who'])).first())
         self.broadcast('update', {'current':current, 'playlist':playlist})
     else:
         self.emit('error', 'That song is already on the playlist!')
Exemple #2
0
 def on_current_request(self):
     current, playlist = get_playlist()
     current = Song.query.filter_by(id=current).first()
     sketchy_ctx = app.test_request_context()
     sketchy_ctx.push()
     self.emit('current_data', render_template('current_bar.html', current=current, played=music.get_time()))
     sketchy_ctx.pop()
Exemple #3
0
 def on_move(self, data):
     current, playlist = get_playlist()
     to = data['to']
     playlist.insert(int(data['to']),
                     playlist.pop(playlist.index(int(data['from']))))
     cache.set('playlist', playlist)
     self.broadcast('update', {'current':current, 'playlist':playlist})
Exemple #4
0
def home():
    current, playlist = music.get_playlist()
    playlist = [Song.query.filter_by(id=pk).first() for pk in playlist]
    current = Song.query.filter_by(id=current).first()
    form = PostAlbumForm()
    return render_template('home.html', form=form, current=current,
                           playlist=playlist, played=music.get_time())
Exemple #5
0
 def on_current_request(self):
     """
     Returns the html for the current song, ready to plop into
     the music player."""
     current, playlist = get_playlist()
     current = Song.query.filter_by(id=current).first()
     sketchy_ctx = app.test_request_context()
     sketchy_ctx.push()
     self.emit('current_data', render_template('current_bar.html', current=current, played=music.get_time()))
     sketchy_ctx.pop()
Exemple #6
0
    def on_match(self, data):
        """Looks for a match for a given search request."""
        current, playlist = get_playlist()
        playlist.append(current)
        response = {}
        if data['what'] == 'song' or data['what'] == 'all':
            songs = Song.query.filter(Song.title.ilike('%%%s%%' %data['query']))
            exclusion = Song.query.filter(Song.id.in_(playlist))
            songs = songs.except_(exclusion).order_by(Song.plays.desc())\
                .limit(5).all()
            songs = [(song.id, song.title, song.artist.name) for song in songs]
            response['songs'] = songs

        if data['what'] == 'artist' or data['what'] == 'all':
            artists = Artist.query.filter(Artist.name.ilike('%%%s%%' %data['query'])).limit(3).all()
            artists = [(artist.id, artist.name) for artist  in artists]
            response['artists'] = artists

        if data['what'] == 'album' or data['what'] == 'all':
            albums = Album.query.filter(Album.title.ilike('%%%s%%' %data['query'])).limit(3).all()
            albums = [(album.id, album.title, album.artist.name) for album  in albums]
            response['albums'] = albums

        if data['what'] == 'by_artist':
            artist = data.get('artist','').strip(' ')
            songs = Song.query.join(Artist).filter(Artist.name.ilike(artist))\
                        .filter(Song.title.ilike('%%%s%%' %data['query']))
            exclusion = Song.query.filter(Song.id.in_(playlist))
            songs = songs.except_(exclusion).order_by(Song.plays.desc()).all()
            songs = [(song.id, song.title, song.artist.name) for song in songs]
            response['songs'] = songs

            albums = Album.query.join(Artist).filter(Artist.name.ilike(artist))\
                        .filter(Album.title.ilike('%%%s%%' %data['query']))
            albums = [(album.id, album.title, album.artist.name) for album in albums]
            response['albums'] = albums
        

        if data['what'] == 'by_album':
            album = data.get('album','').strip(' ')
            songs = Song.query.join(Album).filter(Album.title.ilike(album))\
                        .filter(Song.title.ilike('%%%s%%' %data['query']))
            exclusion = Song.query.filter(Song.id.in_(playlist))
            songs = songs.except_(exclusion).order_by(Song.track).all()
            songs = [(song.id, song.title, song.artist.name) for song in songs]
            response['songs'] = songs
        self.emit('search_results', response)
Exemple #7
0
 def on_delete(self, data):
     current, playlist = get_playlist()
     playlist.pop(playlist.index(int(data['who'])))
     cache.set('playlist', playlist)
     self.broadcast('update', {'current':current, 'playlist':playlist})