(self)
return True
Fetches metadata for this song's uri from Spotify.
Fetches metadata for this song's uri from Spotify.
Fetches metadata for this song s uri from Spotify .
def gather_metadata(self) -> bool:
        """Fetches metadata for this song's uri from Spotify."""
        if not self.id:
            results = self.web_client.get(
                "search",
                params={
                    "q": self.query,
                    "limit": "50",
                    "market": "from_token",
                    "type": "track",
                },
            )

            # apply the filterlist from the settings
            for item in results["tracks"]["items"]:
                artist = item["artists"][0]["name"]
                title = item["name"]
                if song_utils.is_forbidden(artist) or song_utils.is_forbidden(title):
                    continue
                result = item
                break
            else:
                # all tracks got filtered
                self.error = "All results filtered"
                return False
            self.id = result["id"]
        else:
            result = self.web_client.get(f"tracks/{self.id}", params={"limit": "1"})
        try:
            self.metadata["artist"] = result["artists"][0]["name"]
            self.metadata["title"] = result["name"]
            self.metadata["duration"] = result["duration_ms"] / 1000
            self.metadata["internal_url"] = result["uri"]
            self.metadata["external_url"] = result["external_urls"]["spotify"]
            self.metadata["stream_url"] = None
            self.metadata["cached"] = False
        except KeyError:
            self.error = "No song found"
            return False
        return True
def gather_metadata ( self ) -> bool : if not self . id : results = self . web_client . get ( "search" , params = { "q" : self . query , "limit" : "50" , "market" : "from_token" , "type" : "track" , } , ) # apply the filterlist from the settings for item in results [ "tracks" ] [ "items" ] : artist = item [ "artists" ] [ 0 ] [ "name" ] title = item [ "name" ] if song_utils . is_forbidden ( artist ) or song_utils . is_forbidden ( title ) : continue result = item break else : # all tracks got filtered self . error = "All results filtered" return False self . id = result [ "id" ] else : result = self . web_client . get ( f"tracks/{self.id}" , params = { "limit" : "1" } ) try : self . metadata [ "artist" ] = result [ "artists" ] [ 0 ] [ "name" ] self . metadata [ "title" ] = result [ "name" ] self . metadata [ "duration" ] = result [ "duration_ms" ] / 1000 self . metadata [ "internal_url" ] = result [ "uri" ] self . metadata [ "external_url" ] = result [ "external_urls" ] [ "spotify" ] self . metadata [ "stream_url" ] = None self . metadata [ "cached" ] = False except KeyError : self . error = "No song found" return False return True