refactor modules

This commit is contained in:
2026-03-29 17:10:57 +02:00
parent 0b0dd1a1ba
commit a13add9b81
31 changed files with 33 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
from spotify_shortcuts.config import Config, load_config
from spotify_shortcuts.shortcut import Shortcut
from spotify_shortcuts.spotify_auth import authenticated_session
from itertools import chain
def all_scopes() -> list[str]:
from spotify_shortcuts.registry import SHORTCUT_REGISTRY
return list(
set(
chain.from_iterable(
shortcut.get_scopes() for shortcut in SHORTCUT_REGISTRY.values()
)
)
)
def run_shortcut(shortcut: Shortcut, config: Config):
client = authenticated_session(
config, scopes=all_scopes() # use all scopes to avoid re-authentication
)
shortcut.execute(client, config)
def main():
from spotify_shortcuts.registry import SHORTCUT_REGISTRY
import sys
if len(sys.argv) < 2:
print(f"Usage: {sys.argv[0]} <shortcut_name>")
sys.exit(1)
shortcut_name = sys.argv[1]
if shortcut_name not in SHORTCUT_REGISTRY:
print(f"Shortcut '{shortcut_name}' not found.")
sys.exit(1)
shortcut = SHORTCUT_REGISTRY[shortcut_name]
config = load_config(args=sys.argv[2:])
run_shortcut(shortcut, config)
if __name__ == "__main__":
main()