System Gen93 @ 2025-08-01-00:56:55 by jonas@monolith
This commit is contained in:
parent
0f8c6fc562
commit
9a056ce6b0
@ -8,6 +8,7 @@ setup(
|
||||
packages=find_packages(),
|
||||
entry_points={
|
||||
"console_scripts": [
|
||||
"spotisc=spotify_shortcuts.run:main",
|
||||
"spotify-like=spotify_shortcuts.spotify_like:main",
|
||||
"spotify-pl-add=spotify_shortcuts.spotify_pl_add:main",
|
||||
],
|
||||
|
||||
@ -2,8 +2,10 @@ from spotipy.oauth2 import SpotifyOAuth
|
||||
from spotipy import Spotify
|
||||
from spotify_shortcuts.config import Config
|
||||
|
||||
CALLBACK_URI = "http://127.0.0.1:45632/callback"
|
||||
|
||||
def authenticated_session(cfg: Config) -> Spotify:
|
||||
|
||||
def authenticated_session(cfg: Config, scopes: list[str]) -> Spotify:
|
||||
assert cfg.client_id, "Spotify client ID is required"
|
||||
assert cfg.client_secret, "Spotify client secret is required"
|
||||
|
||||
@ -11,8 +13,8 @@ def authenticated_session(cfg: Config) -> Spotify:
|
||||
auth_manager=SpotifyOAuth(
|
||||
client_id=cfg.client_id,
|
||||
client_secret=cfg.client_secret,
|
||||
redirect_uri="http://127.0.0.1:45632/callback",
|
||||
scope="user-library-read user-library-modify user-read-playback-state",
|
||||
redirect_uri=CALLBACK_URI,
|
||||
scope=" ".join(scopes),
|
||||
cache_path=cfg.cache_file,
|
||||
)
|
||||
)
|
||||
|
||||
@ -1,13 +1,18 @@
|
||||
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",
|
||||
]
|
||||
|
||||
def main():
|
||||
cfg = load_config()
|
||||
sp = authenticated_session(cfg)
|
||||
|
||||
if (playback := sp.current_playback()) is None:
|
||||
class SpotifyLike(Shortcut):
|
||||
def execute(self, client, config):
|
||||
if (playback := client.current_playback()) is None:
|
||||
print("No current playback found.")
|
||||
return
|
||||
|
||||
@ -15,9 +20,9 @@ def main():
|
||||
print("No track URI found in current playback.")
|
||||
return
|
||||
|
||||
sp.current_user_saved_tracks_add(tracks=[uri])
|
||||
client.current_user_saved_tracks_add(tracks=[uri])
|
||||
|
||||
if cfg.notifications:
|
||||
if config.notifications:
|
||||
dn = DesktopNotifierSync()
|
||||
dn.send(
|
||||
title="Track Liked",
|
||||
@ -26,6 +31,16 @@ def main():
|
||||
}\" has been liked.",
|
||||
)
|
||||
|
||||
def get_help(self) -> str:
|
||||
return "Like the currently playing track."
|
||||
|
||||
def get_scopes(self) -> list[str]:
|
||||
return SCOPES
|
||||
|
||||
|
||||
def main():
|
||||
run_shortcut(SpotifyLike(), load_config())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@ -1,13 +1,18 @@
|
||||
from spotify_shortcuts.spotify_auth import authenticated_session
|
||||
from spotify_shortcuts.shortcut import Shortcut
|
||||
from spotify_shortcuts.config import load_config
|
||||
from desktop_notifier import DesktopNotifierSync
|
||||
from spotify_shortcuts.run import run_shortcut
|
||||
|
||||
SCOPES = [
|
||||
"playlist-modify-public",
|
||||
"playlist-modify-private",
|
||||
"user-read-playback-state",
|
||||
]
|
||||
|
||||
|
||||
def main():
|
||||
cfg = load_config()
|
||||
sp = authenticated_session(cfg)
|
||||
|
||||
if (playback := sp.current_playback()) is None:
|
||||
class SpotifyPlAdd(Shortcut):
|
||||
def execute(self, client, config):
|
||||
if (playback := client.current_playback()) is None:
|
||||
print("No current playback found.")
|
||||
return
|
||||
|
||||
@ -19,15 +24,17 @@ def main():
|
||||
print("No context URI found in current playback.")
|
||||
return
|
||||
|
||||
sp.playlist_add_items(context_uri, items=[track_uri])
|
||||
client.playlist_add_items(context_uri, items=[track_uri])
|
||||
|
||||
if cfg.notifications:
|
||||
if config.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>")
|
||||
playlist_name = (client.playlist(context_uri) or {}).get(
|
||||
"name", "<no-name>"
|
||||
)
|
||||
|
||||
dn = DesktopNotifierSync()
|
||||
dn.send(
|
||||
@ -35,6 +42,16 @@ def main():
|
||||
message=f'Track "{track_name}" by "{artists}" has been added to {playlist_name}.',
|
||||
)
|
||||
|
||||
def get_help(self) -> str:
|
||||
return "Add the currently playing track to the current playlist."
|
||||
|
||||
def get_scopes(self) -> list[str]:
|
||||
return SCOPES
|
||||
|
||||
|
||||
def main():
|
||||
run_shortcut(SpotifyPlAdd(), load_config())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user