Fixing scanning.

This commit is contained in:
Dessalines 2018-11-26 10:08:18 -07:00
parent ad17496f28
commit 8a2d934048
1 changed files with 52 additions and 41 deletions

View File

@ -4,6 +4,7 @@
# Help line # Help line
cd .. cd ..
torrents_csv="`pwd`/torrents.csv" torrents_csv="`pwd`/torrents.csv"
scanned_out="`pwd`/infohashes_scanned.txt"
help="Run ./scan_torrents.sh [TORRENTS_DIR] \nor goto https://gitlab.com/dessalines/torrents.csv for more help" help="Run ./scan_torrents.sh [TORRENTS_DIR] \nor goto https://gitlab.com/dessalines/torrents.csv for more help"
if [ "$1" == "-h" ] || [ -z "$1" ]; then if [ "$1" == "-h" ] || [ -z "$1" ]; then
@ -27,10 +28,16 @@ fi
pushd $torrents_dir pushd $torrents_dir
for torrent_file in *.torrent; do for torrent_file in *.torrent; do
file_infohash=$(basename $torrent_file | cut -d'.' -f 1)
if rg -Nq $file_infohash $scanned_out; then
echo "$file_infohash already scanned"
else
# Scrape it # Scrape it
health_text=$(torrent-tracker-health --torrent $torrent_file --timeout 1000 --addTrackers={udp://tracker.coppersurfer.tk:6969/announce,udp://tracker.internetwarriors.net:1337/announce,udp://tracker.opentrackr.org:1337/announce,udp://exodus.desync.com:6969/announce,udp://explodie.org:6969/announce}) health_text=$(torrent-tracker-health --torrent $torrent_file --timeout 1000 --addTrackers={udp://tracker.coppersurfer.tk:6969/announce,udp://tracker.internetwarriors.net:1337/announce,udp://tracker.opentrackr.org:1337/announce,udp://exodus.desync.com:6969/announce,udp://explodie.org:6969/announce})
# echo $health_text echo -e "$health_text"
infohash=$(jq -r '.hash' <<< $health_text) infohash=$(jq -r '.hash' <<< $health_text)
name=$(jq -r '.name' <<< $health_text) name=$(jq -r '.name' <<< $health_text)
@ -58,7 +65,7 @@ for torrent_file in *.torrent; do
if [ "$found_seeders" != "$seeders" ]; then if [ "$found_seeders" != "$seeders" ]; then
# Delete the original infohash line # Delete the original infohash line
grep -v "$infohash" $torrents_csv > torfile.tmp.2; mv torfile.tmp.2 $torrents_csv rg -N -v "$infohash" $torrents_csv > torfile.tmp.2; mv torfile.tmp.2 $torrents_csv
# Append the add lines to the torrents.csv file # Append the add lines to the torrents.csv file
echo -e "\n$add_line" >> $torrents_csv echo -e "\n$add_line" >> $torrents_csv
@ -74,15 +81,19 @@ for torrent_file in *.torrent; do
echo -e "New Torrent: $torrent_file | $name | $infohash | $seeders" echo -e "New Torrent: $torrent_file | $name | $infohash | $seeders"
fi fi
else else
# Deleting the line if it existed # Deleting the line if it existed
if [ ! -z "$infohash" ]; then if [ ! -z "$infohash" ]; then
# This removes lines that have no seeders
echo -e "$name has no seeders, removing if existed." echo -e "$name has no seeders, removing if existed."
grep -v "$infohash" $torrents_csv > torfile.tmp.2; mv torfile.tmp.2 $torrents_csv grep -v "$infohash" $torrents_csv > torfile.tmp.2; mv torfile.tmp.2 $torrents_csv
fi fi
fi fi
echo $infohash >> $scanned_out
fi
done done
popd popd