tank-sort.nix (1515B)
1 { pkgs, username, ... }: 2 3 let 4 tank-sort = pkgs.writeShellScriptBin "tank-sort" '' 5 # variables 6 temp_mount="$(mktemp -d)" 7 rclone_config="$HOME/vault/src/dockerfiles/rclone.conf" 8 rclone_remote="seedbox:" 9 destination_tvshows="/mnt/media/videos/television" 10 template_tvshows="{{ .Name }}/{{ .Name }} S{{ printf \"%02d\" .Season }}E{{ printf \"%02d\" .Episode }}{{ if ne .ExtraEpisode -1 }}-{{ printf \"%02d\" .ExtraEpisode }}{{end}}.{{ .Ext }}" 11 destination_movies="/mnt/media/videos/movies" 12 template_movies="{{ .Name }} ({{ .Year }})/{{ .Name }}.{{ .Ext }}" 13 # mount remote 14 ${pkgs.rclone}/bin/rclone --config="$rclone_config" mount "$rclone_remote" "$temp_mount" --daemon 15 # sorting process 16 media-sort --action copy --concurrency 1 --accuracy-threshold 90 --tv-dir "$destination_tvshows" --movie-dir "$destination_movies" --tv-template "$template_tvshows" --movie-template "$template_movies" --recursive --overwrite-if-larger --extensions "mp4,m4v,mkv" "$temp_mount" 17 # unmount remote and remove 18 fusermount -uz "$temp_mount" 2>/dev/null 19 find "$temp_mount" -maxdepth 1 -mount -type d -empty -delete -print 20 ''; 21 in { 22 environment.systemPackages = [tank-sort]; 23 24 systemd.timers.tank-sort = { 25 wantedBy = [ "timers.target" ]; 26 timerConfig = { 27 OnCalendar = "0/12:00:00"; 28 Persistent = true; 29 }; 30 }; 31 32 systemd.services.tank-sort = { 33 script = "tank-sort"; 34 path = [ "/run/current-system/sw" ]; 35 serviceConfig = { 36 Type = "oneshot"; 37 User = "${username}"; 38 }; 39 }; 40 }