diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2017-04-06 17:42:04 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2017-04-06 17:42:04 +0200 |
commit | 9ac06330a70d67f580b15557e9e4fa6a397a2252 (patch) | |
tree | c1480a1bbf691d333b7fda489a2971bd72be2aa0 | |
parent | 863aa163b5486afd69d78badb0ba2876f894b020 (diff) | |
download | nixos-9ac06330a70d67f580b15557e9e4fa6a397a2252.tar nixos-9ac06330a70d67f580b15557e9e4fa6a397a2252.tar.gz nixos-9ac06330a70d67f580b15557e9e4fa6a397a2252.tar.bz2 nixos-9ac06330a70d67f580b15557e9e4fa6a397a2252.tar.xz nixos-9ac06330a70d67f580b15557e9e4fa6a397a2252.zip |
More recv-media
-rw-r--r-- | hel/recv-media.nix | 40 |
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}) |
35 | EOF | 37 | EOF |
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 | '' |