2018-11-25 23:21:52 +00:00
|
|
|
#!/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"
|
2019-01-24 22:45:18 +00:00
|
|
|
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
|
2019-01-24 22:45:18 +00:00
|
|
|
touch $names_out
|
|
|
|
touch $health_out
|
2018-12-21 21:31:21 +00:00
|
|
|
|
2018-11-25 23:21:52 +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
|
2019-01-24 22:45:18 +00:00
|
|
|
# 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
|
2019-01-24 22:45:18 +00:00
|
|
|
cp "$torrent_file" "$tmp_torrent_dir"
|
|
|
|
echo $(basename "$torrent_file" .torrent) >> $names_out
|
|
|
|
done
|
2018-11-25 23:21:52 +00:00
|
|
|
|
2019-01-24 22:45:18 +00:00
|
|
|
if [ -z "$(ls -A $tmp_torrent_dir)" ]; then
|
|
|
|
echo "No new torrents."
|
|
|
|
else
|
2018-12-21 21:31:21 +00:00
|
|
|
# Scrape it
|
2019-01-24 22:45:18 +00:00
|
|
|
torrent-tracker-health --torrent "$tmp_torrent_dir" > $health_out
|
2018-11-25 23:53:55 +00:00
|
|
|
|
2019-01-24 22:45:18 +00:00
|
|
|
echo -e "$health_out"
|
2018-11-25 23:53:55 +00:00
|
|
|
|
2019-01-24 22:45:18 +00:00
|
|
|
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
|
|
|
|
2019-01-24 22:45:18 +00:00
|
|
|
echo -e "$results" >> $torrents_csv
|
|
|
|
cat "$names_out" >> $scanned_out
|
2018-11-26 17:08:18 +00:00
|
|
|
|
2019-01-24 22:45:18 +00:00
|
|
|
popd
|
|
|
|
cd scripts
|
|
|
|
. prune.sh
|
|
|
|
fi
|
2018-12-21 21:31:21 +00:00
|
|
|
|
2019-01-24 22:45:18 +00:00
|
|
|
# Remove the temp dir
|
|
|
|
rm -rf "$tmp_torrent_dir"
|
|
|
|
rm "$names_out"
|
|
|
|
rm "$health_out"
|
2018-11-25 23:21:52 +00:00
|
|
|
|
|
|
|
|