diff options
-rw-r--r-- | configs/configs_root_dir/etc/systemd/system/dyafk@.service | 14 | ||||
-rwxr-xr-x | sh/dyafk | 27 |
2 files changed, 41 insertions, 0 deletions
diff --git a/configs/configs_root_dir/etc/systemd/system/dyafk@.service b/configs/configs_root_dir/etc/systemd/system/dyafk@.service new file mode 100644 index 0000000..e584070 --- /dev/null +++ b/configs/configs_root_dir/etc/systemd/system/dyafk@.service @@ -0,0 +1,14 @@ +[Unit] +Description=Douyu AFK for user %I +After=network.target + +[Service] +User=%i + +Type=simple +ExecStart=/usr/bin/dyafk + +Restart=always + +[Install] +WantedBy=multi-user.target diff --git a/sh/dyafk b/sh/dyafk new file mode 100755 index 0000000..caf1c66 --- /dev/null +++ b/sh/dyafk @@ -0,0 +1,27 @@ +#!/bin/sh +# DouYu AFK + +# maybe another way: https://open.douyu.com/source + +pid= +while :; do + # credit: MIT licensed https://github.com/DIYgod/RSSHub/blob/master/lib/routes/douyu/room.ts + if [ "$(curl -s https://www.douyu.com/betard/9640128 | jq '.room.show_status')" -eq 1 ]; then + if ! pidof -q firefox; then + firefox --headless --profile "$HOME/.mozilla/firefox/dyafk" https://www.douyu.com/9640128 & + # assign previous background process to pid variable + pid=$! + fi + else + if [ "$pid" ]; then + # seems need to only SIGTERM kill the parent firefox process, else firefox will prompt me firefox closed unexpectedly warning which cause firefox not actually open the url + # https://www.reddit.com/r/firefox/comments/fq1mhi/kill_firefox_gracefully_via_terminal_headless/ + # firefox seems now can handle SIGTERM on linux? https://bugzilla.mozilla.org/show_bug.cgi?id=1837907 + kill "$pid" + pid= + fi + fi + # open.douyu.com AUP for api request seems very high, about 6k/min per api? see https://open.douyu.com/source/api/5 + # although I don't use open.douyu.com api but can be used as a reference, so I think 1 request per minute is ok + sleep 60 +done |