32 lines
931 B
Python
32 lines
931 B
Python
from spotify_shortcuts.spotify_auth import authenticated_session
|
|
from spotify_shortcuts.config import load_config
|
|
from desktop_notifier import DesktopNotifierSync
|
|
|
|
|
|
def main():
|
|
cfg = load_config()
|
|
sp = authenticated_session(cfg)
|
|
|
|
if (playback := sp.current_playback()) is None:
|
|
print("No current playback found.")
|
|
return
|
|
|
|
if (uri := playback.get("item", {}).get("uri", None)) is None:
|
|
print("No track URI found in current playback.")
|
|
return
|
|
|
|
sp.current_user_saved_tracks_add(tracks=[uri])
|
|
|
|
if cfg.notifications:
|
|
dn = DesktopNotifierSync()
|
|
dn.send(
|
|
title="Track Liked",
|
|
message=f"Track \"{playback.get('item', {}).get('name', '<no-name>')}\" by \"{
|
|
", ".join(a.get('name', '<no-name>') for a in playback.get('item', {}).get('artists', []))
|
|
}\" has been liked.",
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|