smaller improvments to threadwatcher
This commit is contained in:
parent
cae8647bcc
commit
7d45fd7875
@ -10,9 +10,10 @@ TMP_URLFILE=/tmp/4chan_thread_watcher_tmp$$
|
|||||||
[ -d "$THREADWATCHER_DIR" ] || mkdir -p "$THREADWATCHER_DIR"
|
[ -d "$THREADWATCHER_DIR" ] || mkdir -p "$THREADWATCHER_DIR"
|
||||||
[ -f "$URLFILE" ] || touch "$URLFILE"
|
[ -f "$URLFILE" ] || touch "$URLFILE"
|
||||||
|
|
||||||
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 ;}
|
|
||||||
|
|
||||||
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 ;}
|
||||||
|
|
||||||
if [ $(wc -l "$URLFILE"| cut -d ' ' -f1) -gt 0 ]; then
|
if [ $(wc -l "$URLFILE"| cut -d ' ' -f1) -gt 0 ]; then
|
||||||
echo "scanning threads..."
|
echo "scanning threads..."
|
||||||
else
|
else
|
||||||
@ -36,10 +37,11 @@ scan(){
|
|||||||
mkdir -p "$dl_location"
|
mkdir -p "$dl_location"
|
||||||
fi
|
fi
|
||||||
files_json="$(jq '.posts[] | if has("filename") then {filename: "\(.no)_\(.filename)\(.ext)", location: "\(.tim)\(.ext)", md5: .md5} else null end ' < /tmp/content$$ | grep -vE '^null$')"
|
files_json="$(jq '.posts[] | if has("filename") then {filename: "\(.no)_\(.filename)\(.ext)", location: "\(.tim)\(.ext)", md5: .md5} else null end ' < /tmp/content$$ | grep -vE '^null$')"
|
||||||
|
rm /tmp/content$$
|
||||||
#pastes together a multiline var using process substitution with layout: filename location md5
|
#pastes together a multiline var using process substitution with layout: filename location md5
|
||||||
files="$(paste <(paste <(echo "$files_json" | jq '.filename' | tr -d '"') <(echo "$files_json" | jq '.location' | tr -d '"')) <(echo "$files_json" | jq '.md5' | tr -d '"'))"
|
files="$(paste <(paste <(echo "$files_json" | jq '.filename' | tr -d '"') <(echo "$files_json" | jq '.location' | tr -d '"')) <(echo "$files_json" | jq '.md5' | tr -d '"'))"
|
||||||
echo "$files" | while read -r file_line; do
|
echo "$files" | while read -r file_line; do
|
||||||
filename="$(echo "$file_line" | cut -f1)"
|
filename="$(echo "$file_line" | cut -f1 | tr ' ' '_')"
|
||||||
master_location="$(echo "$file_line" | cut -f2 | tr -d '"')"
|
master_location="$(echo "$file_line" | cut -f2 | tr -d '"')"
|
||||||
filelocation="$dl_location/$filename"
|
filelocation="$dl_location/$filename"
|
||||||
correct_md5="$(echo "$file_line" | cut -f3)"
|
correct_md5="$(echo "$file_line" | cut -f3)"
|
||||||
@ -69,29 +71,32 @@ scan(){
|
|||||||
done<"$URLFILE"
|
done<"$URLFILE"
|
||||||
mv "$TMP_URLFILE" "$URLFILE"
|
mv "$TMP_URLFILE" "$URLFILE"
|
||||||
}
|
}
|
||||||
case "$1" in
|
|
||||||
"add") if echo "$3" | grep -qE '^/'; then
|
makepathabsolute(){
|
||||||
dl_location="$3"
|
if echo "$1" | grep -qE '^/'; then
|
||||||
|
dl_location="$1"
|
||||||
else
|
else
|
||||||
dl_location="$HOME/$3"
|
dl_location="$HOME/$1"
|
||||||
fi
|
fi
|
||||||
|
echo "$dl_location"
|
||||||
|
}
|
||||||
|
case "$1" in
|
||||||
|
"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 $dl_location_already"
|
||||||
choice="$(dmenuinput "If you want to change location of thread to download, please insert new directory now:")"
|
choice="$(dmenuinput "If you want to change location of thread to download, please insert new directory now:")"
|
||||||
if echo "$choice" | grep -qE '^/'; then
|
new_location="$(makepathabsolute "$choice")"
|
||||||
new_location="$3"
|
|
||||||
else
|
|
||||||
new_location="$HOME/$3"
|
|
||||||
fi
|
|
||||||
[ -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"
|
||||||
|
#find "$dl_location_already/" -type f -exec mv {} "$new_location" \;
|
||||||
mv $dl_location_already/* "$new_location"
|
mv $dl_location_already/* "$new_location"
|
||||||
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"
|
||||||
fi
|
fi
|
||||||
|
echo "dl_location:$dl_location"
|
||||||
scan;;
|
scan;;
|
||||||
"scan") scan;;
|
"scan") scan;;
|
||||||
"list") printf "Thread:\t\t\t\t\t\tDownload location:\n"
|
"list") printf "Thread:\t\t\t\t\t\tDownload location:\n"
|
||||||
|
Loading…
Reference in New Issue
Block a user