System Gen93 @ 2025-08-01-00:56:55 by jonas@monolith
This commit is contained in:
@@ -1,30 +1,45 @@
|
||||
from spotify_shortcuts.spotify_auth import authenticated_session
|
||||
from spotify_shortcuts.run import run_shortcut
|
||||
from spotify_shortcuts.shortcut import Shortcut
|
||||
from spotify_shortcuts.config import load_config
|
||||
from desktop_notifier import DesktopNotifierSync
|
||||
|
||||
SCOPES = [
|
||||
"user-library-read",
|
||||
"user-library-modify",
|
||||
"user-read-playback-state",
|
||||
]
|
||||
|
||||
|
||||
class SpotifyLike(Shortcut):
|
||||
def execute(self, client, config):
|
||||
if (playback := client.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
|
||||
|
||||
client.current_user_saved_tracks_add(tracks=[uri])
|
||||
|
||||
if config.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.",
|
||||
)
|
||||
|
||||
def get_help(self) -> str:
|
||||
return "Like the currently playing track."
|
||||
|
||||
def get_scopes(self) -> list[str]:
|
||||
return SCOPES
|
||||
|
||||
|
||||
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.",
|
||||
)
|
||||
run_shortcut(SpotifyLike(), load_config())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user