threadwatcher only moves appropriate files now
This commit is contained in:
parent
16c4ba37b6
commit
d23a7cbd55
@ -16,6 +16,9 @@ DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus
|
|||||||
export DBUS_SESSION_BUS_ADDRESS
|
export DBUS_SESSION_BUS_ADDRESS
|
||||||
export DISPLAY=:0.0
|
export DISPLAY=:0.0
|
||||||
|
|
||||||
|
getfilelist(){
|
||||||
|
true
|
||||||
|
}
|
||||||
scan(){
|
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 ;}
|
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
|
if [ $(wc -l < "$URLFILE") -gt 0 ]; then
|
||||||
@ -35,7 +38,7 @@ scan(){
|
|||||||
curl -s -L "$json_url" | jq . > /tmp/content$$
|
curl -s -L "$json_url" | jq . > /tmp/content$$
|
||||||
if [ -z "$(</tmp/content$$)" ]; then
|
if [ -z "$(</tmp/content$$)" ]; then
|
||||||
echo "Thread $url not found ($dl_location) deleting from cached list of threads to watch"
|
echo "Thread $url not found ($dl_location) deleting from cached list of threads to watch"
|
||||||
notify-send "threadwatcher" "Thread downloading ${$dl_location//\/home\/alex/~} is complete now."
|
notify-send "threadwatcher" "Thread downloading $(echo "$dl_location" | sed "s|$HOME|~|") is complete now."
|
||||||
continue
|
continue
|
||||||
else
|
else
|
||||||
echo "$line" >> "$TMP_URLFILE"
|
echo "$line" >> "$TMP_URLFILE"
|
||||||
@ -89,13 +92,28 @@ case "$1" in
|
|||||||
"add") dl_location="$(makepathabsolute "$3")"
|
"add") dl_location="$(makepathabsolute "$3")"
|
||||||
if grep -qP "^$2\t" "$URLFILE"; then
|
if grep -qP "^$2\t" "$URLFILE"; then
|
||||||
dl_location_already="$(grep -P "^$2\t" "$URLFILE" | cut -f2)"
|
dl_location_already="$(grep -P "^$2\t" "$URLFILE" | cut -f2)"
|
||||||
notify-send "threadwatcher" "Thread already being watched. currently downloads to $dl_location_already"
|
notify-send "threadwatcher" "Thread already being watched. currently downloads to $(echo "$dl_location_already" | sed "s|$HOME|~|")"
|
||||||
choice="$(dmenuinput "If you want to change location of thread to download, please insert new directory now:")"
|
prompt "Do you want to change download directory to $3?" &&
|
||||||
new_location="$(makepathabsolute "$choice")"
|
new_location="$dl_location" ||
|
||||||
|
exit 0
|
||||||
[ -z "$new_location" ] && exit
|
[ -z "$new_location" ] && exit
|
||||||
sed -i "s|$dl_location_already|$new_location|" "$URLFILE"
|
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"
|
notify-send "threadwatcher" "already downloaded files moved to $new_location. New files will also be downloaded there"
|
||||||
|
|
||||||
else
|
else
|
||||||
printf "%s\t%s\n" "$2" "$dl_location" | tee -ai "$URLFILE"
|
printf "%s\t%s\n" "$2" "$dl_location" | tee -ai "$URLFILE"
|
||||||
echo "added $2 to threadwatcher list. Downloading to $dl_location"
|
echo "added $2 to threadwatcher list. Downloading to $dl_location"
|
||||||
|
Loading…
Reference in New Issue
Block a user