nix/host/home/YaMusicDownload.nix

50 lines
1.5 KiB
Nix
Raw Normal View History

{ pkgs, util, lib, __findFile, ... }: let
2024-06-27 02:14:33 +03:00
storage = "/storage/hot/media/music";
package = import <package/yamusicdownload> { inherit pkgs; };
2024-06-27 02:14:33 +03:00
pattern = "#album-artist/#year_#album/#number_#title";
in {
systemd.user = {
services.yamusicdownload = let
script = pkgs.writeText "YaMusicDownloadScript" (util.trimTabs ''
[[ $UID = 0 ]] && exit 0
function notify_silent() {
curl -X POST -H 'Content-Type: Application/json' -d "{\"chat_id\":\"155897358\",\"text\":\"$1\",\"disable_notification\":\"true\"}" https://api.telegram.org/bot2046849441:AAHQpjRK4xpL8tEUyN4JTSDUUze4J0wSIy4/sendMessage &> /dev/null
}
cd ${storage}
output=$(${package}/bin/yandex-music-downloader --browser "firefox" --hq --add-lyrics --embed-cover --skip-existing --stick-to-artist --only-music --path-pattern "${pattern}" --url https://music.yandex.ru/users/cakee.ru/playlists/3)
2024-06-28 01:44:33 +03:00
if [[ $? = 0 ]]; then
notify_silent "Music download complete: ''${output}"
else
notify_silent "Music download failed. Capcha?"
fi
2024-06-27 02:14:33 +03:00
'');
in util.mkStaticSystemdService {
enable = true;
description = "Yandex Music Download.";
serviceConfig = {
Type = "oneshot";
ExecStart = "-${lib.getExe pkgs.bashInteractive} ${script}";
Restart = "on-failure";
};
path = with pkgs; [
2024-06-28 13:22:46 +03:00
curl
2024-06-27 02:14:33 +03:00
firefox-esr
2024-06-28 13:22:46 +03:00
python313
2024-06-27 02:14:33 +03:00
];
};
timers.yamusicdownload = {
timerConfig = {
OnCalendar = "daily";
Persistent = true;
Unit = "yamusicdownload.service";
};
wantedBy = [ "default.target" ];
2024-06-27 02:14:33 +03:00
};
};
}