예제 #1
0
    def objectFromURI(self, uris, asArray=False):
        if not self.logged_in():
            return False

        uris = [uris] if type(uris) != list else uris
        if len(uris) == 0:
            return [] if asArray else None

        uri_type = utils.get_uri_type(uris[0])
        if not uri_type:
            return [] if asArray else None
        elif uri_type == "playlist":
            if len(uris) == 1:
                results = [SpotifyPlaylist(self, uri=uris[0])]
            else:
                thread_results = {}
                jobs = []
                for index in range(0, len(uris)):
                    jobs.append((self, uris[index], thread_results, index))

                def work_function(spotify, uri, results, index):
                    results[index] = SpotifyPlaylist(spotify, uri=uri)

                Spotify.doWorkerQueue(work_function, jobs)

                results = [v for k, v in thread_results.items()]

        elif uri_type in ["track", "album", "artist"]:
            uris = [uri for uri in uris if not utils.is_local(uri)]
            objs = self.api.metadata_request(uris)
            objs = [objs] if type(objs) != list else objs

            failed_requests = len([obj for obj in objs if False == obj])
            if failed_requests > 0:
                print failed_requests, "metadata requests failed"

            objs = [obj for obj in objs if False != obj]
            if uri_type == "track":
                tracks = [SpotifyTrack(self, obj=obj) for obj in objs]
                results = [
                    track for track in tracks
                    if False == self.AUTOREPLACE_TRACKS or track.isAvailable()
                ]
            elif uri_type == "album":
                results = [SpotifyAlbum(self, obj=obj) for obj in objs]
            elif uri_type == "artist":
                results = [SpotifyArtist(self, obj=obj) for obj in objs]
        else:
            return [] if asArray else None

        if not asArray:
            if len(results) == 1:
                results = results[0]
            elif len(results) == 0:
                return [] if asArray else None

        return results
예제 #2
0
    def objectFromURI(self, uris, asArray=False):
        if not self.logged_in():
            return False

        uris = [uris] if type(uris) != list else uris
        if len(uris) == 0:
            return [] if asArray else None

        uri_type = utils.get_uri_type(uris[0])
        if not uri_type:
            return [] if asArray else None
        elif uri_type == "playlist":
            if len(uris) == 1:
                results = [SpotifyPlaylist(self, uri=uris[0])]
            else:
                thread_results = {}
                jobs = []
                for index in range(0, len(uris)):
                    jobs.append((self, uris[index], thread_results, index))

                def work_function(spotify, uri, results, index):
                    results[index] = SpotifyPlaylist(spotify, uri=uri)

                Spotify.doWorkerQueue(work_function, jobs)

                results = [v for k, v in thread_results.items()]

        elif uri_type in ["track", "album", "artist"]:
            uris = [uri for uri in uris if not utils.is_local(uri)]
            objs = self.api.metadata_request(uris)
            objs = [objs] if type(objs) != list else objs

            failed_requests = len([obj for obj in objs if False == obj])
            if failed_requests > 0:
                print failed_requests, "metadata requests failed"

            objs = [obj for obj in objs if False != obj]
            if uri_type == "track":
                tracks = [SpotifyTrack(self, obj=obj) for obj in objs]
                results = [track for track in tracks if
                           False == self.AUTOREPLACE_TRACKS or track.isAvailable()]
            elif uri_type == "album":
                results = [SpotifyAlbum(self, obj=obj) for obj in objs]
            elif uri_type == "artist":
                results = [SpotifyArtist(self, obj=obj) for obj in objs]
        else:
            return [] if asArray else None

        if not asArray:
            if len(results) == 1:
                results = results[0]
            elif len(results) == 0:
                return [] if asArray else None

        return results
예제 #3
0
def display_playlist(playlist):
    print playlist.attributes.name+"\n"

    if playlist.length > 0:
        track_uris = [track.uri for track in playlist.contents.items if not utils.is_local(track.uri)]
        tracks = sp.metadata_request(track_uris)
        for track in tracks:
            print track.name
    else:
        print "no tracks"

    print "\n"
예제 #4
0
def display_playlist(playlist):
    print playlist.attributes.name + "\n"

    if playlist.length > 0:
        track_uris = [
            track.uri for track in playlist.contents.items
            if not utils.is_local(track.uri)
        ]
        tracks = sp.metadata_request(track_uris)
        for track in tracks:
            print track.name
    else:
        print "no tracks"

    print "\n"