From 9ac06330a70d67f580b15557e9e4fa6a397a2252 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Thu, 6 Apr 2017 17:42:04 +0200 Subject: More recv-media --- hel/recv-media.nix | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'hel') diff --git a/hel/recv-media.nix b/hel/recv-media.nix index 7afd981d..fd638ccc 100644 --- a/hel/recv-media.nix +++ b/hel/recv-media.nix @@ -15,6 +15,8 @@ writeScriptBin "recv-media" '' #!${stdenv.shell} pid=$? + notify=${if notifyUser == null then "false" else "true"} + notifyUser=${if notifyUser == null then "" else notifyUser} PATH=${eject}/bin:${coreutils}/bin:${if showTitle then ''${ffmpeg}/bin:${gnused}/bin:'' else ""}${wrapperDir} @@ -29,23 +31,29 @@ writeScriptBin "recv-media" '' logger --id=$pid -t recv-media -p user.debug </dev/null | sed -r '/^\[CHAPTER\]$/q; /^title=/!d; s/^title=//')'' else ''""''} - [[ -z "''${summary}" ]] && summary=$(basename "$1") - printf "%s\n%s\n" "''${summary}" "" | notify-${notifyUser} -a recv-media || true - ) || true + if ! cp -lnv --preserve=all "$1" "''${target}"; then + mkdir -pv $(dirname "''${tmpFile}") || exit 1 + + ionice -c 3 -t cp -vn --preserve=all "$1" "''${tmpFile}" && mv -v "''${tmpFile}" "''${target}" || exit 1 + fi + touch -c -m -t "$2" "''${target}" || exit 1 + ) || ( + if notify; then + printf "%s\n%s\n" $(basename "$1") "Failed to download" | notify-''${notifyUser} -a recv-media -u Critical + fi + ) + + if notify; then + ( + summary=${if showTitle then ''$(ffmpeg -i "''${target}" -f ffmetadata pipe:1 2>/dev/null | sed -r '/^\[CHAPTER\]$/q; /^title=/!d; s/^title=//')'' else ''""''} + [[ -z "''${summary}" ]] && summary=$(basename "$1") + printf "%s\n%s\n" "''${summary}" "" | notify-''${notifyUser} -a recv-media || true + ) || true + fi '' -- cgit v1.2.3