summaryrefslogtreecommitdiff
path: root/hel/recv-media.nix
diff options
context:
space:
mode:
Diffstat (limited to 'hel/recv-media.nix')
-rw-r--r--hel/recv-media.nix40
1 files changed, 24 insertions, 16 deletions
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" ''
15 #!${stdenv.shell} 15 #!${stdenv.shell}
16 16
17 pid=$? 17 pid=$?
18 notify=${if notifyUser == null then "false" else "true"}
19 notifyUser=${if notifyUser == null then "" else notifyUser}
18 20
19 PATH=${eject}/bin:${coreutils}/bin:${if showTitle then ''${ffmpeg}/bin:${gnused}/bin:'' else ""}${wrapperDir} 21 PATH=${eject}/bin:${coreutils}/bin:${if showTitle then ''${ffmpeg}/bin:${gnused}/bin:'' else ""}${wrapperDir}
20 22
@@ -29,23 +31,29 @@ writeScriptBin "recv-media" ''
29 31
30 logger --id=$pid -t recv-media -p user.debug <<EOF 32 logger --id=$pid -t recv-media -p user.debug <<EOF
31$(id) 33$(id)
32$(stat ${dir}) 34$(stat ''${dir})
33$(stat ${1}) 35$(stat ''${1})
34$(print ${2}) 36$(print ''${2})
35EOF 37EOF
36 38
37 if ! cp -lnv --preserve=all "$1" "''${target}"; then
38 mkdir -pv $(dirname "''${tmpFile}")
39
40 ionice -c 3 -t cp -vn --preserve=all "$1" "''${tmpFile}" && mv -v "''${tmpFile}" "''${target}"
41 fi
42 touch -c -m -t "$2" "''${target}"
43
44 ${if notifyUser == null then "" else "#"}exit 0
45
46 ( 39 (
47 summary=${if showTitle then ''$(ffmpeg -i "''${target}" -f ffmetadata pipe:1 2>/dev/null | sed -r '/^\[CHAPTER\]$/q; /^title=/!d; s/^title=//')'' else ''""''} 40 if ! cp -lnv --preserve=all "$1" "''${target}"; then
48 [[ -z "''${summary}" ]] && summary=$(basename "$1") 41 mkdir -pv $(dirname "''${tmpFile}") || exit 1
49 printf "%s\n%s\n" "''${summary}" "" | notify-${notifyUser} -a recv-media || true 42
50 ) || true 43 ionice -c 3 -t cp -vn --preserve=all "$1" "''${tmpFile}" && mv -v "''${tmpFile}" "''${target}" || exit 1
44 fi
45 touch -c -m -t "$2" "''${target}" || exit 1
46 ) || (
47 if notify; then
48 printf "%s\n%s\n" $(basename "$1") "Failed to download" | notify-''${notifyUser} -a recv-media -u Critical
49 fi
50 )
51
52 if notify; then
53 (
54 summary=${if showTitle then ''$(ffmpeg -i "''${target}" -f ffmetadata pipe:1 2>/dev/null | sed -r '/^\[CHAPTER\]$/q; /^title=/!d; s/^title=//')'' else ''""''}
55 [[ -z "''${summary}" ]] && summary=$(basename "$1")
56 printf "%s\n%s\n" "''${summary}" "" | notify-''${notifyUser} -a recv-media || true
57 ) || true
58 fi
51'' 59''