From 10335ae2df5cb5f9912d2af870e939902bb61efc Mon Sep 17 00:00:00 2001 From: cxford Date: Fri, 23 Sep 2016 16:42:15 -0500 Subject: [PATCH] Adding more torrent engines and switching to a file for engine conf --- 1337x.torrentengine.sample | 11 ++-- Makefile | 6 +- offload-wolfpack | 4 ++ torrentproject.torrentengine.sample | 6 ++ wolfpack | 98 +++++++++++++++++++---------- 5 files changed, 84 insertions(+), 41 deletions(-) create mode 100644 torrentproject.torrentengine.sample diff --git a/1337x.torrentengine.sample b/1337x.torrentengine.sample index 4f9ceef..bfd2015 100644 --- a/1337x.torrentengine.sample +++ b/1337x.torrentengine.sample @@ -1,5 +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=true -searchunifier=+ +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='+' +magnetseparator=\" diff --git a/Makefile b/Makefile index f224660..0111aa2 100644 --- a/Makefile +++ b/Makefile @@ -23,9 +23,11 @@ reverse: cp /usr/local/bin/wolfpack* . cp /root/bin/offload-wolfpack . +checkperm: /usr/local/etc/WolfPack/ + chmod -R ug+rw /usr/local/etc/WolfPack/ + chmod 0770 /usr/local/etc/WolfPack/ + offload: offload-wolfpack /root/.ssh/id_rsa /root/.ssh/id_rsa.pub cp offload-wolfpack /root/bin chmod 0700 /root/bin/offload-wolfpack chown root:root /root/bin/offload-wolfpack - - diff --git a/offload-wolfpack b/offload-wolfpack index c33b3e1..0183d3a 100755 --- a/offload-wolfpack +++ b/offload-wolfpack @@ -1,5 +1,9 @@ #!/bin/bash +if [ "$(pgrep -afc wolfpack)" -ne 1 ]; then + echo WolfPack is already working elsewhere. + exit 1 +fi /usr/local/bin/wolfpack --alpha sleep 10 rsync -avz /srv/yggdrasil/new_acquisition/* cxford@10.0.1.3:/srv/yggdrasil/new_acquisition &>>/var/log/wolfpack.log diff --git a/torrentproject.torrentengine.sample b/torrentproject.torrentengine.sample new file mode 100644 index 0000000..d2e064f --- /dev/null +++ b/torrentproject.torrentengine.sample @@ -0,0 +1,6 @@ +torrentengine='http://torrentproject.se/?t=%s' +torrentterms="printf http://torrentproject.se; grep "verified" | head -n 1 | cut -f 2 -d \' | head -n 1" +magnetposition='2' +torrentdebugging='true' +searchunifier='+' +magnetseparator=\' diff --git a/wolfpack b/wolfpack index 1d4394f..7d6af3d 100755 --- a/wolfpack +++ b/wolfpack @@ -1,10 +1,11 @@ #!/bin/bash -source /usr/local/src/SharedLibraries/Bash/header - -# Logging +source /usr/local/etc/WolfPack/torrentengine +export IFS=" +" export logfile='/var/log/wolfpack.log' + function helptext { echo ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -53,15 +54,25 @@ function torrent { fi export downloaddir=$(head -n 2 "$1" | tail -n 1) if [ "$(pgrep -afc transmission-cli)" -ne 0 ]; then - logstatement "Transmission is still running. Aborting." + echo "Transmission is still running. Aborting." | tee -a $logfile return; fi for i in $(tail -n +3 "$1"); do - getmagnetlink "$i" - torrentlink - if [ ! -z "$magnetlink" ]; then + 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 $magnetseparator) + 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" - logstatement "Downloaded and removed $i" + echo Downloaded and removed $i | tee -a $logfile fi done } @@ -72,7 +83,7 @@ function shows { return; fi if [ "$(pgrep -afc transmission-cli)" -ne 0 ]; then - logstatement "Transmission is still running. Aborting." + echo "Transmission is still running. Aborting." | tee -a $logfile return; fi if [ "$(whatismyip)" == "$(nslookup aninix.net | grep Address | cut -f 2 -d ' ')" ]; then @@ -82,20 +93,33 @@ function shows { 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 '#' "$searchunifier")" - getmagnetlink "$searchsegment" - if [ ! -z "$magnetlink" ]; then + 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 # We found an episode. - torrentlink + echo $i | tee -a $logfile + /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 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" - logstatement "$i was downloaded and pup updated." + echo Downloaded and pup updated. | tee -a $logfile + rm -Rf ~/.config/transmission/resume/* + rm -Rf ~/.config/transmission/torrents/* rm -f "$downloaddir"/*/*.txt # Including this to avoid breaking Plex rm -f "$downloaddir"/*/*.nfo + echo | tee -a $logfile else # We didn't -- is there a new season? export sepisode=$(echo $i | cut -f 1 -d '#') @@ -103,14 +127,22 @@ 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 $searchsegment | sed 's/S'$season'E'$episode'/S'$newseason'E01/')" - getmagnetlink "$newsearch" - if [ "$magnetlinki" != "" ]; then - torrentlink - logstatement "$newsearch Downloaded and pup updated." + 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 \") + if [ $torrentdebugging == "true" ]; then + echo $newseason + echo $newsearch + echo $searchresult + echo $magnetlink + read + fi + if [ "$magnetlink" != "" ]; then + echo "S"$newseason"E01" $searchterms | tee -a $logfile + /usr/bin/transmission-cli -d 600 -u 1 -er -w "$downloaddir" -b -f "/usr/local/bin/wolfpack-stoptorrent" "$magnetlink" sed -i "s/$i/S"$newseason"E01#"$searchterms"/" "$1" else - logstatement "No new season found after $searchterms" + echo "No new season found for" $searchterms | tee -a $logfile fi fi done @@ -134,14 +166,14 @@ function download { export filename="$downloaddir"/"$(echo "$nexturl" | rev | cut -f 1 -d \/ | rev)" #if file doesn't already exist.... if [ ! -f "$filename" ]; then - logstatement "Downloading $nexturl to $filename ..." + echo Downloading $nexturl to $filename ... | tee -a $logfile export dedupterm="$(echo $1 | cut -f 1 -d '.' | rev | cut -f 1 -d '/' | rev)" for i in $(find "$downloaddir" | grep -i "$dedupterm"); do - logstatement "Deduped! Removed $i from $downloaddir" + echo Deduped! Removed $i from $downloaddir | tee -a $logfile rm -Rf $i; done wget -q -O "$filename" "$nexturl" - logstatement "Downloaded" + echo Downloaded | tee -a $logfile fi } @@ -155,7 +187,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" - logstatement "Ran search for $searchstring to $file" + echo 'Ran search for '$searchstring' to '$file | tee -a $logfile done } @@ -164,15 +196,13 @@ function stoptorrent { killall transmission-cli } -configuretorrent /usr/local/etc/WolfPack/torrentengine - if [ "$1" == "" ]; then helptext; - exit; + exit 1; fi -logstatement "--- $(date) ---" -logstatement "Started $1 $2 on $(uname -n)" +echo '---' $(date) '---' | tee -a $logfile +echo Started "$1" "$2" on $(uname -n) | tee -a $logfile case "$1" in "--alpha") @@ -181,14 +211,14 @@ case "$1" in else export basedir="$2"; fi - logstatement "Starting members from pup in $basedir" + echo "Starting members from pup in "$basedir | tee -a $logfile for i in $(find "$basedir" -type f | grep '.pup'); do /usr/local/bin/wolfpack --member "$i"; done ;; "--member") - logstatement "Spawning a member for $2" + echo "Spawning a member for "$2 | tee -a $logfile whatismyip | tee -a /var/log/wolfpack.log case "$(head -n 1 "$2")" in "shows") @@ -218,6 +248,6 @@ case "$1" in ;; esac -logstatement "Exited $1" -logstatement "--- $(date) ---" -logstatement " " +echo "Exited "$1 | tee -a $logfile +echo '---' "$(date)" '---' | tee -a $logfile +echo | tee -a $logfile