Pre processing trouble

Come up with a useful post-processing script? Share it here!
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: Help With Categories

Post by shypike »

You are using DOS/windows format files.
Shells don't like that.
Convert your script with dos2unix.
Those ^M characters are the culprits!
jowi
Newbie
Newbie
Posts: 19
Joined: August 9th, 2012, 6:16 am

Re: Help With Categories

Post by jowi »

shypike wrote:You are using DOS/windows format files.
Shells don't like that.
Convert your script with dos2unix.
Those ^M characters are the culprits!
That would mean sabnzb treats preprocessing scripts different from postprocessing scripts? Because i've created both the same way, using a Python plugin in Visual Studio and Notepad++. Both files contain the ^M after each line, but the POST processing scripts work perfectly...

But i will give it a try using the dos2unix conversion.

*edit*

Yes it works...

Code: Select all

2012-08-12 09:40:28,032::INFO::[newsunpack:1417] Running pre-queue script ['/mnt/cache/Apps/sabnzbd/scripts/pre.py', 'Breaking.Bad.S05E02.Madrigal.HDTV.x264-FQM', '', 'tvseries', '', '-100', '330523175', 'alt.binaries.multimedia alt.binaries.teevee', '', '', '', '']
2012-08-12 09:40:28,043::INFO::[newsunpack:1437] Pre-Q refuses Breaking.Bad.S05E02.Madrigal.HDTV.x264-FQM
But still, like i said, it seems sabnzb treats postprocessing scripts different from pre-processing scripts? Why? And why do my UNCONVERTED pre-scripts run on the linux command line, but not from within sabnzb?
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: Pre processing trouble

Post by shypike »

The difference is that SABnzbd processes the output of a pre-processing script,
while that of a post-proc script is simply displayed.
What happens is that it receives "0^M" instead of "0" and sees that as an invalid answer.
OK, maybe SABnzbd should do a bit more processing on this input,
but generally using DOS style scripts leads to unpredictable results (not just with SABnzbd).
Actually, I didn't think about this cause until "NoTolerance" tipped you about it.
jowi
Newbie
Newbie
Posts: 19
Joined: August 9th, 2012, 6:16 am

Re: Pre processing trouble

Post by jowi »

The difference is perhaps that the postprocessing script is being parsed to an interpreter to be processed, and the preprocessing to a (internal?) shell which output is processed? Because the output should be ok, it's the source that probably can't be processed due to the ^M's. Which is still strange to me, because i can run it from the linux command line without any problems. Anyway, it's noted. I found that VS had an option to save a source as UNIX format, and once saved that way, it will keep using the proper line termination :) Thanks!
jowi
Newbie
Newbie
Posts: 19
Joined: August 9th, 2012, 6:16 am

Re: Pre processing trouble

Post by jowi »

Ok, this works, but... it looks like sickbeard does not send all the parameters, or it is not parsed to the pre-queue script by sabnzb. I'm interested in the show, season & episode for my pre-queue process. Is this maybe some setting in sickbeard or sab i've overlooked?

If you take a look at the logging, those fields are coming in empty.
Or is this because i manually triggered sickbeard in snatching an nzb for testing this?

Code: Select all

2012-08-12 09:40:28,032::INFO::[newsunpack:1417] Running pre-queue script ['/mnt/cache/Apps/sabnzbd/scripts/pre.py', 'Breaking.Bad.S05E02.Madrigal.HDTV.x264-FQM', '', 'tvseries', '', '-100', '330523175', 'alt.binaries.multimedia alt.binaries.teevee', '', '', '', '']
2012-08-12 09:40:28,043::INFO::[newsunpack:1437] Pre-Q refuses Breaking.Bad.S05E02.Madrigal.HDTV.x264-FQM
jowi
Newbie
Newbie
Posts: 19
Joined: August 9th, 2012, 6:16 am

Re: Pre processing trouble

Post by jowi »

FYI, i've posted this question about the missing parameters on sickbeard's forum as well.
jowi
Newbie
Newbie
Posts: 19
Joined: August 9th, 2012, 6:16 am

Re: Pre processing trouble

Post by jowi »

