def metadata_request(self, uris, callback=False):
        mercury_requests = mercury_pb2.MercuryMultiGetRequest()

        if type(uris) != list:
            uris = [uris]

        for uri in uris:
            uri_type = utils.get_uri_type(uri)
            if uri_type == "local":
                logger.warning(
                    "Track with URI {0} is a local track, we can't " "request metadata, skipping".format(uri)
                )
                continue

            sid = utils.uri2id(uri)

            mercury_request = mercury_pb2.MercuryRequest()
            mercury_request.body = "GET"
            mercury_request.uri = "hm://metadata/" + uri_type + "/" + sid

            mercury_requests.request.extend([mercury_request])

        args = self.generate_multiget_args(utils.get_uri_type(uris[0]), mercury_requests)

        return self.wrap_request("sp/hm_b64", args, callback, self.parse_metadata)
    def metadata_request(self, uris, callback=False):
        mercury_requests = mercury_pb2.MercuryMultiGetRequest()

        if type(uris) != list:
            uris = [uris]

        for uri in uris:
            uri_type = utils.get_uri_type(uri)
            if uri_type == "local":
                logger.warning("Track with URI {0} is a local track, we can't "
                               "request metadata, skipping".format(uri))
                continue

            sid = utils.uri2id(uri)

            mercury_request = mercury_pb2.MercuryRequest()
            mercury_request.body = "GET"
            mercury_request.uri = "hm://metadata/" + uri_type + "/" + sid

            mercury_requests.request.extend([mercury_request])

        args = self.generate_multiget_args(utils.get_uri_type(uris[0]),
                                           mercury_requests)

        return self.wrap_request("sp/hm_b64", args, callback,
                                 self.parse_metadata)
    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
    def get(self, uri):
        cache = {
            "track": self.track_cache,
            "album": self.album_cache,
            "artist": self.artist_cache,
        }

        uri_type = utils.get_uri_type(uri)
        if uri_type not in cache:
            return False
    def get(self, uri):
        cache = {
            "track": self.track_cache,
            "album": self.album_cache,
            "artist": self.artist_cache,
        }

        uri_type = utils.get_uri_type(uri)
        if uri_type not in cache:
            return False
    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