diff --git a/scripts/prune.sh b/scripts/prune.sh index e3df338..aed1c02 100755 --- a/scripts/prune.sh +++ b/scripts/prune.sh @@ -1,4 +1,5 @@ # This prunes torrents.csv, removing those with too many columns, and sorts it +echo "Pruning torrents.csv ..." cd .. torrents_csv="`pwd`/torrents.csv" @@ -24,4 +25,6 @@ sort --field-separator=';' --key=5 -nr -o $torrents_csv $torrents_csv sed -i "1i $header" $torrents_csv #truncate -s -1 $torrents_csv # Removing last newline +echo "Pruning done." + diff --git a/scripts/scan_torrents.sh b/scripts/scan_torrents.sh index 1dbff00..3e04a83 100755 --- a/scripts/scan_torrents.sh +++ b/scripts/scan_torrents.sh @@ -51,24 +51,36 @@ for torrent_file in *.torrent; do found_line=$(rg -n $infohash $torrents_csv) found_seeders=$(echo -e $found_line | cut -d';' -f 5) - # Only re-add if the infohash doesn't exist, and the seeder counts are different - if [ ! -z "$found_line" ] && [ "$found_seeders" != "$seeders" ]; then + # Only re-add if the infohash doesn't exist, or + if [ ! -z "$found_line" ]; then - # Delete the original infohash line - grep -v "$infohash" $torrents_csv > torfile.tmp.2; mv torfile.tmp.2 $torrents_csv - + # Seeder counts are different + if [ "$found_seeders" != "$seeders" ]; then + + # Delete the original infohash line + grep -v "$infohash" $torrents_csv > torfile.tmp.2; mv torfile.tmp.2 $torrents_csv + + # Append the add lines to the torrents.csv file + echo -e "\n$add_line" >> $torrents_csv + # truncate -s -1 $torrents_csv # Removing last newline + echo -e "Updating Seeders: $torrent_file | $name | $infohash | $seeders" + else + echo -e "Not adding $name, had identical seeders" + fi + else # Append the add lines to the torrents.csv file echo -e "\n$add_line" >> $torrents_csv # truncate -s -1 $torrents_csv # Removing last newline - echo -e "Added $torrent_file | $name | $infohash | $seeders" - else - echo -e "Not adding $name, had identical seeders" + echo -e "New Torrent: $torrent_file | $name | $infohash | $seeders" fi + else - echo -e "$name has no seeders, removing if existed." # Deleting the line if it existed - grep -v "$infohash" $torrents_csv > torfile.tmp.2; mv torfile.tmp.2 $torrents_csv + if [ ! -z "$infohash" ]; then + echo -e "$name has no seeders, removing if existed." + grep -v "$infohash" $torrents_csv > torfile.tmp.2; mv torfile.tmp.2 $torrents_csv + fi fi done