dendrify: comfy-station
This commit is contained in:
1
packages/bulk-transcode/.envrc
Normal file
1
packages/bulk-transcode/.envrc
Normal file
@@ -0,0 +1 @@
|
||||
use flake ../../#bulk-transcode --show-trace
|
||||
96
packages/bulk-transcode/bulk-transcode.sh
Normal file
96
packages/bulk-transcode/bulk-transcode.sh
Normal file
@@ -0,0 +1,96 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
declare -rA presets=(
|
||||
[davinci-resolve]="-c:v dnxhd -profile:v dnxhr_hq -pix_fmt yuv422p -c:a pcm_s16le"
|
||||
[instagram]="-vf scale='if(gte(iw/ih,1),1920,-1)':'if(gte(iw/ih,1),-1,1920)':flags=lanczos -r 30 -c:v libx264 -profile:v high -level 4.1 -pix_fmt yuv420p -preset slow -crf 18 -bf 2 -g 15 -keyint_min 15 -x264-params \"open-gop=0:cabac=1:b-pyramid=none\" -movflags +faststart -c:a aac -b:a 96k"
|
||||
[insta-4k]="-r 30 -c:v libx264 -profile:v high -level 4.1 -pix_fmt yuv420p -preset slow -crf 18 -bf 2 -g 15 -keyint_min 15 -x264-params \"open-gop=0:cabac=1:b-pyramid=none\" -movflags +faststart -c:a aac -b:a 96k"
|
||||
[storage-hevc]="-c:v libx265 -preset slower -crf 18 -pix_fmt yuv420p10le -x265-params aq-mode=3:aq-strength=1.0:psy-rd=1.8:psy-rdoq=1.0 -c:a copy"
|
||||
[storage-av1]="-c:v libsvtav1 -preset 6 -crf 28 -pix_fmt yuv420p -g 240 -svtav1-params tune=0:aq-mode=2 -c:a copy"
|
||||
[storage-av1-1080p]="-vf scale='if(gte(iw/ih,1),1920,-1)':'if(gte(iw/ih,1),-1,1920)' -c:v libsvtav1 -preset 6 -crf 28 -pix_fmt yuv420p -g 240 -svtav1-params tune=0:aq-mode=2 -c:a copy"
|
||||
[storage-av1-nvenc]="-c:v av1_nvenc -cq 28 -preset slow -pix_fmt yuv420p10le -c:a copy"
|
||||
[network]="-c:v libx264 -preset slow -crf 22 -pix_fmt yuv420p -c:a aac -b:a 128k"
|
||||
[network-1080p]="-vf scale='if(gte(iw/ih,1),1920,-1)':'if(gte(iw/ih,1),-1,1920)' -c:v libx264 -preset slow -crf 22 -pix_fmt yuv420p -c:a aac -b:a 128k"
|
||||
[whatsapp]="-vf scale='if(gte(iw/ih,1),1920,-1)':'if(gte(iw/ih,1),-1,1920)' -c:v libx264 -preset slow -crf 30 -profile:v baseline -level 3.0 -pix_fmt yuv420p -r 25 -g 50 -c:a aac -b:a 160k -r:a 44100"
|
||||
)
|
||||
|
||||
declare -rA containers=(
|
||||
[davinci-resolve]="mov"
|
||||
[instagram]="mp4"
|
||||
[insta-4k]="mp4"
|
||||
[storage-hevc]="mkv"
|
||||
[storage-av1]="mkv"
|
||||
[storage-av1-1080p]="mkv"
|
||||
[storage-av1-nvenc]="mkv"
|
||||
[network]="mp4"
|
||||
[network-1080p]="mp4"
|
||||
[whatsapp]="mp4"
|
||||
)
|
||||
|
||||
where="${1:-.}"
|
||||
dest="${2:-$where}"
|
||||
|
||||
selection=$(find "$where" -type f | fzf --multi --preview 'ffprobe -v error -show_format -show_streams {}' --preview-window=up:wrap)
|
||||
|
||||
preset=$(
|
||||
printf '%s\n' "${!presets[@]}" | \
|
||||
fzf --multi --prompt "Select a preset"
|
||||
)
|
||||
flags="${presets[$preset]}"
|
||||
container="${containers[$preset]}"
|
||||
|
||||
output_dir=$(find "$dest" -type d ! -name '.*' ! -path '*/.*/*' | fzf --preview 'tree -C {}' --preview-window=up:wrap --prompt "Select output directory: ")
|
||||
|
||||
if gum confirm "Flatten the directory structure?";
|
||||
then
|
||||
flatten=true
|
||||
else
|
||||
flatten=false
|
||||
fi
|
||||
|
||||
|
||||
function transcode_job {
|
||||
local ifile="$1"
|
||||
local output_dir="$2"
|
||||
local flatten="$3"
|
||||
local where="$4"
|
||||
local flags="$5"
|
||||
local container="$6"
|
||||
local fname=$(basename "$ifile")
|
||||
local segment=$(realpath --relative-to="$where" "$ifile")
|
||||
|
||||
|
||||
if [ "$flatten" = true ]; then
|
||||
output_file="$output_dir/$fname.$container"
|
||||
else
|
||||
output_file="$output_dir/$segment.$container"
|
||||
fi
|
||||
|
||||
tmp_file=$(mktemp)
|
||||
|
||||
echo "Running Command: ffmpeg -y -i $ifile $flags $output_file" >> "$tmp_file"
|
||||
|
||||
mkdir -p "$(dirname "$output_file")"
|
||||
|
||||
if ffmpeg -y -i "$ifile" $(echo -n "$flags") "$output_file" 2>> "$tmp_file";
|
||||
then
|
||||
rm -f "$tmp_file"
|
||||
else
|
||||
# gum log "Failed to transcode $ifile. Check ./error.log for details."
|
||||
cat "$tmp_file" >> error.log
|
||||
rm -f "$tmp_file"
|
||||
|
||||
fi
|
||||
}
|
||||
export -f transcode_job
|
||||
|
||||
mapfile -t files <<< "$selection"
|
||||
len=${#files[@]}
|
||||
i=1
|
||||
for file in "${files[@]}"; do
|
||||
if [[ -f "$file" ]]; then
|
||||
gum spin --spinner dot --title "[$i/$len] Transcoding $file" -- bash -c "source <(declare -f transcode_job); transcode_job \"$file\" \"$output_dir\" \"$flatten\" \"$where\" \"$flags\" \"$container\""
|
||||
else
|
||||
echo "Skipping invalid file: $file" >&2
|
||||
fi
|
||||
((i++))
|
||||
done
|
||||
9
packages/bulk-transcode/default.nix
Normal file
9
packages/bulk-transcode/default.nix
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
flake.overlays.bulk-transcode = final: prev: {
|
||||
bulk-transcode = import ./overlay.nix {inherit final prev;};
|
||||
};
|
||||
perSystem = {pkgs, ...}: {
|
||||
packages.bulk-transcode = pkgs.callPackage ./derivation.nix {};
|
||||
devShells.bulk-transcode = import ./shell.nix {inherit pkgs;};
|
||||
};
|
||||
}
|
||||
35
packages/bulk-transcode/derivation.nix
Normal file
35
packages/bulk-transcode/derivation.nix
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
bash,
|
||||
coreutils,
|
||||
ffmpeg,
|
||||
findutils,
|
||||
fzf,
|
||||
gum,
|
||||
lib,
|
||||
makeWrapper,
|
||||
stdenv,
|
||||
tree,
|
||||
...
|
||||
}:
|
||||
stdenv.mkDerivation (finalAttrs: {
|
||||
name = "bulk-transcode";
|
||||
src = ./.;
|
||||
|
||||
buildInputs = [
|
||||
bash
|
||||
coreutils
|
||||
ffmpeg
|
||||
findutils
|
||||
fzf
|
||||
gum
|
||||
makeWrapper
|
||||
tree
|
||||
];
|
||||
|
||||
installPhase = ''
|
||||
install -Dm755 bulk-transcode.sh $out/bin/bulk-transcode
|
||||
|
||||
wrapProgram $out/bin/bulk-transcode \
|
||||
--set PATH "${lib.makeBinPath finalAttrs.buildInputs}"
|
||||
'';
|
||||
})
|
||||
7
packages/bulk-transcode/shell.nix
Normal file
7
packages/bulk-transcode/shell.nix
Normal file
@@ -0,0 +1,7 @@
|
||||
{pkgs ? import <nixpkgs> {}}: let
|
||||
bin = pkgs.callPackage ./derivation.nix {};
|
||||
in
|
||||
pkgs.mkShell {
|
||||
name = "bulk-transcode";
|
||||
inputsFrom = [bin];
|
||||
}
|
||||
40
packages/crossover.nix
Normal file
40
packages/crossover.nix
Normal file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
appimageTools,
|
||||
fetchurl,
|
||||
makeWrapper,
|
||||
...
|
||||
}: let
|
||||
pname = "crossover";
|
||||
version = "3.1.5";
|
||||
src = fetchurl {
|
||||
url = "https://github.com/lacymorrow/crossover/releases/download/v${version}/CrossOver-${version}-x86_64.AppImage";
|
||||
sha256 = "sha256-64RPal8n1PJh1LB+CTyNFt04Pw1lVgcsyc63S8yQ/DA=";
|
||||
};
|
||||
appimageContents = appimageTools.extract {
|
||||
inherit pname version src;
|
||||
};
|
||||
in
|
||||
appimageTools.wrapType2 {
|
||||
inherit pname version src;
|
||||
|
||||
nativeBuildInputs = [makeWrapper];
|
||||
extraInstallCommands = ''
|
||||
wrapProgram $out/bin/${pname} --add-flags "--no-sandbox"
|
||||
|
||||
# Create a minimal .desktop file manually
|
||||
mkdir -p $out/share/applications
|
||||
cat > $out/share/applications/${pname}.desktop <<EOF
|
||||
[Desktop Entry]
|
||||
Name=${pname}
|
||||
Exec=${pname} %U
|
||||
Icon=${pname}
|
||||
Type=Application
|
||||
Categories=Utility;
|
||||
EOF
|
||||
|
||||
# Optionally extract icon from AppImage (if available)
|
||||
# You can also manually install an icon here:
|
||||
mkdir -p $out/share/icons/hicolor/0x0/apps
|
||||
cp ${appimageContents}/usr/share/icons/hicolor/0x0/apps/${pname}.png $out/share/icons/hicolor/0x0/apps/${pname}.png || true
|
||||
'';
|
||||
}
|
||||
8
packages/default.nix
Normal file
8
packages/default.nix
Normal file
@@ -0,0 +1,8 @@
|
||||
final: _: {
|
||||
hive = {
|
||||
crossover = final.callPackage ./crossover.nix {};
|
||||
bulk-transcode = final.callPackage ./bulk-transcode {};
|
||||
spotify-shortcuts = final.callPackage ./spotify-shortcuts/derivation.nix {};
|
||||
layan-qt6 = final.kdePackages.callPackage ./layan-qt6.nix {};
|
||||
};
|
||||
}
|
||||
52
packages/layan-qt6.nix
Normal file
52
packages/layan-qt6.nix
Normal file
@@ -0,0 +1,52 @@
|
||||
{
|
||||
stdenv,
|
||||
lib,
|
||||
fetchFromGitHub,
|
||||
gitUpdater,
|
||||
kdeclarative,
|
||||
libplasma,
|
||||
plasma-workspace,
|
||||
}:
|
||||
stdenv.mkDerivation {
|
||||
pname = "layan-kde-qt6";
|
||||
version = "2025-02-13";
|
||||
src = fetchFromGitHub {
|
||||
owner = "vinceliuice";
|
||||
repo = "Layan-kde";
|
||||
rev = "ace0b1d93e5f08c650630c146b2d637e1e2e6cd1";
|
||||
hash = "sha256-T69bGjfZeOsJLmOZKps9N2wMv5VKYeo1ipGEsLAS+Sg=";
|
||||
};
|
||||
|
||||
# Propagate sddm theme dependencies to user env otherwise sddm does
|
||||
# not find them. Putting them in buildInputs is not enough.
|
||||
propagatedUserEnvPkgs = [
|
||||
kdeclarative
|
||||
libplasma
|
||||
plasma-workspace
|
||||
];
|
||||
|
||||
postPatch = ''
|
||||
patchShebangs install.sh
|
||||
|
||||
substituteInPlace install.sh \
|
||||
--replace '$HOME/.local' $out \
|
||||
--replace '$HOME/.config' $out/share
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
|
||||
name= ./install.sh --dest $out/share/themes
|
||||
|
||||
runHook postInstall
|
||||
'';
|
||||
|
||||
passthru.updateScript = gitUpdater {};
|
||||
|
||||
meta = with lib; {
|
||||
description = "Flat Design theme for KDE Plasma desktop";
|
||||
homepage = "https://github.com/vinceliuice/Layan-kde";
|
||||
license = licenses.gpl3Only;
|
||||
platforms = platforms.all;
|
||||
};
|
||||
}
|
||||
1
packages/spotify-shortcuts/.envrc
Normal file
1
packages/spotify-shortcuts/.envrc
Normal file
@@ -0,0 +1 @@
|
||||
use flake ../../#spotify-shortcuts --show-trace
|
||||
2
packages/spotify-shortcuts/default.nix
Normal file
2
packages/spotify-shortcuts/default.nix
Normal file
@@ -0,0 +1,2 @@
|
||||
{pkgs ? import <nixpkgs> {}}:
|
||||
pkgs.callPackage ./derivation.nix {}
|
||||
9
packages/spotify-shortcuts/derivation.nix
Normal file
9
packages/spotify-shortcuts/derivation.nix
Normal file
@@ -0,0 +1,9 @@
|
||||
{python3Packages}:
|
||||
with python3Packages;
|
||||
buildPythonApplication {
|
||||
name = "spotify-shortcuts";
|
||||
propagatedBuildInputs = [spotipy pyxdg desktop-notifier];
|
||||
pyproject = true;
|
||||
build-system = [setuptools];
|
||||
src = ./.;
|
||||
}
|
||||
16
packages/spotify-shortcuts/setup.py
Normal file
16
packages/spotify-shortcuts/setup.py
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
setup(
|
||||
name="spotify_shortcuts",
|
||||
version="1.0",
|
||||
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",
|
||||
],
|
||||
},
|
||||
)
|
||||
15
packages/spotify-shortcuts/shell.nix
Normal file
15
packages/spotify-shortcuts/shell.nix
Normal file
@@ -0,0 +1,15 @@
|
||||
{pkgs ? import <nixpkgs> {}}: let
|
||||
drv = pkgs.callPackage ./derivation.nix {};
|
||||
in
|
||||
pkgs.mkShell {
|
||||
packages = [
|
||||
pkgs.pyright
|
||||
pkgs.black
|
||||
];
|
||||
|
||||
inputsFrom = [drv];
|
||||
|
||||
shellHook = ''
|
||||
export PYTHONPATH="$PYTHONPATH:$(pwd)"
|
||||
'';
|
||||
}
|
||||
4
packages/spotify-shortcuts/spotify_shortcuts/__main__.py
Normal file
4
packages/spotify-shortcuts/spotify_shortcuts/__main__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from spotify_shortcuts.run import main
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
74
packages/spotify-shortcuts/spotify_shortcuts/config.py
Normal file
74
packages/spotify-shortcuts/spotify_shortcuts/config.py
Normal file
@@ -0,0 +1,74 @@
|
||||
from pathlib import Path
|
||||
from dataclasses import dataclass
|
||||
from argparse import ArgumentParser
|
||||
from typing import List
|
||||
from os import getenv
|
||||
from sys import argv
|
||||
from xdg.BaseDirectory import xdg_cache_home
|
||||
from json import loads
|
||||
|
||||
|
||||
@dataclass
|
||||
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):
|
||||
if not path.exists():
|
||||
raise FileNotFoundError(f"Configuration file {path} does not exist.")
|
||||
with open(path, "r") as f:
|
||||
data = loads(f.read())
|
||||
|
||||
return Config(
|
||||
cache_file=Path(data.get("cacheFile", Config.cache_file)),
|
||||
client_id=data.get("clientId", Config.client_id),
|
||||
client_secret=data.get("clientSecret", Config.client_secret),
|
||||
)
|
||||
|
||||
|
||||
def load_config(args: List[str] = argv[1:]) -> Config:
|
||||
parser = ArgumentParser(description="Spotify CLI Tool")
|
||||
parser.add_argument(
|
||||
"--cache-file",
|
||||
type=Path,
|
||||
default=Config.cache_file,
|
||||
help="Path to the cache file for Spotify authentication",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--client-id",
|
||||
type=str,
|
||||
default=Config.client_id,
|
||||
help="Spotify API Client ID",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--client-secret",
|
||||
type=str,
|
||||
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 := 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,
|
||||
)
|
||||
7
packages/spotify-shortcuts/spotify_shortcuts/registry.py
Normal file
7
packages/spotify-shortcuts/spotify_shortcuts/registry.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from spotify_shortcuts.spotify_like import SpotifyLike
|
||||
from spotify_shortcuts.spotify_pl_add import SpotifyPlAdd
|
||||
|
||||
SHORTCUT_REGISTRY = {
|
||||
"like": SpotifyLike(),
|
||||
"pl_add": SpotifyPlAdd(),
|
||||
}
|
||||
47
packages/spotify-shortcuts/spotify_shortcuts/run.py
Normal file
47
packages/spotify-shortcuts/spotify_shortcuts/run.py
Normal 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()
|
||||
21
packages/spotify-shortcuts/spotify_shortcuts/shortcut.py
Normal file
21
packages/spotify-shortcuts/spotify_shortcuts/shortcut.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from spotify_shortcuts.config import Config
|
||||
from spotipy import Spotify
|
||||
|
||||
|
||||
class Shortcut(ABC):
|
||||
@abstractmethod
|
||||
def execute(self, client: Spotify, config: Config):
|
||||
"""Execute the shortcut action."""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_help(self) -> str:
|
||||
"""Return a description of the shortcut."""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_scopes(self) -> list[str]:
|
||||
"""Return the spotify API scopes required for the shortcut."""
|
||||
pass
|
||||
20
packages/spotify-shortcuts/spotify_shortcuts/spotify_auth.py
Normal file
20
packages/spotify-shortcuts/spotify_shortcuts/spotify_auth.py
Normal file
@@ -0,0 +1,20 @@
|
||||
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, scopes: list[str]) -> Spotify:
|
||||
assert cfg.client_id, "Spotify client ID is required"
|
||||
assert cfg.client_secret, "Spotify client secret is required"
|
||||
|
||||
return Spotify(
|
||||
auth_manager=SpotifyOAuth(
|
||||
client_id=cfg.client_id,
|
||||
client_secret=cfg.client_secret,
|
||||
redirect_uri=CALLBACK_URI,
|
||||
scope=" ".join(scopes),
|
||||
cache_path=cfg.cache_file,
|
||||
)
|
||||
)
|
||||
46
packages/spotify-shortcuts/spotify_shortcuts/spotify_like.py
Normal file
46
packages/spotify-shortcuts/spotify_shortcuts/spotify_like.py
Normal file
@@ -0,0 +1,46 @@
|
||||
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():
|
||||
run_shortcut(SpotifyLike(), load_config())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,57 @@
|
||||
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",
|
||||
]
|
||||
|
||||
|
||||
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():
|
||||
run_shortcut(SpotifyPlAdd(), load_config())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user