Changing to use standard APIs

This commit is contained in:
cxford 2016-08-30 13:17:18 -05:00
parent e60037ee0e
commit d0b1596515
4 changed files with 102 additions and 68 deletions

View 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="+"

View File

@ -1,12 +1,6 @@
build: compile: ./1337x.torrentengine.sample
Nothing to build -- this is a bash script. 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
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"
@echo "Run make install and add '/usr/local/bin/wolfpack --alpha' to root's crontab to schedule data collection." @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 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 chmod 0755 /usr/local/bin/wolfpack
chown root:root /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: reverse:
cp /usr/local/bin/wolfpack* . 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 offload: offload-wolfpack /root/.ssh/id_rsa /root/.ssh/id_rsa.pub
cp offload-wolfpack /root/bin cp offload-wolfpack /root/bin

View File

@ -1,3 +1,3 @@
torrent torrent
/srv/yggdrasil/new_acquisition /usr/local/src/
ArchLinux ISO ArchLinux ISO

139
wolfpack
View File

@ -1,10 +1,49 @@
#!/bin/bash #!/bin/bash
export IFS="
" source /usr/local/src/SharedLibraries/Bash/header
export torrentengine="https://1337x.to/search/%s/1/"
export torrentterms='printf https://1337x.to; grep "/torrent/" | head -n 1 | cut -f 2 -d \"' # Configure the torrenting engine.
export magnetposition=4 function configuretorrent {
export torrentdebugging="false" 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' export logfile='/var/log/wolfpack.log'
function helptext { function helptext {
@ -49,27 +88,21 @@ function torrent {
echo "Need a valid argument." echo "Need a valid argument."
return; return;
fi 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) export downloaddir=$(head -n 2 "$1" | tail -n 1)
if [ "$(pgrep -afc transmission-cli)" -ne 0 ]; then if [ "$(pgrep -afc transmission-cli)" -ne 0 ]; then
echo "Transmission is still running. Aborting." | tee -a $logfile logstatement "Transmission is still running. Aborting."
return; return;
fi fi
for i in $(tail -n +3 "$1"); do for i in $(tail -n +3 "$1"); do
export searchstring="$(echo $i | sed 's/ /+/g')" getmagnetlink "$i"
export searchlink="$(printf "$torrentengine" "$searchstring")" torrentlink
export searchresult=$(wget -q -O - "$searchlink" | bash -c "$torrentterms") if [ ! -z "$magnetlink" ]; then
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"
sed -i "/$i/d" "$1" sed -i "/$i/d" "$1"
echo Downloaded and removed $i | tee -a $logfile logstatement "Downloaded and removed $i"
fi fi
done done
} }
@ -82,39 +115,30 @@ function shows {
return; return;
fi fi
if [ "$(pgrep -afc transmission-cli)" -ne 0 ]; then if [ "$(pgrep -afc transmission-cli)" -ne 0 ]; then
echo "Transmission is still running. Aborting." | tee -a $logfile logstatement "Transmission is still running. Aborting."
return; return;
fi 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) export downloaddir=$(head -n 2 "$1" | tail -n 1)
echo "Would download to "$downloaddir echo "Would download to "$downloaddir
for i in $(tail -n +3 "$1"); do for i in $(tail -n +3 "$1"); do
export searchsegment="$(echo $i | tr '#' '+' | tr ' ' '+')" export searchsegment="$(echo $i | tr '#' "$searchunifier")"
export searchlink="$(printf "$torrentengine" "$searchsegment")" getmagnetlink "$searchsegment"
export searchresult=$(wget -q -O - "$searchlink" | bash -c "$torrentterms") if [ ! -z "$magnetlink" ]; then
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
# We found an episode. # We found an episode.
echo $i >> $logfile torrentlink
/usr/bin/transmission-cli -d 600 -u 1 -er -w "$downloaddir" -b -f "/usr/local/bin/wolfpack-stoptorrent" "$magnetlink"
export sepisode=$(echo $i | cut -f 1 -d '#') export sepisode=$(echo $i | cut -f 1 -d '#')
export searchterms="$(echo $i | cut -f 2 -d '#')" export searchterms="$(echo $i | cut -f 2 -d '#')"
export season=$(echo $sepisode | cut -f 1 -d 'E' | cut -f 2 -d 'S') export season=$(echo $sepisode | cut -f 1 -d 'E' | cut -f 2 -d 'S')
export episode=$(echo $sepisode | cut -f 2 -d 'E') export episode=$(echo $sepisode | cut -f 2 -d 'E')
export ep=$(printf "%02d\n" $((${episode#0} + 1))) export ep=$(printf "%02d\n" $((${episode#0} + 1)))
sed -i "s/$i/S"$season"E"$ep"#"$searchterms"/" "$1" sed -i "s/$i/S"$season"E"$ep"#"$searchterms"/" "$1"
echo Downloaded and pup updated. >> $logfile logstatement "$i was downloaded and pup updated."
rm -Rf ~/.config/transmission/resume/*
rm -Rf ~/.config/transmission/torrents/*
rm -f "$downloaddir"/*/*.txt # Including this to avoid breaking Plex rm -f "$downloaddir"/*/*.txt # Including this to avoid breaking Plex
rm -f "$downloaddir"/*/*.nfo rm -f "$downloaddir"/*/*.nfo
echo >> $logfile
else else
# We didn't -- is there a new season? # We didn't -- is there a new season?
export sepisode=$(echo $i | cut -f 1 -d '#') 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 season=$(echo $sepisode | cut -f 1 -d 'E' | cut -f 2 -d 'S')
export episode=$(echo $sepisode | cut -f 2 -d 'E') export episode=$(echo $sepisode | cut -f 2 -d 'E')
export newseason=$(printf "%02d\n" $((${season#0} + 1))) export newseason=$(printf "%02d\n" $((${season#0} + 1)))
export newsearch="$(echo $searchlink | sed 's/S'$season'E'$episode'/S'$newseason'E01/')" export newsearch="$(echo $searchsegment | sed 's/S'$season'E'$episode'/S'$newseason'E01/')"
export searchresult=$(wget -q -O - "$newsearch" | bash -c "$torrentterms") getmagnetlink "$newsearch"
export magnetlink=$(wget -q -O - "$searchresult" | grep 'magnet:?' | cut -f $magnetposition -d \")
if [ "$magnetlinki" != "" ]; then if [ "$magnetlinki" != "" ]; then
echo "S"$newseason"E01" $searchterms >> $logfile torrentlink
/usr/bin/transmission-cli -d 600 -u 1 -er -w "$downloaddir" -b -f "/usr/local/bin/wolfpack-stoptorrent" "$magnetlink" logstatement "$newsearch Downloaded and pup updated."
sed -i "s/$i/S"$newseason"E01#"$searchterms"/" "$1" sed -i "s/$i/S"$newseason"E01#"$searchterms"/" "$1"
else else
echo "No new season found for" $searchterms >> $logfile logstatement "No new season found after $searchterms"
fi fi
fi fi
done done
@ -154,14 +177,14 @@ function download {
export filename="$downloaddir"/"$(echo "$nexturl" | rev | cut -f 1 -d \/ | rev)" export filename="$downloaddir"/"$(echo "$nexturl" | rev | cut -f 1 -d \/ | rev)"
#if file doesn't already exist.... #if file doesn't already exist....
if [ ! -f "$filename" ]; then 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)" export dedupterm="$(echo $1 | cut -f 1 -d '.' | rev | cut -f 1 -d '/' | rev)"
for i in $(find "$downloaddir" | grep -i "$dedupterm"); do 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; rm -Rf $i;
done done
wget -q -O "$filename" "$nexturl" wget -q -O "$filename" "$nexturl"
echo Downloaded >> $logfile logstatement "Downloaded"
fi fi
} }
@ -175,7 +198,7 @@ function search {
export searchstring=$(echo $i | sed 's/ /+/g') export searchstring=$(echo $i | sed 's/ /+/g')
export file="$downloaddir"/$searchstring'.txt' export file="$downloaddir"/$searchstring'.txt'
echo | googler --count=5 -C -x "$searchstring" | grep -v 'Enter n, p, result' > "$file" 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 done
} }
@ -184,13 +207,15 @@ function stoptorrent {
killall transmission-cli killall transmission-cli
} }
configuretorrent /usr/local/etc/WolfPack/torrentengine
if [ "$1" == "" ]; then if [ "$1" == "" ]; then
helptext; helptext;
exit; exit;
fi fi
echo '---' $(date) '---' >> $logfile logstatement "--- $(date) ---"
echo Started "$1" "$2" on $(uname -n) >> $logfile logstatement "Started $1 $2 on $(uname -n)"
case "$1" in case "$1" in
"--alpha") "--alpha")
@ -199,14 +224,14 @@ case "$1" in
else else
export basedir="$2"; export basedir="$2";
fi 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 for i in $(find "$basedir" -type f | grep '.pup'); do
/usr/local/bin/wolfpack --member "$i"; /usr/local/bin/wolfpack --member "$i";
done done
;; ;;
"--member") "--member")
echo "Spawning a member for "$2 >> $logfile logstatement "Spawning a member for $2"
whatismyip | tee -a /var/log/wolfpack.log whatismyip | tee -a /var/log/wolfpack.log
case "$(head -n 1 "$2")" in case "$(head -n 1 "$2")" in
"shows") "shows")
@ -236,6 +261,6 @@ case "$1" in
;; ;;
esac esac
echo "Exited "$1 >> $logfile logstatement "Exited $1"
echo '---' "$(date)" '---' >> $logfile logstatement "--- $(date) ---"
echo >> $logfile logstatement " "