From 87e526dec70e3d21023a6597acc059772bb7b83d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20R=C3=B6ger?= Date: Fri, 25 Jul 2025 01:02:06 +0200 Subject: [PATCH] System Gen89 @ 2025-07-25-01:02:05 by jonas@monolith --- pkgs/spotify-shortcuts/derivation.nix | 2 +- pkgs/spotify-shortcuts/shell.nix | 23 ++++++++++++------- .../spotify_shortcuts/config.py | 14 ++++++++++- .../spotify_shortcuts/spotify_like.py | 10 ++++++++ 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/pkgs/spotify-shortcuts/derivation.nix b/pkgs/spotify-shortcuts/derivation.nix index f4cb8a5..8906869 100644 --- a/pkgs/spotify-shortcuts/derivation.nix +++ b/pkgs/spotify-shortcuts/derivation.nix @@ -2,6 +2,6 @@ with python3Packages; buildPythonApplication { name = "spotify-shortcuts"; - propagatedBuildInputs = [spotipy pyxdg]; + propagatedBuildInputs = [spotipy pyxdg desktop-notifier]; src = ./.; } diff --git a/pkgs/spotify-shortcuts/shell.nix b/pkgs/spotify-shortcuts/shell.nix index c41f7d0..a863d83 100644 --- a/pkgs/spotify-shortcuts/shell.nix +++ b/pkgs/spotify-shortcuts/shell.nix @@ -1,8 +1,15 @@ -{pkgs ? import {}}: -pkgs.mkShell { - packages = [ - pkgs.pyright - pkgs.black - ]; - inputsFrom = [(pkgs.callPackage ./derivation.nix {})]; -} +{pkgs ? import {}}: let + drv = pkgs.callPackage ./derivation.nix {}; +in + pkgs.mkShell { + packages = [ + pkgs.pyright + pkgs.black + ]; + + inputsFrom = [drv]; + + shellHook = '' + export PYTHONPATH="$PYTHONPATH:$(pwd)" + ''; + } diff --git a/pkgs/spotify-shortcuts/spotify_shortcuts/config.py b/pkgs/spotify-shortcuts/spotify_shortcuts/config.py index c997893..69901e1 100644 --- a/pkgs/spotify-shortcuts/spotify_shortcuts/config.py +++ b/pkgs/spotify-shortcuts/spotify_shortcuts/config.py @@ -13,6 +13,7 @@ class Config: cache_file: Path = Path(xdg_cache_home) / Path("spotify-shortcuts.json") client_id: str | None = None client_secret: str | None = None + notifications: bool = True @staticmethod def from_file(path: Path): @@ -48,15 +49,26 @@ def load_config(args: List[str] = argv[1:]) -> Config: default=Config.client_secret, help="Spotify API Client Secret", ) + parser.add_argument( + "--config-file", + type=str, + help="Path to a json configuration file with keys clientId and clientSecret", + ) + parser.add_argument( + "--no-notifications", + action="store_true", + help="Disable desktop notifications", + ) ns = parser.parse_args(args) cfg = Config() - if (cfg_file := getenv("SPOTIFY_SHORTCUTS_CONFIG", None)) != None: + if (cfg_file := ns.config_file or getenv("SPOTIFY_SHORTCUTS_CONFIG", None)) != None: cfg = Config.from_file(Path(cfg_file)) return Config( cache_file=ns.cache_file or cfg.cache_file, client_id=ns.client_id or cfg.client_id, client_secret=ns.client_secret or cfg.client_secret, + notifications=not ns.no_notifications or cfg.notifications, ) diff --git a/pkgs/spotify-shortcuts/spotify_shortcuts/spotify_like.py b/pkgs/spotify-shortcuts/spotify_shortcuts/spotify_like.py index b0ebd78..a38ad2a 100644 --- a/pkgs/spotify-shortcuts/spotify_shortcuts/spotify_like.py +++ b/pkgs/spotify-shortcuts/spotify_shortcuts/spotify_like.py @@ -1,5 +1,6 @@ from spotify_shortcuts.spotify_auth import authenticated_session from spotify_shortcuts.config import load_config +from desktop_notifier import DesktopNotifierSync def main(): @@ -16,6 +17,15 @@ def main(): 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', '')}\" by \"{ + ", ".join(a.get('name', '') for a in playback.get('item', {}).get('artists', [])) + }\" has been liked.", + ) + if __name__ == "__main__": main()