torrents.csv/scripts/scan_torrents.sh

67 lines
1.7 KiB
Bash
Raw Normal View History

#!/bin/bash
# Checking arguments
# Help line
cd ..
torrents_csv="`pwd`/torrents.csv"
2018-11-26 17:08:18 +00:00
scanned_out="`pwd`/infohashes_scanned.txt"
tmp_torrent_dir="`pwd`/tmp_torrents"
names_out="`pwd`/names.out"
health_out="`pwd`/health.out"
2018-12-21 21:31:21 +00:00
touch $scanned_out
touch $names_out
touch $health_out
2018-12-21 21:31:21 +00:00
help="Run ./scan_torrents.sh [TORRENTS_DIR] \nor goto https://gitlab.com/dessalines/torrents.csv for more help"
if [ "$1" == "-h" ] || [ -z "$1" ]; then
echo -e $help
exit 1
fi
torrents_dir="$1"
echo "Torrents dir=$torrents_dir"
# Check dependencies
if command -v "torrent-tracker-health" >/dev/null 2>&1 ; then
echo "torrent-tracker-health installed."
else
echo -e "Installing torrent-tracker-health:\nnpm i -g dessalines/torrent-tracker-health \nhttps://github.com/dessalines/torrent-tracker-health\n"
npm i -g install dessalines/torrent-tracker-health
fi
# Loop over all torrents
pushd $torrents_dir
2018-12-21 21:31:21 +00:00
# for torrent_file in *.torrent; do
# Copy the unscanned torrent files to a temp dir
mkdir $tmp_torrent_dir
2018-12-21 21:31:21 +00:00
find `pwd` -name "*.torrent" | sort -n | grep -vFf $scanned_out | while read torrent_file ; do
cp "$torrent_file" "$tmp_torrent_dir"
echo $(basename "$torrent_file" .torrent) >> $names_out
done
if [ -z "$(ls -A $tmp_torrent_dir)" ]; then
echo "No new torrents."
else
2018-12-21 21:31:21 +00:00
# Scrape it
torrent-tracker-health --torrent "$tmp_torrent_dir" > $health_out
echo -e "$health_out"
results=$(jq -r '.results | map([.hash, .name, .length, (.created | strptime("%Y-%m-%dT%H:%M:%S.000Z") | mktime), .seeders, .leechers, .completed, (now | floor)] | join(";")) | join("\n")' $health_out)
2018-11-26 17:08:18 +00:00
echo -e "$results" >> $torrents_csv
cat "$names_out" >> $scanned_out
2018-11-26 17:08:18 +00:00
popd
cd scripts
. prune.sh
fi
2018-12-21 21:31:21 +00:00
# Remove the temp dir
rm -rf "$tmp_torrent_dir"
rm "$names_out"
rm "$health_out"