Changing to use standard APIs
This commit is contained in:
parent
e60037ee0e
commit
d0b1596515
6
1337x.torrentengine.sample
Normal file
6
1337x.torrentengine.sample
Normal file
@ -0,0 +1,6 @@
|
||||
torrentengine="https://1337x.to/search/%s/1/"
|
||||
torrentterms='printf https://1337x.to; grep "/torrent/" | head -n 1 | cut -f 2 -d \"'
|
||||
magnetposition=4
|
||||
torrentdebugging="false"
|
||||
searchunifier="+"
|
||||
|
23
Makefile
23
Makefile
@ -1,12 +1,6 @@
|
||||
build:
|
||||
Nothing to build -- this is a bash script.
|
||||
|
||||
configure:
|
||||
mkdir -p /usr/local/etc/WolfPack
|
||||
chmod 0770 /usr/local/etc/WolfPack
|
||||
cp ./*.pup /usr/local/etc/WolfPack
|
||||
chmod 0660 /usr/local/etc/WolfPack/*
|
||||
@echo "Default configuration directory of /usr/local/etc/WolfPack created with example pups"
|
||||
compile: ./1337x.torrentengine.sample
|
||||
if [ ! -d /usr/local/src/SharedLibraries ]; then git -C /usr/local/src/ clone https://aninix.net/foundation/SharedLibraries; else git -C /usr/local/src/SharedLibraries pull; fi
|
||||
if [ ! -d /usr/local/etc/WolfPack ]; then mkdir -p /usr/local/etc/WolfPack; chmod 0770 /usr/local/etc/WolfPack; cp ./*.pup /usr/local/etc/WolfPack; cp ./1337x.torrentengine.sample /usr/local/etc/WolfPack; chmod 0660 /usr/local/etc/WolfPack/*; echo "Default configuration directory of /usr/local/etc/WolfPack created with example pups and torrent engine."; fi
|
||||
@echo "Run make install and add '/usr/local/bin/wolfpack --alpha' to root's crontab to schedule data collection."
|
||||
|
||||
install: /usr/bin/wget /usr/bin/transmission-cli /usr/bin/googler wolfpack wolfpack-stoptorrent /usr/local/bin/whatismyip
|
||||
@ -16,9 +10,18 @@ install: /usr/bin/wget /usr/bin/transmission-cli /usr/bin/googler wolfpack wolfp
|
||||
chmod 0755 /usr/local/bin/wolfpack
|
||||
chown root:root /usr/local/bin/wolfpack*
|
||||
|
||||
clean:
|
||||
@echo Nothing to do
|
||||
|
||||
test:
|
||||
./wolfpack --member ./example-download.pup
|
||||
./wolfpack --member ./example-search.pup
|
||||
./wolfpack --member ./example-shows.pup
|
||||
./wolfpack --member ./example-torrent.pup
|
||||
|
||||
reverse:
|
||||
cp /usr/local/bin/wolfpack* .
|
||||
[ ! -f /root/bin/offload-wolfpack ] || cp /root/bin/offload-wolfpack .
|
||||
cp /root/bin/offload-wolfpack .
|
||||
|
||||
offload: offload-wolfpack /root/.ssh/id_rsa /root/.ssh/id_rsa.pub
|
||||
cp offload-wolfpack /root/bin
|
||||
|
@ -1,3 +1,3 @@
|
||||
torrent
|
||||
/srv/yggdrasil/new_acquisition
|
||||
/usr/local/src/
|
||||
ArchLinux ISO
|
||||
|
139
wolfpack
139
wolfpack
@ -1,10 +1,49 @@
|
||||
#!/bin/bash
|
||||
export IFS="
|
||||
"
|
||||
export torrentengine="https://1337x.to/search/%s/1/"
|
||||
export torrentterms='printf https://1337x.to; grep "/torrent/" | head -n 1 | cut -f 2 -d \"'
|
||||
export magnetposition=4
|
||||
export torrentdebugging="false"
|
||||
|
||||
source /usr/local/src/SharedLibraries/Bash/header
|
||||
|
||||
# Configure the torrenting engine.
|
||||
function configuretorrent {
|
||||
if [ ! -f "$1" ]; then
|
||||
errorheader "Torrent configuration file not found."
|
||||
exit 1;
|
||||
fi
|
||||
param "$1" torrentengine
|
||||
param "$1" torrentterms
|
||||
param "$1" magnetposition
|
||||
param "$1" torrentdebugging
|
||||
param "$1" searchunifier
|
||||
}
|
||||
# Get a magnet link for downloads.
|
||||
function getmagnetlink {
|
||||
if [ -z "$1" ]; then
|
||||
errorheader "Need search terms";
|
||||
exit 1;
|
||||
fi
|
||||
if [ -z "$torrentengine" ] || [ -z "$searchlink" ]; then
|
||||
errorheader Torrent not configured.
|
||||
fi
|
||||
export searchstring="$(echo "$1" | sed "s/ /$searchunifier/g")"
|
||||
export searchlink="$(printf "$torrentengine" "$searchstring")"
|
||||
export searchresult=$(wget -q -O - "$searchlink" | bash -c "$torrentterms")
|
||||
export magnetlink=$(wget -q -O - "$searchresult" | grep 'magnet:?' | cut -f $magnetposition -d \")
|
||||
if [ $torrentdebugging == "true" ]; then
|
||||
echo $searchstring
|
||||
echo $searchlink
|
||||
echo $searchresult
|
||||
echo $magnetlink
|
||||
read
|
||||
fi
|
||||
}
|
||||
function torrentlink {
|
||||
if [ ! -z "$magnetlink" ]; then
|
||||
/usr/bin/transmission-cli -d 1000 -u 1 -er -w "$downloaddir" -b -f "/usr/local/bin/wolfpack-stoptorrent" "$magnetlink"
|
||||
rm -Rf ~/.config/transmission/resume/*
|
||||
rm -Rf ~/.config/transmission/torrents/*
|
||||
fi
|
||||
}
|
||||
|
||||
# Logging
|
||||
export logfile='/var/log/wolfpack.log'
|
||||
|
||||
function helptext {
|
||||
@ -49,27 +88,21 @@ function torrent {
|
||||
echo "Need a valid argument."
|
||||
return;
|
||||
fi
|
||||
if [ "$(whatismyip)" == "$(nslookup aninix.net | grep Address | cut -f 2 -d ' ')" ]; then
|
||||
echo "Should not torrent directly from the AniNIX main IP for privacy reasons" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
export downloaddir=$(head -n 2 "$1" | tail -n 1)
|
||||
if [ "$(pgrep -afc transmission-cli)" -ne 0 ]; then
|
||||
echo "Transmission is still running. Aborting." | tee -a $logfile
|
||||
logstatement "Transmission is still running. Aborting."
|
||||
return;
|
||||
fi
|
||||
for i in $(tail -n +3 "$1"); do
|
||||
export searchstring="$(echo $i | sed 's/ /+/g')"
|
||||
export searchlink="$(printf "$torrentengine" "$searchstring")"
|
||||
export searchresult=$(wget -q -O - "$searchlink" | bash -c "$torrentterms")
|
||||
export magnetlink=$(wget -q -O - "$searchresult" | grep 'magnet:?' | cut -f $magnetposition -d \")
|
||||
if [ $torrentdebugging == "true" ]; then
|
||||
echo $searchstring
|
||||
echo $searchlink
|
||||
echo $searchresult
|
||||
echo $magnetlink
|
||||
read
|
||||
fi
|
||||
if [ "$magnetlink" != "" ]; then
|
||||
/usr/bin/transmission-cli -d 1000 -u 1 -er -w "$downloaddir" -b -f "/usr/local/bin/wolfpack-stoptorrent" "$magnetlink"
|
||||
getmagnetlink "$i"
|
||||
torrentlink
|
||||
if [ ! -z "$magnetlink" ]; then
|
||||
sed -i "/$i/d" "$1"
|
||||
echo Downloaded and removed $i | tee -a $logfile
|
||||
logstatement "Downloaded and removed $i"
|
||||
fi
|
||||
done
|
||||
}
|
||||
@ -82,39 +115,30 @@ function shows {
|
||||
return;
|
||||
fi
|
||||
if [ "$(pgrep -afc transmission-cli)" -ne 0 ]; then
|
||||
echo "Transmission is still running. Aborting." | tee -a $logfile
|
||||
logstatement "Transmission is still running. Aborting."
|
||||
return;
|
||||
fi
|
||||
if [ "$(whatismyip)" == "$(nslookup aninix.net | grep Address | cut -f 2 -d ' ')" ]; then
|
||||
echo "Should not torrent directly from the AniNIX main IP for privacy reasons" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
export downloaddir=$(head -n 2 "$1" | tail -n 1)
|
||||
echo "Would download to "$downloaddir
|
||||
for i in $(tail -n +3 "$1"); do
|
||||
export searchsegment="$(echo $i | tr '#' '+' | tr ' ' '+')"
|
||||
export searchlink="$(printf "$torrentengine" "$searchsegment")"
|
||||
export searchresult=$(wget -q -O - "$searchlink" | bash -c "$torrentterms")
|
||||
export magnetlink=$(wget -q -O - "$searchresult" | grep 'magnet:?' | cut -f $magnetposition -d \")
|
||||
if [ $torrentdebugging == "true" ]; then
|
||||
echo $searchstring
|
||||
echo $searchlink
|
||||
echo $searchresult
|
||||
echo $magnetlink
|
||||
read
|
||||
fi
|
||||
if [ "$magnetlink" != "" ]; then
|
||||
export searchsegment="$(echo $i | tr '#' "$searchunifier")"
|
||||
getmagnetlink "$searchsegment"
|
||||
if [ ! -z "$magnetlink" ]; then
|
||||
# We found an episode.
|
||||
echo $i >> $logfile
|
||||
/usr/bin/transmission-cli -d 600 -u 1 -er -w "$downloaddir" -b -f "/usr/local/bin/wolfpack-stoptorrent" "$magnetlink"
|
||||
torrentlink
|
||||
export sepisode=$(echo $i | cut -f 1 -d '#')
|
||||
export searchterms="$(echo $i | cut -f 2 -d '#')"
|
||||
export season=$(echo $sepisode | cut -f 1 -d 'E' | cut -f 2 -d 'S')
|
||||
export episode=$(echo $sepisode | cut -f 2 -d 'E')
|
||||
export ep=$(printf "%02d\n" $((${episode#0} + 1)))
|
||||
sed -i "s/$i/S"$season"E"$ep"#"$searchterms"/" "$1"
|
||||
echo Downloaded and pup updated. >> $logfile
|
||||
rm -Rf ~/.config/transmission/resume/*
|
||||
rm -Rf ~/.config/transmission/torrents/*
|
||||
logstatement "$i was downloaded and pup updated."
|
||||
rm -f "$downloaddir"/*/*.txt # Including this to avoid breaking Plex
|
||||
rm -f "$downloaddir"/*/*.nfo
|
||||
echo >> $logfile
|
||||
else
|
||||
# We didn't -- is there a new season?
|
||||
export sepisode=$(echo $i | cut -f 1 -d '#')
|
||||
@ -122,15 +146,14 @@ function shows {
|
||||
export season=$(echo $sepisode | cut -f 1 -d 'E' | cut -f 2 -d 'S')
|
||||
export episode=$(echo $sepisode | cut -f 2 -d 'E')
|
||||
export newseason=$(printf "%02d\n" $((${season#0} + 1)))
|
||||
export newsearch="$(echo $searchlink | sed 's/S'$season'E'$episode'/S'$newseason'E01/')"
|
||||
export searchresult=$(wget -q -O - "$newsearch" | bash -c "$torrentterms")
|
||||
export magnetlink=$(wget -q -O - "$searchresult" | grep 'magnet:?' | cut -f $magnetposition -d \")
|
||||
export newsearch="$(echo $searchsegment | sed 's/S'$season'E'$episode'/S'$newseason'E01/')"
|
||||
getmagnetlink "$newsearch"
|
||||
if [ "$magnetlinki" != "" ]; then
|
||||
echo "S"$newseason"E01" $searchterms >> $logfile
|
||||
/usr/bin/transmission-cli -d 600 -u 1 -er -w "$downloaddir" -b -f "/usr/local/bin/wolfpack-stoptorrent" "$magnetlink"
|
||||
torrentlink
|
||||
logstatement "$newsearch Downloaded and pup updated."
|
||||
sed -i "s/$i/S"$newseason"E01#"$searchterms"/" "$1"
|
||||
else
|
||||
echo "No new season found for" $searchterms >> $logfile
|
||||
logstatement "No new season found after $searchterms"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
@ -154,14 +177,14 @@ function download {
|
||||
export filename="$downloaddir"/"$(echo "$nexturl" | rev | cut -f 1 -d \/ | rev)"
|
||||
#if file doesn't already exist....
|
||||
if [ ! -f "$filename" ]; then
|
||||
echo Downloading $nexturl to $filename ... >> $logfile
|
||||
logstatement "Downloading $nexturl to $filename ..."
|
||||
export dedupterm="$(echo $1 | cut -f 1 -d '.' | rev | cut -f 1 -d '/' | rev)"
|
||||
for i in $(find "$downloaddir" | grep -i "$dedupterm"); do
|
||||
echo Deduped! Removed $i from $downloaddir >> $logfile
|
||||
logstatement "Deduped! Removed $i from $downloaddir"
|
||||
rm -Rf $i;
|
||||
done
|
||||
wget -q -O "$filename" "$nexturl"
|
||||
echo Downloaded >> $logfile
|
||||
logstatement "Downloaded"
|
||||
fi
|
||||
}
|
||||
|
||||
@ -175,7 +198,7 @@ function search {
|
||||
export searchstring=$(echo $i | sed 's/ /+/g')
|
||||
export file="$downloaddir"/$searchstring'.txt'
|
||||
echo | googler --count=5 -C -x "$searchstring" | grep -v 'Enter n, p, result' > "$file"
|
||||
echo 'Ran search for '$searchstring' to '$file >> $logfile
|
||||
logstatement "Ran search for $searchstring to $file"
|
||||
done
|
||||
}
|
||||
|
||||
@ -184,13 +207,15 @@ function stoptorrent {
|
||||
killall transmission-cli
|
||||
}
|
||||
|
||||
configuretorrent /usr/local/etc/WolfPack/torrentengine
|
||||
|
||||
if [ "$1" == "" ]; then
|
||||
helptext;
|
||||
exit;
|
||||
fi
|
||||
|
||||
echo '---' $(date) '---' >> $logfile
|
||||
echo Started "$1" "$2" on $(uname -n) >> $logfile
|
||||
logstatement "--- $(date) ---"
|
||||
logstatement "Started $1 $2 on $(uname -n)"
|
||||
|
||||
case "$1" in
|
||||
"--alpha")
|
||||
@ -199,14 +224,14 @@ case "$1" in
|
||||
else
|
||||
export basedir="$2";
|
||||
fi
|
||||
echo "Starting members from pup in "$basedir >> $logfile
|
||||
logstatement "Starting members from pup in $basedir"
|
||||
for i in $(find "$basedir" -type f | grep '.pup'); do
|
||||
/usr/local/bin/wolfpack --member "$i";
|
||||
done
|
||||
;;
|
||||
|
||||
"--member")
|
||||
echo "Spawning a member for "$2 >> $logfile
|
||||
logstatement "Spawning a member for $2"
|
||||
whatismyip | tee -a /var/log/wolfpack.log
|
||||
case "$(head -n 1 "$2")" in
|
||||
"shows")
|
||||
@ -236,6 +261,6 @@ case "$1" in
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "Exited "$1 >> $logfile
|
||||
echo '---' "$(date)" '---' >> $logfile
|
||||
echo >> $logfile
|
||||
logstatement "Exited $1"
|
||||
logstatement "--- $(date) ---"
|
||||
logstatement " "
|
||||
|
Loading…
Reference in New Issue
Block a user