67 lines
1.7 KiB
Bash
Executable File
67 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Checking arguments
|
|
# Help line
|
|
cd ..
|
|
torrents_csv="`pwd`/torrents.csv"
|
|
scanned_out="`pwd`/infohashes_scanned.txt"
|
|
tmp_torrent_dir="`pwd`/tmp_torrents"
|
|
names_out="`pwd`/names.out"
|
|
health_out="`pwd`/health.out"
|
|
touch $scanned_out
|
|
touch $names_out
|
|
touch $health_out
|
|
|
|
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
|
|
# for torrent_file in *.torrent; do
|
|
# Copy the unscanned torrent files to a temp dir
|
|
mkdir $tmp_torrent_dir
|
|
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
|
|
# 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)
|
|
|
|
echo -e "$results" >> $torrents_csv
|
|
cat "$names_out" >> $scanned_out
|
|
|
|
popd
|
|
cd scripts
|
|
. prune.sh
|
|
fi
|
|
|
|
# Remove the temp dir
|
|
rm -rf "$tmp_torrent_dir"
|
|
rm "$names_out"
|
|
rm "$health_out"
|
|
|
|
|