diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2018-04-06 19:54:03 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2018-04-06 19:54:03 +0200 |
commit | e52e5ea5494319f158e9d9c1425b16b9986e929a (patch) | |
tree | 7330667fc281e6de00b968bd31ff7ca5e5234f41 /odin | |
parent | a29c95fe7335167cc3012dedfef2c4afbe1392c7 (diff) | |
download | nixos-e52e5ea5494319f158e9d9c1425b16b9986e929a.tar nixos-e52e5ea5494319f158e9d9c1425b16b9986e929a.tar.gz nixos-e52e5ea5494319f158e9d9c1425b16b9986e929a.tar.bz2 nixos-e52e5ea5494319f158e9d9c1425b16b9986e929a.tar.xz nixos-e52e5ea5494319f158e9d9c1425b16b9986e929a.zip |
rss_staggered
Diffstat (limited to 'odin')
-rw-r--r-- | odin/strm.nix | 8 | ||||
-rwxr-xr-x | odin/strm/rss_staggered | 32 |
2 files changed, 37 insertions, 3 deletions
diff --git a/odin/strm.nix b/odin/strm.nix index 8c88514e..71d93011 100644 --- a/odin/strm.nix +++ b/odin/strm.nix | |||
@@ -1,4 +1,4 @@ | |||
1 | { stdenv, zsh, ffmpeg-full, youtube-dl, pv, notmuch }: | 1 | { stdenv, zsh, ffmpeg-full, youtube-dl, pv, notmuch, rss2email }: |
2 | 2 | ||
3 | stdenv.mkDerivation { | 3 | stdenv.mkDerivation { |
4 | name = "strm"; | 4 | name = "strm"; |
@@ -6,7 +6,7 @@ stdenv.mkDerivation { | |||
6 | 6 | ||
7 | phases = [ "unpackPhase" "buildPhase" "installPhase" ]; | 7 | phases = [ "unpackPhase" "buildPhase" "installPhase" ]; |
8 | 8 | ||
9 | inherit zsh pv notmuch; | 9 | inherit zsh pv notmuch rss2email; |
10 | ffmpeg = ffmpeg-full; | 10 | ffmpeg = ffmpeg-full; |
11 | youtubedl = youtube-dl; | 11 | youtubedl = youtube-dl; |
12 | 12 | ||
@@ -16,6 +16,7 @@ stdenv.mkDerivation { | |||
16 | substituteAllInPlace send_media | 16 | substituteAllInPlace send_media |
17 | substituteAllInPlace cache_media | 17 | substituteAllInPlace cache_media |
18 | substituteAllInPlace send_kitty | 18 | substituteAllInPlace send_kitty |
19 | substituteAllInPlace rss_staggered | ||
19 | ''; | 20 | ''; |
20 | 21 | ||
21 | installPhase = '' | 22 | installPhase = '' |
@@ -26,6 +27,7 @@ stdenv.mkDerivation { | |||
26 | cleanup_youtube \ | 27 | cleanup_youtube \ |
27 | send_media \ | 28 | send_media \ |
28 | cache_media \ | 29 | cache_media \ |
29 | send_kitty | 30 | send_kitty \ |
31 | rss_staggered | ||
30 | ''; | 32 | ''; |
31 | } | 33 | } |
diff --git a/odin/strm/rss_staggered b/odin/strm/rss_staggered new file mode 100755 index 00000000..54bbd1a3 --- /dev/null +++ b/odin/strm/rss_staggered | |||
@@ -0,0 +1,32 @@ | |||
1 | #!@zsh@/bin/zsh | ||
2 | |||
3 | delta_t=20 | ||
4 | interval=3600 | ||
5 | |||
6 | staggerFile=~/.rss-stagger | ||
7 | |||
8 | [[ "${FLOCKER}" != "$0" ]] && exec env FLOCKER="$0" flock -x "${staggerFile}" "$0" "$@" || : | ||
9 | |||
10 | feeds=$(@rss2email@/bin/r2e list | awk -F ':' 'END { print $1; }') | ||
11 | max=$(($feeds + 1)) | ||
12 | num=$(((max * delta_t) / interval)) | ||
13 | [[ $num -lt 1 ]] && num=1 | ||
14 | |||
15 | now=$(cat ${staggerFile} || echo 0) | ||
16 | now=$((now % max)) | ||
17 | |||
18 | typeset -a run | ||
19 | run=() | ||
20 | typeset -a names | ||
21 | names=() | ||
22 | |||
23 | n=0 | ||
24 | |||
25 | for i in $(seq $((now + 1)) $((now + num + 1))); do | ||
26 | n=$((i % max)) | ||
27 | run+=$n | ||
28 | done | ||
29 | |||
30 | echo $n >! ${staggerFile} | ||
31 | |||
32 | exec @rss2email@/bin/r2e run $run | ||