diff --git a/.local/bin/threadwatcher b/.local/bin/threadwatcher index 00f4957..ce90077 100755 --- a/.local/bin/threadwatcher +++ b/.local/bin/threadwatcher @@ -16,6 +16,9 @@ DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus export DBUS_SESSION_BUS_ADDRESS export DISPLAY=:0.0 +getfilelist(){ + true +} scan(){ ping -q -c 1 1.1.1.1 > /dev/null || ping -q -c 1 1.0.0.1 > /dev/null || ping -q -c 1 example.org || { echo "No internet connection detected."; exit ;} if [ $(wc -l < "$URLFILE") -gt 0 ]; then @@ -35,7 +38,7 @@ scan(){ curl -s -L "$json_url" | jq . > /tmp/content$$ if [ -z "$(> "$TMP_URLFILE" @@ -89,13 +92,28 @@ case "$1" in "add") dl_location="$(makepathabsolute "$3")" if grep -qP "^$2\t" "$URLFILE"; then dl_location_already="$(grep -P "^$2\t" "$URLFILE" | cut -f2)" - notify-send "threadwatcher" "Thread already being watched. currently downloads to $dl_location_already" - choice="$(dmenuinput "If you want to change location of thread to download, please insert new directory now:")" - new_location="$(makepathabsolute "$choice")" + notify-send "threadwatcher" "Thread already being watched. currently downloads to $(echo "$dl_location_already" | sed "s|$HOME|~|")" + prompt "Do you want to change download directory to $3?" && + new_location="$dl_location" || + exit 0 [ -z "$new_location" ] && exit sed -i "s|$dl_location_already|$new_location|" "$URLFILE" - mv "$dl_location_already"/* "$new_location" + + ## Move already downloaded files to new location + mkdir -p "$new_location" + url="$2" + json_url="$(echo "$url" | sed -E 's/boards\.(4chan|4channel)/a.4cdn/; s/$/.json/')" + curl -s -L "$json_url" | jq . > /tmp/content$$ + files_json="$(jq '.posts[] | if has("filename") then {filename: "\(.no)_\(.filename)\(.ext)", location: "\(.tim)\(.ext)"} else null end ' < /tmp/content$$ | grep -vE '^null$')" + rm /tmp/content$$ + files="$(paste <(echo "$files_json" | jq '.filename' | tr -d '"') <(echo "$files_json" | jq '.location' | tr -d '"'))" + echo "$files" | while read -r file_line; do + filename="$(echo "$file_line" | cut -f1 | tr ' ' '_')" + mv -v "$dl_location_already/$filename" "$new_location" + done + rmdir --ignore-fail-on-non-empty "$dl_location_already" notify-send "threadwatcher" "already downloaded files moved to $new_location. New files will also be downloaded there" + else printf "%s\t%s\n" "$2" "$dl_location" | tee -ai "$URLFILE" echo "added $2 to threadwatcher list. Downloading to $dl_location"