diff options
Diffstat (limited to 'spotify.py')
-rwxr-xr-x | spotify.py | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/spotify.py b/spotify.py index e9b0790..609b2e2 100755 --- a/spotify.py +++ b/spotify.py @@ -48,24 +48,22 @@ class Spotify: p = self.parseprop() data = urlopen(url).read().decode() p.feed(data) - irc_string = "[\x0304Spotify\x03] \x0307ERROR:\x0308 got no data from server! \x0315(check your URL for typos!)\x03" + irc_string = ( + "[\x0304Spotify\x03] \x0307ERROR:\x0308 got no data from server! \x0315(check your URL for typos!)\x03" + ) ansi_string = "[\x1b[31mSpotify\x1b[0m] \x1b[33;2mERROR:\x1b[33;1m got no data from server! \x1b[37;2m(check your URL for typos!)\x1b[0m" data = json.loads(Spotify.ldjson) try: type = data["@type"] except KeyError: - print(ansi_string) + if __import__("sys").stdout.isatty(): + print(ansi_string) return irc_string, True id = data["@id"] name = data["name"] date = data["datePublished"] artists = data["description"] - artists = ( - artists.removeprefix(f"Listen to {name} on Spotify") - .removeprefix(".") - .strip() - .removeprefix("· ") - ) + artists = artists.removeprefix(f"Listen to {name} on Spotify").removeprefix(".").strip().removeprefix("· ") if artists.startswith("Song · "): artists = artists.removeprefix("Song · ") elif artists.startswith("Album · "): @@ -77,7 +75,8 @@ class Spotify: ansi_string = f"[\x1b[32mSpotify\x1b[0m] \x1b[1m{name}\x1b[0m by \x1b[03m{artists}\x1b[0m published on {date}" # print(("Song: " if type=="MusicRecording" else "Album: " if type=="MusicAlbum" else f"Unknown type ({type}): ")+'"'+name+'"'+" by "+'"'+artists+'"'+" released on "+date) # irc_string="dummy" - print(ansi_string) + if __import__("sys").stdout.isatty(): + print(ansi_string) return irc_string, False |