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.nix23
1 files changed, 13 insertions, 10 deletions
diff --git a/hel/recv-media.nix b/hel/recv-media.nix
index 582a1ee3..91801593 100644
--- a/hel/recv-media.nix
+++ b/hel/recv-media.nix
@@ -27,11 +27,11 @@ writeScriptBin "recv-media" ''
27 27
28 dir=/var/media 28 dir=/var/media
29 group=$(stat -c '%G' $dir) 29 group=$(stat -c '%G' $dir)
30 tmpFile="''${dir}"/.tmp/$(basename "$1") 30 tmpFile="''${dir}/.tmp/''${1:t}"
31 target="''${dir}"/$(basename "$1") 31 target="''${dir}/''${1:t}"
32 32
33 if [[ -n "''${3}" ]]; then 33 if [[ -n "''${3}" ]]; then
34 target="''${dir}"/$(echo ''${3} | base64 -d) 34 target="''${dir}"/$(base64 -d <<<''${3})
35 fi 35 fi
36 36
37 logger --id=$pid -t recv-media -p user.debug <<EOF 37 logger --id=$pid -t recv-media -p user.debug <<EOF
@@ -46,19 +46,22 @@ writeScriptBin "recv-media" ''
46 exec -- sg $group "$0 $*" 46 exec -- sg $group "$0 $*"
47 fi 47 fi
48 48
49 typeset -a failures
50 failures=()
51
49 ( 52 (
50 if ! cp -lnv --preserve=all "$1" "''${target}"; then 53 if ! cp -lnv --preserve=all "$1" "''${target}"; then
51 mkdir -pv $(dirname "''${tmpFile}") || exit 1 54 mkdir -pv "''${tmpFile:h}" || failures+="mkdir"
52 55
53 ionice -c 3 -t cp -vn --preserve=all "$1" "''${tmpFile}" && mv -v "''${tmpFile}" "''${target}" || exit 1 56 ionice -c 3 -t cp -vn --preserve=all "$1" "''${tmpFile}" && mv -v "''${tmpFile}" "''${target}" || failures+="cp"
54 fi
55 touch -c -m -t "$2" "''${target}" || exit 1
56 ) || (
57 if $notify; then
58 printf "%s\n%s\n" $(basename "$1") "Failed to download" | notify-''${notifyUser} -a recv-media -u Critical
59 fi 57 fi
58 touch -c -m -t "$2" "''${target}" || failures+="touch"
60 ) 59 )
61 60
61 if $notify && [[ $#failures -gt 0 ]]; then
62 printf "%s\n%s\n%s" $(basename "$1") "Failed to download" ''${(j:, :)failures} | notify-''${notifyUser} -a recv-media -u Critical
63 fi
64
62 if $notify; then 65 if $notify; then
63 ( 66 (
64 summary=${if showTitle then ''$(ffmpeg -i "''${target}" -f ffmetadata pipe:1 2>/dev/null | sed -r '/^\[CHAPTER\]$/q; /^title=/!d; s/^title=//')'' else ''""''} 67 summary=${if showTitle then ''$(ffmpeg -i "''${target}" -f ffmetadata pipe:1 2>/dev/null | sed -r '/^\[CHAPTER\]$/q; /^title=/!d; s/^title=//')'' else ''""''}