I guess those parameters, though specified, arent used at all... ?
Also no solution from the sickbeard community. Too bad.
MrMennens
Newbie
Newbie
Posts: 3
Joined: July 3rd, 2014, 4:02 pm

Re: Pre processing trouble

Post by MrMennens »

Hi there everyone,

i know this topic hasn't had much activity lately..
but i do have a question.

I'm running Sabnzbd 0.7.16 on my Synology NAS 207+ very succesfully, but i've run in some trouble with a pre process script..

this is the script: (got it from: Mar2zz)

Code: Select all

#!/bin/sh
#
# Sabnzbd Queue Script by Mar2zz v0.2

### USAGE ###
# 
# Below are examples for changing inputparameters before the nzb enters the queue. 
# By manipulating variables with bash you can have almost complete automated control over your queue.
# Those variables need to be echoed in specific order. So, don't change the order below this.
#
###


### INPUT VARIABLES ###
# input (this is what sabnzbd feeds to this script and can be changed before the nzb hits the queue)
# All parameters (except 1) can be empty, meaning a default value.
# 1 : Name of the NZB (no path, no ".nzb")
# 2 : PP (0, 1, 2 or 3)
# 3 : Category
# 4 : Script (no path)
# 5 : Priority (-100, -1, 0 or 1 meaning Default, Low, Normal, High)
# 6 : Size of the download (in bytes)
# 7 : Group list (separated by spaces)
# 8 : Show name
# 9 : Season (1..99)
# 10 : Episode (1..99)
# 11: Episode name



##################
### ACCEPTANCE ###
##################

### Refuse or Accept script in queue
### 0=Refuse, 1=Accept
echo 1


##########################
### NZB NAME HANDLING ####
##########################

### Name of the NZB (no path, no ".nzb")
### Clean up unwanted words in nzbnames
case $3 in
   movies)
      # cleanup _ and everything after (year)
      nzb=$(echo $1 | sed -e '
               s/_/ /
               s/).*/)/
            ' )
      ;;
   *)
      # cleanup unwanted words
      nzb=(echo $1 | sed -e '
               s/.par2//
               s/.rar//
               s/.001//
               s/_/ /
	       s/[DUT]//
            ' )
      ;;
esac


#####################
#### XBMC NOTIFY ####
#####################

### If you want to be notified on snatched downloads in XBMC, please specify your xbmc credentials:
### Note: curl needs to be installed for this (sudo apt-get install curl)
xbmc_notify () {
xbmc_host=192.168.1.103 # hostname or ipaddress
xbmc_port=8080
xbmc_user=xbmc # if user is not set delete '$xbmc_user:$pass@' in url below
xbmc_pass=xbmc # if password is not set delete ':$pass@' in url below

if which curl > /dev/null
   then
   snatched=$(echo $nzb | sed -e 's/ /%20/g')
   curl -s "http://$xbmc_user@$xbmc_host:$xbmc_port/xbmcCmds/xbmcHttp/?command=ExecBuiltIn(Notification(Snatched,

$snatched))" | xargs echo > /dev/null
fi
}
xbmc_notify # comment this line if you do not want to use xbmc-notify.


#####################
#### PP HANDLING ####
#####################

# PP (0, 1, 2 or 3)
echo $2


###########################
#### CATEGORY HANDLING ####
###########################

### Set category if no category is specified
if [ -n $3 ]
   then
   case $7 in
      *movie*)
         echo films
         ;;
      *book*)
         echo ebooks
         ;;
      *teevee*)
         echo tv
         ;;
      *)
         echo $3
         ;;
   esac
else
   echo $3
fi



#########################
#### SCRIPT HANDLING ####
#########################

### Use this to set a script (No Path, just basename, e.g. sabToSickbeard.py)
echo $4


##########################
### PRIORITY HANDLING ####
##########################

### Priority (-100 -2, -1, 0 or 1, meaning Default, Paused, Low, Normal, High )

### Set priority X if it's a file from category X
case $3 in
   tv)   # <- change this to your Sickbeard category
      priority="1" 
      ;;
   couchpotato)
      priority="1"
      ;;
   *)
      priority="$5"
      ;;
esac

