Ejemplo n.º 1
0
 def track(self, track, context):
     track.load()
     t = Cache.Instance().getTrack(track.link.uri)
     if t != None:
         BohnifyQueue.Instance().setVoteToTrack(t)
         t["context"] = "spotify:" + context
         return t
     else:
         t = BohnifyQueue.Instance().getTrackIfIsAnyQueue(track.link.uri)
         if t != None:
             BohnifyQueue.Instance().setVoteToTrack(t)
             t["context"] = "spotify:" + context
             return t
         else:
             if track.availability == spotify.TrackAvailability.AVAILABLE:
                 t = {
                     "title": track.name,
                     "popularity": track.popularity,
                     "duration": track.duration,
                     "uri": track.link.uri,
                     "album": self.album(track.album),
                     "artists": self.artists(track.artists)
                 }
                 Cache.Instance().addTrack(t)
                 BohnifyQueue.Instance().setVoteToTrack(t)
                 t["context"] = "spotify:" + context
                 return t
             else:
                 return None
Ejemplo n.º 2
0
    def playlist(self, pl, tracks=True, listener=None):
        pl.load()
        playlist = Cache.Instance().getPlaylist(pl.link.uri)
        if playlist != None:
            return playlist
        else:
            playlist = {
                "name": "Starred" if "starred" in pl.link.uri else pl.name,
                "uri": pl.link.uri,
                "author": self.author(pl.owner),
                "collaborative": pl.collaborative,
                "description": pl.description
            }
            img = pl.image()
            if img != None:
                img.load()
                playlist["image"] = img.link.uri
            if tracks:
                tracks = pl.tracks[::
                                   -1] if "starred" in pl.link.uri else pl.tracks
                playlist["tracks"] = self.tracks(tracks, pl.link.uri)
                Cache.Instance().addPlaylist(playlist)

            if listener != None and pl.num_listeners(
                    spotify.PlaylistEvent.PLAYLIST_UPDATE_IN_PROGRESS) == 0:
                #pl.on(spotify.PlaylistEvent.TRACKS_ADDED, listener)
                #pl.on(spotify.PlaylistEvent.TRACKS_REMOVED, listener)
                #pl.on(spotify.PlaylistEvent.TRACKS_MOVED, listener)
                #pl.on(spotify.PlaylistEvent.PLAYLIST_RENAMED, listener)
                #pl.on(spotify.PlaylistEvent.PLAYLIST_STATE_CHANGED, listener)
                #pl.on(spotify.PlaylistEvent.PLAYLIST_METADATA_UPDATED, listener)
                #pl.on(spotify.PlaylistEvent.DESCRIPTION_CHANGED, listener)
                pl.on(spotify.PlaylistEvent.PLAYLIST_UPDATE_IN_PROGRESS,
                      listener)
            return playlist
Ejemplo n.º 3
0
 def author(self, user):
     user.load()
     u = Cache.Instance().getUser(user.link.uri)
     if u != None:
         return u
     u = {
         "nick": user.display_name,
         "name": user.canonical_name,
         "uri": user.link.uri
     }
     Cache.Instance().addUser(u)
     return u
Ejemplo n.º 4
0
 def artist(self, artist):
     artist.load()
     a = Cache.Instance().getArtist(artist.link.uri)
     if a != None:
         return a
     else:
         por = None
         try:
             por = artist.portrait_link().uri
         except:
             pass
         a = {"name": artist.name, "uri": artist.link.uri, "portrait": por}
         Cache.Instance().addArtist(a)
         return a
Ejemplo n.º 5
0
 def search_playlist(self, pl):
     playlist = Cache.Instance().getPlaylist(pl.uri, True)
     if playlist != None:
         return playlist
     else:
         playlist = {"name": pl.name, "uri": pl.uri, "image": pl.image_uri}
         return playlist
Ejemplo n.º 6
0
 def albumBrowsed(album):
     album.load()
     album.album.load()
     if arr != None:
         if self.arrayContainsAlbum(arr, album.album.name):
             return callback(None)
     cover = None
     try:
         cover = album.album.cover_link().uri
     except:
         pass
     a = {
         "uri": album.album.link.uri,
         "title": album.album.name,
         "cover": cover,
         "type": album.album.type,
         "artist": self.artist(album.artist),
         "year": album.album.year
     }
     if artist == None or artist == album.artist.link.uri:
         a["tracks"] = self.tracks(album.tracks,
                                   album.album.link.uri)
         Cache.Instance().addAlbum(a, True)
     else:
         a["type"] = 4
     if arr != None:
         if ("tracks" in a and len(a["tracks"])
                 == 0) or self.arrayContainsAlbum(
                     arr, album.album.name):
             return callback(None)
     return callback(a)
Ejemplo n.º 7
0
 def playlistChanged(self, pl, done):
   if done:
     Cache.Instance().removePlaylist(pl.link.uri)
     playlist = Transformer().playlist(pl, True, self.playlistChanged)
     playlist["name"] = "Starred" if "starred" in playlist["uri"] else playlist["name"]
     if self.cache_playlists != None:
       self.updatePlaylist(self.cache_playlists,playlist)
     cherrypy.engine.publish('websocket-broadcast', json.dumps({"playlistchanged" : playlist}))
Ejemplo n.º 8
0
 def playlistscallback(playlists):
     u = {
         "nick": user.display_name,
         "name": user.canonical_name,
         "uri": user.link.uri,
         "playlists": playlists
     }
     Cache.Instance().addUser(u, True)
     return u
Ejemplo n.º 9
0
 def album(self, album):
     album.load()
     a = Cache.Instance().getAlbum(album.link.uri)
     if a != None:
         return a
     else:
         cover = None
         try:
             cover = album.cover_link().uri
         except:
             pass
         a = {
             "uri": album.link.uri,
             "title": album.name,
             "artist": self.artist(album.artist),
             "cover": cover
         }
         Cache.Instance().addAlbum(a)
         return a
Ejemplo n.º 10
0
    def user(self, user, callback):
        user.load()
        u = Cache.Instance().getUser(user.link.uri, True)
        if u != None:
            return u

        def playlistscallback(playlists):
            u = {
                "nick": user.display_name,
                "name": user.canonical_name,
                "uri": user.link.uri,
                "playlists": playlists
            }
            Cache.Instance().addUser(u, True)
            return u

        self.playlistContainer(user.published_playlists, playlistscallback,
                               None, False, user.starred)
Ejemplo n.º 11
0
    def artist_b(self, artist, callback):
        a = Cache.Instance().getArtist(artist.link.uri, True)
        if a != None:
            callback(a)
        else:

            def artistBrowsed(artist):
                por = None
                try:
                    por = artist.artist.portrait_link().uri
                except:
                    pass
                a = {
                    "name":
                    artist.artist.name,
                    "uri":
                    artist.artist.link.uri,
                    "portrait":
                    por,
                    "bio":
                    artist.biography,
                    "toptracks":
                    self.tracks(artist.tophit_tracks, artist.artist.link.uri),
                    "similar":
                    self.artists(artist.similar_artists)
                }

                def albumsBrowsed(albums):
                    a["albums"] = albums
                    Cache.Instance().addArtist(a, True)
                    callback(a)

                self.albums_b(artist.albums, albumsBrowsed,
                              artist.artist.link.uri)

            artist = artist.browse(spotify.ArtistBrowserType.NO_TRACKS,
                                   artistBrowsed)
Ejemplo n.º 12
0
 def albumsBrowsed(albums):
     a["albums"] = albums
     Cache.Instance().addArtist(a, True)
     callback(a)