System Gen91 @ 2025-07-27-18:31:26 by jonas@monolith
This commit is contained in:
parent
818c017614
commit
283f0febef
40
pkgs/spotify-shortcuts/spotify_shortcuts/spotify_pl_add.py
Normal file
40
pkgs/spotify-shortcuts/spotify_shortcuts/spotify_pl_add.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
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 (track_uri := playback.get("item", {}).get("uri", None)) is None:
|
||||||
|
print("No track URI found in current playback.")
|
||||||
|
return
|
||||||
|
|
||||||
|
if (context_uri := playback.get("context", {}).get("uri", None)) is None:
|
||||||
|
print("No context URI found in current playback.")
|
||||||
|
return
|
||||||
|
|
||||||
|
sp.playlist_add_items(context_uri, items=[track_uri])
|
||||||
|
|
||||||
|
if cfg.notifications:
|
||||||
|
track_name = playback.get("item", {}).get("name", "<no-name>")
|
||||||
|
artists = ", ".join(
|
||||||
|
a.get("name", "<no-name>")
|
||||||
|
for a in playback.get("item", {}).get("artists", [])
|
||||||
|
)
|
||||||
|
playlist_name = (sp.playlist(context_uri) or {}).get("name", "<no-name>")
|
||||||
|
|
||||||
|
dn = DesktopNotifierSync()
|
||||||
|
dn.send(
|
||||||
|
title="Track Added to Playlist",
|
||||||
|
message=f'Track "{track_name}" by "{artists}" has been added to {playlist_name}.',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
x
Reference in New Issue
Block a user