### Set a Size treshold for priority in bytes 
### To calculate see http://easycalculation.com/bandwidth-calculator.php (9663676416 bytes = 9 GB)
maxsize="9663676416" # <- change the number for a maximum filesize 
if [ "$6" -gt "$maxsize" ] 
   then
   priority="-1"
fi

echo $priority


########################
#### GROUP HANDLING ####
########################

### Group to be used (in case your provider doesn't carry all groups and there are multiple groups in the NZB)
echo $7
The main thing i wan't to do is add automatic categories to them when they come in my que and because i use a certain website i want to remove "[DUT]" from the nzb name, it messes up the automatic movie renamer in sabnzbd.

if i try this one whill SSH'd in my nas with putty i get the folowing error:

Code: Select all

sh Pre-Process.sh 'The.Thing.2011.German.AC3D.5.1.720p.BDRiP.XviD-icq4711'
'' '' '' '-100' '2919867029' 'alt.binaries.ath alt.binaries.dc alt.binaries.mom alt.bina
ries.nzm' '' '' '' ''
: not found.sh: line 4:
: not found.sh: line 12:
: not found.sh: line 13:
: not found.sh: line 28:
: not found.sh: line 29:
: not found.sh: line 30:
: not found.sh: line 34:
1
: not found.sh: line 38:
: not found.sh: line 39:
: not found.sh: line 43:
Pre-Process.sh: line 46: syntax error: unexpected word (expecting "in")
can someone help me or point me in the right direction!?
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: Pre processing trouble

Post by shypike »

Is the file in MSDOS format (so with CR-LF as end-of-line instead of LF)?
MrMennens
Newbie
Newbie
Posts: 3
Joined: July 3rd, 2014, 4:02 pm

Re: Pre processing trouble

Post by MrMennens »

shypike wrote:Is the file in MSDOS format (so with CR-LF as end-of-line instead of LF)?
How do i check this!?

didn't know how to check it.. but converted it with: dos2unix
now checking if it works...

edit:
Nope, stil not working.. if i try it in terminal, i get nothing back... if i try it with sab i don't get anything either..
MrMennens
Newbie
Newbie
Posts: 3
Joined: July 3rd, 2014, 4:02 pm

Re: Pre processing trouble

Post by MrMennens »

Ok, if i check the log i get this:

Code: Select all

2014-07-05 11:23:31,815::INFO::[newsunpack:1553] Running pre-queue script ['/usr/local/sabnzbd/bin/nice', '-n15', '/usr/local/sabnzbd/var/scripts/Pre-Proces$', '[DUT] Under The.Skin.2013.720p.WEB-DL.DD5.1.H264-RARBG', '', '', '', '-100', '4430069245', 'alt.binaries.moovee', '', '', '', '']
2014-07-05 11:23:44,378::INFO::[__init__:904] Saving data for totals9.sab in /usr/local/sabnzbd/var/admin/totals9.sab
2014-07-05 11:23:44,589::INFO::[assembler:87] Decoding /volume1/DL_TEMP/NZBGET_COMPLETED/incomplete/Noah (2013)/142526-2.34 yenc
2014-07-05 11:23:51,009::INFO::[newsunpack:1575] Pre-Q accepts [DUT] Under The.Skin.2013.720p.WEB-DL.DD5.1.H264-RARBG
2014-07-05 11:23:52,635::INFO::[nzbqueue:211] Saving queue
so i guess it does run.. but i don't have a categorie, or a name change...
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: Pre processing trouble

Post by shypike »

SABnzbd doesn't log what it receives back, so it might still be wrong.
If you get nothing back when you run it from a terminal, then there's an error in the script.
It must return something to work.
BTW: if a script return nothing, SABnzbd assumes that the NZB file should be accepted.

Another BTW: The script name ends with a $. I'm not sure if that's a good idea.
Mark88
Newbie
Newbie
Posts: 2
Joined: April 18th, 2015, 10:24 am

Re: Pre processing trouble

Post by Mark88 »

Code: Select all

2015-05-03 08:58:43,891::INFO::[newsunpack:1553] Running pre-queue script ['/usr/local/sabnzbd/bin/nice', '-n15', '/volume1/@appstore/sabnzbd/var/scripts/Pre-Process.py', '[DUT] Blackhat (2015) HQ AC3 DD5.1 (Externe Subs)', '', '', '', '-100', '2360073677', 'alt.binaries.boneless alt.binaries.misc', '', '', '', '', '']

