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(),
|
packages=find_packages(),
|
||||||
entry_points={
|
entry_points={
|
||||||
"console_scripts": [
|
"console_scripts": [
|
||||||
|
"spotisc=spotify_shortcuts.run:main",
|
||||||
"spotify-like=spotify_shortcuts.spotify_like:main",
|
"spotify-like=spotify_shortcuts.spotify_like:main",
|
||||||
"spotify-pl-add=spotify_shortcuts.spotify_pl_add:main",
|
"spotify-pl-add=spotify_shortcuts.spotify_pl_add:main",
|
||||||
],
|
],
|
||||||
|
|||||||
@ -2,8 +2,10 @@ from spotipy.oauth2 import SpotifyOAuth
|
|||||||
from spotipy import Spotify
|
from spotipy import Spotify
|
||||||
from spotify_shortcuts.config import Config
|
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_id, "Spotify client ID is required"
|
||||||
assert cfg.client_secret, "Spotify client secret is required"
|
assert cfg.client_secret, "Spotify client secret is required"
|
||||||
|
|
||||||
@ -11,8 +13,8 @@ def authenticated_session(cfg: Config) -> Spotify:
|
|||||||
auth_manager=SpotifyOAuth(
|
auth_manager=SpotifyOAuth(
|
||||||
client_id=cfg.client_id,
|
client_id=cfg.client_id,
|
||||||
client_secret=cfg.client_secret,
|
client_secret=cfg.client_secret,
|
||||||
redirect_uri="http://127.0.0.1:45632/callback",
|
redirect_uri=CALLBACK_URI,
|
||||||
scope="user-library-read user-library-modify user-read-playback-state",
|
scope=" ".join(scopes),
|
||||||
cache_path=cfg.cache_file,
|
cache_path=cfg.cache_file,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@ -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 spotify_shortcuts.config import load_config
|
||||||
from desktop_notifier import DesktopNotifierSync
|
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():
|
def main():
|
||||||
cfg = load_config()
|
run_shortcut(SpotifyLike(), 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__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@ -1,39 +1,56 @@
|
|||||||
from spotify_shortcuts.spotify_auth import authenticated_session
|
from spotify_shortcuts.shortcut import Shortcut
|
||||||
from spotify_shortcuts.config import load_config
|
from spotify_shortcuts.config import load_config
|
||||||
from desktop_notifier import DesktopNotifierSync
|
from desktop_notifier import DesktopNotifierSync
|
||||||
|
from spotify_shortcuts.run import run_shortcut
|
||||||
|
|
||||||
|
SCOPES = [
|
||||||
|
"playlist-modify-public",
|
||||||
|
"playlist-modify-private",
|
||||||
|
"user-read-playback-state",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class SpotifyPlAdd(Shortcut):
|
||||||
|
def execute(self, client, config):
|
||||||
|
if (playback := client.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
|
||||||
|
|
||||||
|
client.playlist_add_items(context_uri, items=[track_uri])
|
||||||
|
|
||||||
|
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 = (client.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}.',
|
||||||
|
)
|
||||||
|
|
||||||
|
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():
|
def main():
|
||||||
cfg = load_config()
|
run_shortcut(SpotifyPlAdd(), 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__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user