several usenet script

sendng.sh 25KB

    #!/bin/bash FILE=$1 #TEXT=$(echo $2 | sed 's/°//' | iconv -f utf-8 -t ascii//translit) TEXT=$(echo $2 | sed 's/[Nn][ ]*°/N/g' | konwert utf8-ascii) TORRENTHASH=$3 TRACKER=$4 RTORRENTRC=$5 DEPTH=$6 HDCHKSLP=120 HDCHK=0 #For multiple file process in a directory, max size of the files to process it as a single directory #20480 mio = 20Gio MULTIPLEMAXSIZE=20480 M="m" IDTOSQL="" TKNAME="" TKID="" WEECHAT="/tmp/weechat_fifo" LCYAN="\x0311" RESET="\x0F" LBLUE="\x0312" GREEN="\x0309" WHITE="\x0300" COOKIE_ABN="/tmp/cookie_abn.txt" COOKIE_XTHOR="/tmp/cookie_xthor.txt" function doInit() { echo "FILE: $FILE" DIRNAME=$(dirname "$FILE") echo "DIRNAME: $DIRNAME" MULTIPLEDIR=0 #TAG=$(echo $1 | cut -d"/" -f6) OLD_IFS=$IFS IFS='/' read -r -a TBL <<< "$FILE" TAG=${TBL[-2]} IFS=$OLD_IFS TEMPD="/tmp/usenet" NEWSUPLOG="$TEMPD/newsup.log" HTTP="$HOME/public_html/.93oJMgFL53wm" OUTPUT="$HTTP/$TAG" #PASSWD="ko{Uz6ek9ou}Ze" NEWZNAB="/home/newznab/nnplus/misc/update_scripts" NZBTEMP="/tmp/usenet/nzbtemp" FAILEDFILE="$HOME/scripts/outputRtorrent_failed.txt" RARSIZE="52224000b" CONNECTIONS=15 N=1 RECOVERY="-r15" SENDDIR=0 MOVIESHD=2040 MOVIESSD=2030 GAMES=4050 TV=5020 TVHDFR=5042 TVHDVOSTFR=5041 TVSD=5030 DOC=5080 ANIME=5070 EBOOKS=7020 COMICS=7030 MANGAS=7040 MAGS=7010 MUSIQUE=3010 FLAC=3040 MISC=8010 SONY=1080 MICROSOFT=1050 NINTENDO=1030 APPZ=4010 XXX=6070 MAC=4030 TVSPORT=5060 TVOTHER=5050 BLURAY=2050 THREED=2060 TVBLURAY=5090 NFO=8020 CAT=$MISC changeTrackerName getInfo isNfo=0 if ! [[ $DEPTH =~ ^-?[0-9]+$ ]]; then DEPTH=-1 fi echo "DEPTH: $DEPTH" } function RarFile() { #regex="$DIRNAME/(.*)" #torar="$FILE" #if [[ $FILE =~ $regex ]]; then # torar=${BASH_REMATCH[1]} #fi SIZES=${#DIRNAME} ((SIZES=SIZES+2)) torar=$(echo "$FILE" | cut -c $SIZES-) #sha1sum # echo "computing SHA1SUM" # echo "torar: $torar" # SHA1SUM=$({ echo "$torar"; echo; # sha1sum "$FILE"; # } | sha1sum | cut -d" " -f1) # echo "SHA1SUM: $SHA1SUM" #rar get_rar_size echo "RarFile"; cd "$DIRNAME" echo "torar: $torar" START=$(date +%s) nice /usr/bin/rar a $TEMPD/$ENCODE/$ENCODE -hp$PASSWD -v$RARSIZE -m0 -mt4 -y -idcdp -- "$torar" 2>&1 1>/dev/null END=$(date +%s) RARTIME=$(( $END - $START )) echo "RarFile done. It took $RARTIME seconds to complete" } function RarDirectory() { #regex="$DIRNAME/(.*)" #torar="$FILE" #if [[ $FILE =~ $regex ]]; then # torar=${BASH_REMATCH[1]} #fi SIZES=${#DIRNAME} ((SIZES=SIZES+2)) torar=$(echo "$FILE" | cut -c $SIZES-) #sha1sum #rar get_rar_size echo "RarDirectory"; cd "$DIRNAME" echo "torar: $torar" START=$(date +%s) nice /usr/bin/rar a $TEMPD/$ENCODE/$ENCODE -hp$PASSWD -v$RARSIZE -m0 -mt4 -y -idcdp -r -- "$torar" 2>&1 1>/dev/null END=$(date +%s) RARTIME=$(( $END - $START )) echo "RarDirectory done. It took $RARTIME seconds to complete" } function Makecksfv() { echo "cksfv" cd $TEMPD/$ENCODE START=$(date +%s) #nice cksfv * > $ENCODE.sfv WINEDEBUG=-all nice wine $HOME/bin/MultiPar/sfv_md5.exe c $ENCODE.sfv *.rar 3>&1 1>&2 2>&3- END=$(date +%s) CKSFVTIME=$(( $END - $START )) echo "SFV done. It took $CKSFVTIME seconds to complete" } function get_par2_blocksize() { par2_block_size=0; files_size=$(find -L . -maxdepth 1 -regextype posix-extended -iregex '.*\.rar' -type f -exec stat -L -c %s {} \; | paste -s -d'+' | bc) par2_block_size=$(echo "768000 + ($files_size / 1500000000)*768000" | bc 2>/dev/null); if [[ "$par2_block_size" -ge "7680000" ]] then par2_block_size=7680000 fi } function get_rar_size(){ SIZE=`du -sb "$FILE" | cut -f1` if [[ $SIZE -gt 8000000000 ]]; then RARSIZE="157440000b" else RARSIZE="52224000b" fi #setup the number of connections for upload if [[ $SIZE -lt 10000000 ]]; then CONNECTIONS=3 elif [[ $SIZE -lt 100000000 ]]; then CONNECTIONS=8 elif [[ $SIZE -lt 500000000 ]]; then CONNECTIONS=20 else CONNECTIONS=25 fi echo "CONNECTIONS: $CONNECTIONS" } function get_par2_recoverysize() { SIZE=`du -sb "$FILE" | cut -f1` SIZE=$(echo "$SIZE / 768000" | bc 2>/dev/null); if [ $SIZE -lt 14 ]; then #RECOVERY="-c15" RECOVERY="/rn15" elif [ $SIZE -lt 130 ]; then #RECOVERY="-r50" RECOVERY="/rr50" elif [ $SIZE -lt 650 ]; then #RECOVERY="-r25" RECOVERY="/rr25" else #RECOVERY="-r15" RECOVERY="/rr15" fi } function get_par2_slize_count() { file_slice_count=$(find -L . -maxdepth 1 -regextype posix-extended -iregex '.*\.rar' -type f -exec stat -L -c %s {} \; | while read -r line; do echo -n "($line+$par2_block_size-1)/$par2_block_size+"; done | sed 's/.$/\n/' | bc) #file_slice_count=$(let result=($files_size+$par2_block_size-1)/$par2_block_size; echo $result) if [ $SIZE -lt 14 ]; then SLIZE="15" elif [ $SIZE -lt 130 ]; then SLIZE=$(let result=(\($file_slice_count*50+50\)/100);echo $result) elif [ $SIZE -lt 650 ]; then SLIZE=$(let result=(\($file_slice_count*25+25\)/100);echo $result) else SLIZE=$(let result=(\($file_slice_count*15+15\)/100);echo $result) fi } function get_par2_slice_per_file() { slice_per_file=$(find -L . -maxdepth 1 -regextype posix-extended -iregex '.*\.rar' -type f -exec stat -L -c %s {} \; | sort -r -n | head -n 1) if [[ $par2_block_size -ge $slice_per_file ]]; then par2_block_size=$slice_per_file fi slice_per_file=$(( ($slice_per_file + $par2_block_size - 1) / $par2_block_size )) } function get_par2_slice_per_file2() { parity_num=$SLIZE recovery_limit=$slice_per_file recovery_num=0 i=1 j=0 k=0 while [ $j -lt $parity_num ]; do k=$i if [ $k -ge $recovery_limit ]; then k=$recovery_limit else i=$(( $i * 2 )) fi j=$(( $j + $k )) recovery_num=$(( $recovery_num + 1 )) done recovery_limit=$k #echo "recovery_limit: $recovery_limit" #echo "recovery_num: $recovery_num" } function CreatePar() { echo "CreatePar"; RETVAL2=999; get_par2_blocksize; get_par2_slice_per_file; get_par2_recoverysize; get_par2_slize_count; get_par2_slice_per_file2; echo "recovery: $RECOVERY" echo "Input File total size : $files_size" echo "Input File Slice size : $par2_block_size" echo "Input File Slice count : $file_slice_count" echo "Recovery Slice count : $SLIZE" echo "Recovery File count : $recovery_num" echo "Slice distribution : 2, power of two (until $recovery_limit)" echo "slice_per_file: $slice_per_file" FREEMEMORY=$(free -m | grep Mem | awk '{printf "%dM", ($4+$7)*6/8}') START=$(date +%s) nice node $HOME/tools/ParPar/bin/parpar.js -s $par2_block_size -r $SLIZE -m $FREEMEMORY -d pow2 -n -p $recovery_limit -o $ENCODE *.rar *.sfv END=$(date +%s) PARTIME=$(( $END - $START )) echo "CreatePar OK. It took $PARTIME seconds to complete" } function injectPassword() { OLD="<nzb>" NEW="<nzb><head><meta type=\"password\">$PASSWD<\/meta><\/head>" if [ -f "$TEMPD/$NZBFILE" ]; then #echo "inject password" sed "s/$OLD/$NEW/g" "$TEMPD/$NZBFILE" > /tmp/$NZBFILE && mv /tmp/$NZBFILE "$TEMPD/$NZBFILE" fi } function _SendNg() { echo "_SendNg" cd $TEMPD $HOME/bin/NewsUP/newsup.pl -connections $CONNECTIONS -headercheck $HDCHK -headerCheckSleep $HDCHKSLP -headerCheckConnections $CONNECTIONS -f "$ENCODE" -metadata password="$PASSWD" -nzb "newsmangler_$ENCODE.nzb" | tee $NEWSUPLOG & sleep 5s OLDSIZE=$(du -sb "$NEWSUPLOG" | sed 's/\([0-9]*\).*/\1/') SIZE=0 DONOTHING=0 PID=$(pgrep -f "newsup.pl.*$ENCODE") while [[ $PID != "" ]]; do if [[ $DONOTHING -gt 300 ]]; then echo "Killing newsup as not progressing anymore" kill -9 $PID echo "restarting newsup" $HOME/bin/NewsUP/newsup.pl -connections $CONNECTIONS -headercheck $HDCHK -headerCheckSleep $HDCHKSLP -headerCheckConnections $CONNECTIONS -f "$ENCODE" -metadata password="$PASSWD" -nzb "newsmangler_$ENCODE.nzb" | tee $NEWSUPLOG & sleep 5s OLDSIZE=$(du -sb "$NEWSUPLOG" | sed 's/\([0-9]*\).*/\1/') SIZE=0 DONOTHING=0 fi if [[ $SIZE -eq $OLDSIZE ]]; then ((DONOTHING=DONOTHING+5)) else DONOTHING=0 fi sleep 5s PID=$(pgrep -f "newsup.pl.*$ENCODE") OLDSIZE=$SIZE SIZE=$(du -sb "$NEWSUPLOG" | sed 's/\([0-9]*\).*/\1/') done } function SendNg2(){ echo "SendNg2" cd $TEMPD _SendNg SLEEP=0 while [[ ! -f $NZBFILE ]]; do SLEEP=$(($SLEEP + 2)) MSLEEP=$SLEEP$M echo "Error during upload to NG, waiting $MSLEEP and try again" sleep $MSLEEP _SendNg done } function SaveNzb() { echo "SaveNzb"; if [ -f "$FILE" ]; then if [[ "$TEXT" == *".nfo"* ]]; then TEXT="$TEXT" isNfo=1 elif [[ "$TEXT" =~ .*\..{2,3}$ ]]; then TEXT="${TEXT%.*}" isNfo=0 fi fi TEXT=${TEXT//[\/]/_} OUTPUTFILE="$TEXT.nzb"; OUTPUTFILE3="$TORRENTHASH.nzb" echo -n "Output file: "; echo $OUTPUTFILE2; if [ -f "$TEMPD/$NZBFILE" ]; then echo "write file"; if [[ $TORRENTHASH != "" ]]; then cp "$TEMPD/$NZBFILE" "$TEMPD/$OUTPUTFILE3"; fi if [ "$TAG" != "XXX" ]; then cp "$TEMPD/$NZBFILE" "$NZBTEMP/$OUTPUTFILE"; else cp "$TEMPD/$NZBFILE" "$OUTPUT/$OUTPUTFILE"; fi fi } function SendFile() { Encode; RarFile; Makecksfv; CreatePar; SendNg2; SaveNzb; processNewzNab; DelData; } function CheckDir() { SENDDIR=0 echo "CheckDir" SIZE=$(du -sm "$FILE" | sed 's/\([0-9]*\).*/\1/') if [ $SIZE -gt $MULTIPLEMAXSIZE ]; then shopt -s lastpipe find "$FILE" -type f -print0 | while read -d '' -r i; do SIZE=$(du -sm "$i" | sed 's/\([0-9]*\).*/\1/') if [ $SIZE -gt 150 ]; then ((SENDDIR++)) fi done fi echo "SENDDIR= $SENDDIR" } function SendDepthDir() { local OLDOUTPUT="$OUTPUT" local MYDEPTH=$DEPTH echo "Depth = $DEPTH" if [[ -f "$FILE" ]]; then SendFile; elif [[ -d "$FILE" ]]; then if [[ $DEPTH -ne 0 ]]; then ((DEPTH--)) OUTPUT="$OUTPUT/$TEXT" SECTION=$(echo $FILE | grep -o "/" | wc -l) ((SECTION++)) local OLDFILE=$(echo $FILE | cut -d"/" -f$SECTION) for element in "$FILE"/* do FILE=$element SECTION=$(echo $element | grep -o "/" | wc -l) ((SECTION++)) TEXT=$(echo $element | cut -d"/" -f$SECTION) TEXT=$(echo $TEXT | sed 's/[Nn][ ]*°/N/g' | konwert utf8-ascii) if [[ $TEXT =~ $regex ]]; then TEXT=${BASH_REMATCH[1]} fi SendDepthDir done else SendOneDir; fi fi OUTPUT="$OLDOUTPUT" DEPTH=$MYDEPTH } function SendMultipleDir() { echo "SendMultipleDir" local OLDOUTPUT="$OUTPUT" CheckDir; if [ $SENDDIR -gt 1 ]; then OUTPUT="$OUTPUT/$TEXT" MULTIPLEDIR=1 SECTION=$(echo $FILE | grep -o "/" | wc -l) ((SECTION++)) local OLDFILE=$(echo $FILE | cut -d"/" -f$SECTION) for element in "$FILE"/* do FILE=$element SECTION=$(echo $element | grep -o "/" | wc -l) ((SECTION++)) TEXT=$(echo $element | cut -d"/" -f$SECTION) #if [[ $TEXT == *".nfo"* ]]; then # TEXT="$OLDFILE.nfo" #fi TEXT=$(echo $TEXT | sed 's/[Nn][ ]*°/N/g' | konwert utf8-ascii) regex="^[\.]+(.*)" if [[ $TEXT =~ $regex ]]; then TEXT=${BASH_REMATCH[1]} fi if [ -f "$element" ]; then SendFile; elif [ -d "$element" ]; then SendMultipleDir; fi done else SendOneDir; fi OUTPUT="$OLDOUTPUT" } function SendDirectory() { #echo "here" #echo -n "Directory: "; #echo $FILE; #echo -n "Will be save as: "; #echo $TEXT; if [[ $DEPTH -lt 0 ]]; then if [ "$TAG" == "Animes" ]; then #echo "Animes !!" SendMultipleDir; elif [ "$TAG" == "Films" ]; then #echo "Films !!!" SendMultipleDir; elif [ "$TAG" == "Series" ]; then #echo "Series !!!" SendMultipleDir; else SendOneDir; fi else echo "SendDepthDir" SendDepthDir; fi } function SendOneDir() { echo "SendOneDir" Encode; RarDirectory; Makecksfv; CreatePar; SendNg2; SaveNzb; processNewzNab; DelData; } function Encode() { PASSWD=$(echo `</dev/urandom tr -dc 'A-Za-z0-9[\-_@]=+$!\(\)' | head -c14`) RAND=$TEXT$PASSWD ENCODE=$(echo -n $RAND | md5sum | cut -d" " -f1) #NZBFILE=$ENCODE".nzb" NZBFILE="newsmangler_"$ENCODE".nzb" echo -n "Encode: "; echo $ENCODE; cd $TEMPD; mkdir -p $ENCODE; cd $ENCODE; echo "******* Password: $PASSWD"; } function DelData() { echo "DelData"; cd $TEMPD; rm -rf $ENCODE; rm -f $NZBFILE; rm -f $OUTPUTFILE3; rm /tmp/usenet/nzbtemp/*.nzb } function changeTrackerName() { if [[ $TRACKER == *"xthor"* ]]; then TRACKER="xthor" fi if [[ $TRACKER == *"abnormal"* ]]; then TRACKER="abnormal" fi } function getInfo() { old_IFS=$IFS IFS=$'\t' SQLTITLE="" SQLURL="" while read -a row do TEXT=$(echo ${row[0]} | sed 's/[Nn][ ]*°/N/g' | konwert utf8-ascii) RLSURL=${row[1]} TKNAME="${row[0]}" done < <(echo "select TITLE, URL from releasestk.flexget where HASH=\"$TORRENTHASH\" and TRACKER=\"$TRACKER\";" | mysql -N -h localhost -u SQLUSER -pSQLPASSWD ) echo "TEXT: $TEXT" echo "RLSURL: $RLSURL" echo "TKNAME: $TKNAME" echo "TRACKER: $TRACKER" case "$TRACKER" in 'xthor' ) getInfoFromXTHOR ;; 'abnormal' ) getInfoFromABN ;; esac regex="^[\.]+(.*)" if [[ $TEXT =~ $regex ]]; then TEXT=${BASH_REMATCH[1]} fi #remove unnecessary extensions regex="(.*)\.(epub)$" if [[ $TEXT =~ $regex ]]; then TEXT=${BASH_REMATCH[1]} fi echo "TITLE: $TEXT" } function getInfoFromABN() { echo "getInfoFromABN()" #getting ID regex=".*id=([0-9]+)" if [[ $RLSURL =~ $regex ]]; then TKID="${BASH_REMATCH[1]}" fi } function getInfoFromXTHOR() { echo "getInfoFromXTHOR()" #getting ID regex=".*torrent=([0-9]+)" if [[ $RLSURL =~ $regex ]]; then TKID="${BASH_REMATCH[1]}" fi } function getInfoFailed() { echo "Failed getting data from tracker $TRACKER. Exiting" echo "$FILE ¤¤ $TEXT ¤¤ $TORRENTHASH ¤¤ $TRACKER ¤¤ $RTORRENTRC ¤¤ $DEPTH" >> $FAILEDFILE exit } function getNFOABN() { echo "getNFOABN()" NFOURL="" if [[ $TKID != "" ]]; then echo "Getting NFO from ABN for release id $TKID" NFOURL="https://abnormal.ws/torrents.php?action=downloadnfo&authkey=$ABNAUTHKEY&id=$TKID" NFOFILE="$TEMPD/ABN_$TKID.nfo" result=$(curl -D - -s -k --referer "https://abnormal.ws" --cookie $COOKIE_ABN $NFOURL -o "$NFOFILE" | grep Location | cut -d' ' -f2) echo "result: $result" if [[ $result == *"login.php"* ]]; then echo "ABN cookie outdated, regenerating it" result=$(curl -c $COOKIE_ABN --referer https://abnormal.ws -d "username=$ABNUSERID" -d "password=$ABNPASSWD" "https://abnormal.ws/login.php") sleep 1s result=$(curl -D - -s -k --referer "https://abnormal.ws" --cookie $COOKIE_ABN $NFOURL -o "$NFOFILE" | grep Location | cut -d' ' -f2) if [[ $result == *"login.php"* ]]; then echo "ABN NFO get issues" NFOFILE="" fi fi fi } function manipulateNFOXthor() { echo "manipulateNFOXthor()" regex="data-cfemail=\"([a-zA-Z0-9]+)\"" for aString in ${result[@]}; do if [[ ${aString} =~ $regex ]]; then echo "email decryption" echo "hash: ${BASH_REMATCH[1]}" decoded=$(php $HOME/scripts/decodeCFemail.php ${BASH_REMATCH[1]}) echo "email decoded: $decoded" result=$(echo "$result" | perl -pe 's/<a class=\"__cf_email__\"((?!<\/script>).)*<\/script>/BLIBLABLU/') result=$(echo "$result" | sed "s/BLIBLABLU/$decoded/") fi done echo $result | xmllint --html --xpath "string(//td[@class='text'])" 2>/dev/null - > $NFOFILE.temp if [[ $(grep '[^[:space:]]' $NFOFILE.temp) != "" ]]; then dos2unix $NFOFILE.temp tr "αΘΦτ" "àéèç" < $NFOFILE.temp > $NFOFILE recode utf8..cp437 $NFOFILE rm $NFOFILE.temp else echo "NFO empty. Removing it" rm $NFOFILE.temp NFOFILE="" fi } function getNFOXthor() { echo "getNFOXthor" NFOURL="" echo "TKID: $TKID" if [[ $TKID != "" ]]; then echo "Getting NFO from XTHOR for release id $TKID" NFOURL="https://xthor.bz/details.php?id=$TKID" NFOFILE="$TEMPD/XTHOR_$TKID.nfo" result=$(curl -s -k --referer "https://xthor.bz" --cookie $COOKIE_XTHOR "$NFOURL") if [[ $result == "" ]]; then echo "XTHOR cookie probably outdated, regenerating it" result=$(curl -c $COOKIE_XTHOR --referer "https://xthor.bz" "https://xthor.bz/pagelogin.php?qlogin=$FASTXTHORLOGIN") sleep 1s result=$(curl -s -k --referer "https://xthor.bz" --cookie $COOKIE_XTHOR "$NFOURL") if [[ $result == "" ]]; then echo "XTHOR NFO get issues" NFOFILE="" else manipulateNFOXthor fi else manipulateNFOXthor fi fi } function getTrackerNFO() { echo "getTrackerNFO()" case "$TRACKER" in 'abnormal' ) getNFOABN ;; 'xthor' ) getNFOXthor ;; esac } function getNFO() { echo "getNFO()" BASENAME=$(basename "$FILE") if [ -f "$FILE" ]; then BASENAME="${BASENAME%.*}" DIRECTORY="$DIRNAME" echo -n "Source is a file. " regex="(.*)\/.*" if [[ $torar =~ $regex ]]; then DIRECTORY="$DIRECTORY/${BASH_REMATCH[1]}" fi else DIRECTORY="$FILE" echo -n "Source is a directory. " fi echo "going into directory $DIRECTORY" cd "$DIRECTORY" echo "BASENAME: $BASENAME" NBNFO=$(find -L . -regextype posix-extended -iregex '.*\.nfo' -type f | wc -l) echo "NBNFO: $NBNFO" if [[ $NBNFO -ge 1 ]]; then if [[ $NBNFO -eq 1 ]]; then if [ -f "$FILE" ]; then NBNFO=$(find -L . -maxdepth 1 -regextype posix-extended -iregex '.*\.nfo' -type f | wc -l) if [[ $NBNFO -eq 1 ]]; then echo "Equal to 1" NBNFO=$(find -L . -maxdepth 1 -regextype posix-extended -iregex '.*\.nfo' -type f) NFOFILE="$TEMPD/$ENCODE.nfo" cp "$NBNFO" "$NFOFILE" fi else #source is a directly NBNFO=$(find -L . -regextype posix-extended -iregex '.*\.nfo' -type f) NFOFILE="$TEMPD/$ENCODE.nfo" cp "$NBNFO" "$NFOFILE" fi else echo "More than 1" NBNFO=$(find -L . -regextype posix-extended -iregex '.*\.nfo' -type f | grep -i "$BASENAME.nfo") if [[ "$NBNFO" != "" ]]; then NFOFILE="$TEMPD/$ENCODE.nfo" cp "$NBNFO" "$NFOFILE" fi fi echo "NBNFO: $NBNFO" echo "NFOFILE: $NFOFILE" else NFOFILE="" fi if [[ $NFOFILE == "" ]]; then getTrackerNFO fi } function importNFO() { cd $NEWZNAB; if [[ "$NFOFILE" != "" ]]; then if [[ -f "$NFOFILE" && -s "$NFOFILE" ]]; then echo "importNFO" RETURN=$(/usr/bin/php5 import_nfo.php $NNID "$NFOFILE") if [[ $RETURN != "" ]]; then echo "issue when inserting NFO file: $RETURN" else echo "nfo imported successfully" fi fi fi } function processNewzNab() { echo "Processing: $TEXT"; echo "NewzNab for: $TAG"; cd $NEWZNAB; shopt -s nocasematch case "$TAG" in 'Journaux Magazines') CAT=$MAGS TAG2="JOURNAL/MAGAZINE" ;; 'Series') if [[ "$TEXT" =~ .*COMPLETE.*BLURAY.* ]]; then CAT=$TVBLURAY CAT2="TVBLURAY" elif [[ "$TEXT" =~ .*(\.| )DOC(\.| ).* ]]; then CAT=$DOC TAG2="DOC" elif [[ "$TEXT" =~ .*(\.| )E[0-9]{2,4}(\.| ).* ]]; then CAT=$ANIME TAG2="ANIME" elif [[ "$TEXT" =~ .*(\.| )(720p|1080p|2160p)(\.| ).* ]]; then if [[ "$TEXT" =~ .*(\.| )(FRENCH|MULTI)(\.| ).* ]]; then CAT=$TVHDFR TAG2="TV-HD-FR" else CAT=$TVHDVOSTFR TAG2="TV-HD-VOSTFR" fi else CAT=$TVSD TAG2="TV-SD" fi ;; 'eBooks') CAT=$EBOOKS TAG2="EBOOK" ;; 'Films') if [[ "$TEXT" =~ .*COMPLETE.*BLURAY.* ]]; then CAT=$BLURAY TAG2="BLURAY" elif [[ "$TEXT" =~ .*(\.| )(720p|1080p|2160p)(\.| ).* ]]; then CAT=$MOVIESHD TAG2="MOVIE-HD" else CAT=$MOVIESSD TAG2="MOVIE-SD" fi ;; 'Mangas') CAT=$MANGAS TAG2="MANGA" ;; 'Jeux-Windows') CAT=$GAMES TAG2="GAME" ;; 'Jeux-Linux') CAT=$GAMES TAG2="GAME" ;; 'Jeux-PC') CAT=$GAMES TAG2="GAME" ;; 'Jeux-Nintendo') CAT=$NINTENDO TAG2="NINTENDO" ;; 'Jeux-Microsoft') CAT=$MICROSOFT TAG2="MICROSOFT" ;; 'Jeux-Sony') CAT=$SONY TAG2="SONY" ;; 'Animes') CAT=$ANIME TAG2="ANIME" ;; 'Progs-Linux') CAT=$APPZ TAG2="APPZ" ;; 'Progs-Windows') CAT=$APPZ TAG2="APPZ" ;; 'Progs') CAT=$APPZ TAG2="APPZ" ;; 'Divers') if [[ "$TEXT" =~ .*(\.| )DOC(\.| ).* ]]; then CAT=$DOC TAG2="DOC" else CAT=$MISC TAG2="MISC" fi ;; 'Musique') if [[ "$TEXT" =~ .*FLAC.* ]]; then CAT=$FLAC TAG2="FLAC" else CAT=$MUSIQUE TAG2="MUSIQUE" fi ;; 'AudioBook') CAT=$EBOOKS TAG2="AUDIOBOOK" ;; 'Comics BDs') CAT=$COMICS TAG2="BD/COMICS" ;; 'XXX') CAT=$XXX ;; 'Jeux-Mac') CAT=$MAC TAG2="MAC" ;; 'Progs-Mac') CAT=$MAC TAG2="MAC" ;; 'Mac') CAT=$MAC TAG2="MAC" ;; 'Docs') CAT=$DOC TAG2="DOC" ;; 'TV-Other') CAT=$TVOTHER TAG2="TV-OTHER" ;; 'TV-Sport') CAT=$TVSPORT TAG2="TV-SPORT" ;; 'Bluray') CAT=$BLURAY TAG2="BLURAY" ;; '3D') CAT=$THREED TAG2="3D" ;; *) CAT=$MISC TAG2="MISC" ;; esac if [[ $isNfo -eq 1 ]]; then CAT=$NFO fi RESULT=$(/usr/bin/php5 import2.php $NZBTEMP true false false $CAT) NNID=$(echo "$RESULT" | grep "^¤¤" | grep -F "$TEXT" | awk -F" ¤¤ " '{ print $3 }') if [[ $NNID != "" ]]; then echo "Release $TEXT correctly inserted into newznab with ID $NNID" else echo "issue getting Newznab ID" echo "here is the log:" echo "NNID: $NNID" echo "RESULT: $RESULT" echo "END" fi if [[ $IDTOSQL == "" ]]; then IDTOSQL=$NNID else IDTOSQL="$IDTOSQL|$NNID" fi #getNFO from source directory getNFO #import NFO to newznab importNFO #delete NFO delNFOFile #send message to IRC sendToIRC } function delTorrentData() { echo "delTorrentData" echo "RTORRENTRC: $RTORRENTRC" if [[ $RTORRENTRC == *"rtorrent.specific*" ]]; then if [[ $CAT == $BLURAY ]]; then echo "running delete_torrent.sh" $HOME/scripts/delete_torrent.sh "$TORRENTHASH" "$RTORRENTRC" "$TRACKER" & fi if [[ $CAT == $TVBLURAY ]]; then echo "running delete_torrent.sh" $HOME/scripts/delete_torrent.sh "$TORRENTHASH" "$RTORRENTRC" "$TRACKER" & fi fi } function delNFOFile() { if [[ -f "$NFOFILE" ]]; then echo "delNFOFile" rm "$NFOFILE" fi } function addToSQL(){ if [[ $TKID != "" ]] && [[ $TKID != "null" ]] && [[ $IDTOSQL != "" ]]; then echo "Adding to SQL DB" echo "HASH: $TORRENTHASH" echo "Newznab IDs: $IDTOSQL" echo "Tracker: $TRACKER" echo "TKNAME: $TKNAME" echo "TKID: $TKID" SQLID=$(echo "select ID from releasestk.releases where TRACKER=\"$TRACKER\" and TKID=$TKID;" | mysql -N -h localhost -u $SQLUSER -p$SQLPASSWD) if [[ $SQLID == "" ]]; then echo "Release does not exist in DB, adding it" TKNAMEESCAPE=$(/usr/bin/php5 $HOME/scripts/escapestring.php "$TKNAME") RETURN=$(echo "INSERT INTO releasestk.releases (TRACKER, HASH, TKNAME, TKID, NNIDS) VALUES ('$TRACKER','$TORRENTHASH','$TKNAMEESCAPE','$TKID','$IDTOSQL');" | mysql -N -h localhost -u $SQLUSER -p$SQLPASSWD) if [[ $RETURN == "" ]]; then echo "Release correctly added to DB" else echo "Error when adding release to DB: \"$RETURN\"" fi else echo "Release already exists in DB, updating it" TKNAMEESCAPE=$(/usr/bin/php5 $HOME/scripts/escapestring.php "$TKNAME") RETURN=$(echo "UPDATE releasestk.releases SET HASH = '$TORRENTHASH', TKNAME = '$TKNAMEESCAPE', NNIDS = '$IDTOSQL' WHERE ID =$SQLID;" | mysql -N -h localhost -u $SQLUSER -p$SQLPASSWD) if [[ $RETURN == "" ]]; then echo "Release correctly updated to DB" else echo "Error when updating release to DB: \"$RETURN\"" fi fi fi delTorrentData } function sendToIRC(){ echo "sendToIRC" if [[ -e $WEECHAT ]] && [[ $CAT != "XXX" ]] && [[ $CAT != "NFO" ]]; then echo -e "irc.server.#chan *[$LCYAN$TAG2$RESET] $WHITE$TEXT$LBLUE added into NNDB $GREEN$NNID" > $WEECHAT fi } if [ "$TAG" == "Reseed" ]; then echo -e "Reseed: exiting" elif [ $# == 0 ]; then echo -e "Erreur: vérifie tes parametres :O" elif [ ! -e "$1" ]; then echo -e "$1 n'existe pas" elif [ -f "$1" ]; then doInit SendFile addToSQL elif [ -d "$1" ]; then doInit SendDirectory addToSQL fi