2015-05-03 08:58:46,086::INFO::[newsunpack:1575] Pre-Q accepts [DUT] Blackhat (2015) HQ AC3 DD5.1 (Externe Subs)
2
This is what happens, i don't get it... this is the script: (so it should remove everything after the year and it should remove the [DUT] if i'm correct...

Code: Select all

#!/bin/sh

### INPUT VARIABLES ###

# input (this is what sabnzbd feeds to this script and can be changed before the nzb hits the queue)

# All parameters (except 1) can be empty, meaning a default value.
# 1 : Name of the NZB (no path, no ".nzb")
# 2 : PP (0, 1, 2 or 3)
# 3 : Category
# 4 : Script (no path)
# 5 : Priority (-100, -1, 0 or 1 meaning Default, Low, Normal, High)
# 6 : Size of the download (in bytes)
# 7 : Group list (separated by spaces)
# 8 : Show name
# 9 : Season (1..99)
# 10 : Episode (1..99)
# 11: Episode name



    ##################
    ### ACCEPTANCE ###
    ##################

    ### Refuse or Accept script in queue
    ### 0=Refuse, 1=Accept
   
        moviemaxsize="4294967296" #insert max movie size in binary bytes
        musicmaxsize="524288000" #insert max music size in binary bytes
        tvmaxsize="2147483648"  #insert max tv size in binary bytes
        maxsize="10737418240" #insert abosolute max nzb size in binary bytes
      
        if [ "$6" -le "$maxsize" ]
        then
                if [ $3="movies" -a "$6" -le "$moviemaxsize" ] || [ $3="music" -a "$6" -le "$musicmaxsize" ] || [ $3="tv" -a "$6" -le "$tvmaxsize" ]
                then
                accept="1"
                else
                accept="0"
                fi
        else
        accept="0"
        fi
        echo $accept

    ##########################
    ### NZB NAME HANDLING ####
    ##########################

    ### Name of the NZB (no path, no ".nzb")
    ### Clean up unwanted words in nzbnames
    case $3 in
       movies)
          # cleanup _ and everything after (year)
          nzb=$(echo $1 | sed -e '
                   s/_/ /
                   s/).*/)/
                ' )
          ;;
       *)
          # cleanup unwanted words
          nzb=$(echo $1 | sed -e '
                   s/.par2//
                   s/.rar//
                   s/.001//
                   s/[DUT]//
                   s/_/ /
                ' )
          ;;
    esac

    #####################
    #### PP HANDLING ####
    #####################

    # PP (0, 1, 2 or 3)
    echo $2


    ###########################
    #### CATEGORY HANDLING ####
    ###########################

    ### Set category if no category is specified
    if [ -n $3 ]
       then
       case $7 in
          *movie*)
             echo movies
             ;;
          *songs*)
             echo music
             ;;
          *teevee*)
             echo tv
             ;;
          *)
             echo $3
             ;;
       esac
    else
       echo $3
    fi



    #########################
    #### SCRIPT HANDLING ####
    #########################

    ### Use this to set a script (No Path, just basename, e.g. sabToSickbeard.py)
    echo $4


    ##########################
    ### PRIORITY HANDLING ####
    ##########################

    ### Priority (-100 -2, -1, 0 or 1, meaning Default, Paused, Low, Normal, High )

    ### Set priority X if it's a file from category X
    case $3 in
       tv)   # <- change this to your Sickbeard category
          priority="1"
          ;;
       couchpotato)
          priority="1"
          ;;
       *)
          priority="$5"
          ;;
    esac

    ### Set a Size treshold for priority in bytes
    ### To calculate see http://easycalculation.com/bandwidth-calculator.php (9663676416 bytes = 9 GB)
    maxsize="9663676416" # <- change the number for a maximum filesize
    if [ "$6" -gt "$maxsize" ]
       then
       priority="-1"
    fi

    echo $priority


    ########################
    #### GROUP HANDLING ####
    ########################

    ### Group to be used (in case your provider doesn't carry all groups and there are multiple groups in the NZB)
    echo $7
Post Reply