From d2593acdca013fa1db5bc5276d32d3aa96ccbcc0 Mon Sep 17 00:00:00 2001 From: Jurgen S Date: Tue, 20 Nov 2012 07:56:48 +0100 Subject: [PATCH 01/16] Changed arguments to work with NZBGet Reduced number of arguments and removed description not used arguments, set status of NZB to success --- sabToCouchPotato.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/sabToCouchPotato.py b/sabToCouchPotato.py index 4fdbfe60..ef4a4276 100644 --- a/sabToCouchPotato.py +++ b/sabToCouchPotato.py @@ -3,22 +3,18 @@ import sys import autoProcessMovie -if len(sys.argv) < 8: - print "Not enough arguments received from SABnzbd." +if len(sys.argv) < 2: + print "Not enough arguments received from NZBGet." print "Running autoProcessMovie as a manual run" autoProcessMovie.process('Manual Run', 'Manual Run', 0) else: - status = int(sys.argv[7]) + status = 0 autoProcessMovie.process(sys.argv[1], sys.argv[2], status) -# SABnzbd argv: +# NZBGet argv: # 1 The final directory of the job (full path) # 2 The original name of the NZB file -# 3 Clean version of the job name (no path info and ".nzb" removed) -# 4 Indexer's report number (if supported) -# 5 User-defined category -# 6 Group that the NZB was posted in e.g. alt.binaries.x -# 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2 +# 3 Status of post processing. 0 = OK From ecd7e3785a2a6a233976a7a44ca1700abef943ba Mon Sep 17 00:00:00 2001 From: Jurgen S Date: Tue, 20 Nov 2012 18:25:42 +0100 Subject: [PATCH 02/16] Added installation details for nzbget --- README.md | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 88df2b69..c799506e 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,26 @@ -sabToCouchPotato -================ +nzbgetToCouchPotato +=================== -Provides SABnzbd postprocessing for CouchPotatoServer +Provides NZBGet postprocessing for CouchPotatoServer, based on sabToCouchPotato from clinton-hall -Rename the file autoProcessMovie.cfg.sample to autoProcessMovie.cfg and fill in the appropriate fields as -they apply to your installation. +To get this to work with NZBGet you have to do the following: -In order to utilize failed download handling in CPS you will need to chnage the following settings in sabnzbd: -sabnzbd, config, switches, Post-Process Only Verified Jobs = Off -sabnzbd, config, special, empty_postproc = On +1) Put all the files eg. in a directory named /scripts and change the permission so nzbget can use them. +2) Add the following lines into postprocess.conf in the "PATH" section: + + # Set the full path to sabToCouchpotato.py for Couchpotato's postprocessing + SabToCouchpotato=/usr/local/nzbget/var/scripts/sabToCouchpotato.py + +3) Add the following lines into postproecess.sh right before the line "# Check if destination directory was set in postprocessing parameters" + + if [ $NZBPP_CATEGORY = "movies" -a -e "$SabToCouchpotato" ]; then + # Call Couchpotatos postprocessing script + echo "[INFO] Post-Process: Running Couchpotato's postprocessing script ($SabToCouchpotato $NZBPP_DIRECTORY $NZBPP_NZBFILENAME)" + $PythonCmd $SabToCouchpotato "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" >/dev/null 2>&1 + fi + +4)Rename the file autoProcessMovie.cfg.sample to autoProcessMovie.cfg and fill in the appropriate fields as they apply to your installation. [Notes_On_Delay] delay must be a minimum of 60 seconds for the renamer.scan to run successfully. CouchPotato @@ -34,7 +45,7 @@ sabnzbd, config, special, empty_postproc = On If you have added .py to your PATHEXT (in windows) or you have given sabToCouchPotato.py executable permissions, or you are using the compiled executables you can manually call this process outside of -sabnzbd for testing your configuration or in case a postprocessing event failed. +your nzbclient for testing your configuration or in case a postprocessing event failed. To do this, execute sabToCouchPotato.py e.g. via ssl issue the following command: #./sabToCouchPotato.py when in the directory where sabToCouchPotato.py is located. \ No newline at end of file From 454f989c1baa3562b534d56fd389820abaee8b56 Mon Sep 17 00:00:00 2001 From: Jurgen S Date: Tue, 20 Nov 2012 19:25:42 +0100 Subject: [PATCH 03/16] Revised installation details --- README.md | 100 +++++++++++++++++++++++++++--------------------------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index c799506e..e3be047f 100644 --- a/README.md +++ b/README.md @@ -1,51 +1,51 @@ -nzbgetToCouchPotato -=================== - -Provides NZBGet postprocessing for CouchPotatoServer, based on sabToCouchPotato from clinton-hall - -To get this to work with NZBGet you have to do the following: - -1) Put all the files eg. in a directory named /scripts and change the permission so nzbget can use them. - -2) Add the following lines into postprocess.conf in the "PATH" section: - - # Set the full path to sabToCouchpotato.py for Couchpotato's postprocessing - SabToCouchpotato=/usr/local/nzbget/var/scripts/sabToCouchpotato.py - -3) Add the following lines into postproecess.sh right before the line "# Check if destination directory was set in postprocessing parameters" - - if [ $NZBPP_CATEGORY = "movies" -a -e "$SabToCouchpotato" ]; then - # Call Couchpotatos postprocessing script - echo "[INFO] Post-Process: Running Couchpotato's postprocessing script ($SabToCouchpotato $NZBPP_DIRECTORY $NZBPP_NZBFILENAME)" - $PythonCmd $SabToCouchpotato "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" >/dev/null 2>&1 - fi - -4)Rename the file autoProcessMovie.cfg.sample to autoProcessMovie.cfg and fill in the appropriate fields as they apply to your installation. - -[Notes_On_Delay] - delay must be a minimum of 60 seconds for the renamer.scan to run successfully. CouchPotato - performs a test to ensure files/folder are not newer than 1 minute to prevent renaming of - files that are still extracting. - -[Notes_On_Method_renamer] - method "renamer" is the default which will cause CouchPotato to move and rename downloaded files - as specified in the CouchPotato renamer settings. - This will also add the movie to the manage list and initiate any configured notifications. - In this case SABnzbd (or your download client) must extract the files to the "from" folder - as specified in your CouchPotato renamer settings. Renamer must be enabled but you should - increase the "run every" option in CouchPotato renamer settings (advanced settings) to only - run daily (1440) or weekly (10080) or automatic scan can be disabled by setting run every =0. - -[Notes_On_Method_manage] - method "manage" will make CouchPotato update the list of managed movies if manager - is enabled but renamer is not enabled. - In this case SABnzbd (or your download client) must extract the files directly - to your final movies folder (as configured in CouchPotato manage settings) and Manage must - be enabled. - -If you have added .py to your PATHEXT (in windows) or you have given sabToCouchPotato.py executable -permissions, or you are using the compiled executables you can manually call this process outside of -your nzbclient for testing your configuration or in case a postprocessing event failed. -To do this, execute sabToCouchPotato.py -e.g. via ssl issue the following command: #./sabToCouchPotato.py +nzbgetToCouchPotato +=================== + +Provides NZBGet postprocessing for CouchPotatoServer, based on sabToCouchPotato from clinton-hall + +To get this to work with NZBGet you have to do the following: + +1) Put all the files eg. in a directory wherever you want to keep them (eg. /scripts/ in the home directory of nzbget) and change the permission accordingly so nzbget has access to this files. + +2) Add the following lines into nzbget's postprocess.conf in the "PATH" section: + + # Set the full path to sabToCouchpotato.py for Couchpotato's postprocessing + SabToCouchpotato=/usr/local/nzbget/var/scripts/sabToCouchpotato.py + +3) Add the following lines into nzbget's postprocess.sh right before the line "# Check if destination directory was set in postprocessing parameters" + + if [ $NZBPP_CATEGORY = "movies" -a -e "$SabToCouchpotato" ]; then + # Call Couchpotatos postprocessing script + echo "[INFO] Post-Process: Running Couchpotato's postprocessing script ($SabToCouchpotato $NZBPP_DIRECTORY $NZBPP_NZBFILENAME)" + $PythonCmd $SabToCouchpotato "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" >/dev/null 2>&1 + fi + +4)Rename the file autoProcessMovie.cfg.sample to autoProcessMovie.cfg and fill in the appropriate fields as they apply to your installation. + +[Notes_On_Delay] + delay must be a minimum of 60 seconds for the renamer.scan to run successfully. CouchPotato + performs a test to ensure files/folder are not newer than 1 minute to prevent renaming of + files that are still extracting. + +[Notes_On_Method_renamer] + method "renamer" is the default which will cause CouchPotato to move and rename downloaded files + as specified in the CouchPotato renamer settings. + This will also add the movie to the manage list and initiate any configured notifications. + In this case SABnzbd (or your download client) must extract the files to the "from" folder + as specified in your CouchPotato renamer settings. Renamer must be enabled but you should + increase the "run every" option in CouchPotato renamer settings (advanced settings) to only + run daily (1440) or weekly (10080) or automatic scan can be disabled by setting run every =0. + +[Notes_On_Method_manage] + method "manage" will make CouchPotato update the list of managed movies if manager + is enabled but renamer is not enabled. + In this case SABnzbd (or your download client) must extract the files directly + to your final movies folder (as configured in CouchPotato manage settings) and Manage must + be enabled. + +If you have added .py to your PATHEXT (in windows) or you have given sabToCouchPotato.py executable +permissions, or you are using the compiled executables you can manually call this process outside of +your nzbclient for testing your configuration or in case a postprocessing event failed. +To do this, execute sabToCouchPotato.py +e.g. via ssl issue the following command: #./sabToCouchPotato.py when in the directory where sabToCouchPotato.py is located. \ No newline at end of file From 8d7bea83e5f5e161c34d299b434d306057332e40 Mon Sep 17 00:00:00 2001 From: Jurgen S Date: Wed, 21 Nov 2012 00:30:54 +0100 Subject: [PATCH 04/16] corrected path --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e3be047f..bd3c2eb1 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ To get this to work with NZBGet you have to do the following: 2) Add the following lines into nzbget's postprocess.conf in the "PATH" section: # Set the full path to sabToCouchpotato.py for Couchpotato's postprocessing - SabToCouchpotato=/usr/local/nzbget/var/scripts/sabToCouchpotato.py + SabToCouchpotato=/sabToCouchpotato.py 3) Add the following lines into nzbget's postprocess.sh right before the line "# Check if destination directory was set in postprocessing parameters" From 301e889026652e5ce00095180c0a09d7d5861be1 Mon Sep 17 00:00:00 2001 From: Jurgen S Date: Sun, 25 Nov 2012 03:06:55 +0100 Subject: [PATCH 05/16] Renamed project and added installation details --- README.md | 111 ++++++++++++++++++++++++++++---------------- nzbToCouchPotato.py | 32 +++++++++++++ sabToCouchPotato.py | 20 -------- 3 files changed, 103 insertions(+), 60 deletions(-) create mode 100644 nzbToCouchPotato.py delete mode 100644 sabToCouchPotato.py diff --git a/README.md b/README.md index bd3c2eb1..6ff47da5 100644 --- a/README.md +++ b/README.md @@ -1,51 +1,82 @@ -nzbgetToCouchPotato -=================== +nzbToCouchPotato +================ -Provides NZBGet postprocessing for CouchPotatoServer, based on sabToCouchPotato from clinton-hall +Provides an efficient way to handle postprocessing for [CouchPotatoServer](https://couchpota.to/ "CouchPotatoServer") +when using one of the popular NZB download clients like [SABnzbd](http://sabnzbd.org/) and [NZBGet](http://nzbget.sourceforge.net/ "NZBGet") on low performance systems like a NAS. +This script is based on [sabToCouchPotato] (https://github.com/clinton-hall/sabToCouchPotato "sabToCouchPotato") from Clinton Hall, but extends the original script with the support for NZBGet. -To get this to work with NZBGet you have to do the following: +Introduction +------------ +My Synology DS211j was too weak to provide decent downloads rates with SABnzbd and CouchPotatoServer even by using sabToCouchPotato. +The only alternative was to switch to NZBGet which uses far less resources and helped to reach the full download speed. +But i was still unsatisfied as i could not use sabToCouchPotato anymore. +Even worse the renamer of CouchPotatoServer caused broken downloads by interfering with NZBGet while it was still unpacking the files. +In needed a solution and out of this motivation i started working on a own version of sabToCouchPotato named "nzbToCouchPotato". -1) Put all the files eg. in a directory wherever you want to keep them (eg. /scripts/ in the home directory of nzbget) and change the permission accordingly so nzbget has access to this files. +Installation +------------ +### General +1. Put all files in a directory wherever you want to keep them (eg. /scripts/ in the home directory of your nzb client) + and change the permission accordingly so the nzb client can access to this files. -2) Add the following lines into nzbget's postprocess.conf in the "PATH" section: +2. Rename the file autoProcessMovie.cfg.sample to autoProcessMovie.cfg and fill in the appropriate + fields as they apply to your installation. - # Set the full path to sabToCouchpotato.py for Couchpotato's postprocessing - SabToCouchpotato=/sabToCouchpotato.py + [Notes_On_Delay] + Delay must be a minimum of 60 seconds for the renamer.scan to run successfully. CouchPotato + performs a test to ensure files/folder are not newer than 1 minute to prevent renaming of + files that are still extracting. -3) Add the following lines into nzbget's postprocess.sh right before the line "# Check if destination directory was set in postprocessing parameters" + [Notes_On_Method_renamer] + Method "renamer" is the default which will cause CouchPotato to move and rename downloaded files + as specified in the CouchPotato renamer settings. + This will also add the movie to the manage list and initiate any configured notifications. + In this case your nzb client must extract the files to the "from" folder + as specified in your CouchPotato renamer settings. Renamer must be enabled + but automatic scan can be disabled by setting "Run Every" to "0". - if [ $NZBPP_CATEGORY = "movies" -a -e "$SabToCouchpotato" ]; then - # Call Couchpotatos postprocessing script - echo "[INFO] Post-Process: Running Couchpotato's postprocessing script ($SabToCouchpotato $NZBPP_DIRECTORY $NZBPP_NZBFILENAME)" - $PythonCmd $SabToCouchpotato "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" >/dev/null 2>&1 - fi + [Notes_On_Method_manage] + Method "manage" will make CouchPotato update the list of managed movies if manager + is enabled but renamer is not enabled. + In this case your nzb client must extract the files directly + to your final movies folder (as configured in CouchPotato manage settings) and Manage must + be enabled. -4)Rename the file autoProcessMovie.cfg.sample to autoProcessMovie.cfg and fill in the appropriate fields as they apply to your installation. +3. If you have added .py to your PATHEXT (in windows) or you have given nzbToCouchPotato.py executable + permissions, or you are using the compiled executables you can manually call this process outside of + your nzb client for testing your configuration or in case a postprocessing event failed. + To do this, execute nzbToCouchPotato.py e.g. via ssl issue the following command: + $ ./nzbToCouchPotato.py when in the directory where nzbToCouchPotato.py is located. -[Notes_On_Delay] - delay must be a minimum of 60 seconds for the renamer.scan to run successfully. CouchPotato - performs a test to ensure files/folder are not newer than 1 minute to prevent renaming of - files that are still extracting. +### SABnzbd +If you are using SABnzbd perform the following steps to configure postprocessing for "nzbToCouchPotato": -[Notes_On_Method_renamer] - method "renamer" is the default which will cause CouchPotato to move and rename downloaded files - as specified in the CouchPotato renamer settings. - This will also add the movie to the manage list and initiate any configured notifications. - In this case SABnzbd (or your download client) must extract the files to the "from" folder - as specified in your CouchPotato renamer settings. Renamer must be enabled but you should - increase the "run every" option in CouchPotato renamer settings (advanced settings) to only - run daily (1440) or weekly (10080) or automatic scan can be disabled by setting run every =0. +1. In SABnzbd go to "Config" -> "Folders", then configure in the section "User Folders" + the option "Post-Processing Scripts Folder" with the path where you keep the post-processings scripts for SABnzbd. + +2. Then go to "Config" -> "Categories" + and configure the category which you want to use for CouchPotato (eg. movies) + then select "nzbToCouchPotato.py" as the script that shall be executed after the job was finished by SABnzbd. + +3. For better handling of failed downloads in version 0.7.5 of SABnzbd a new special parameter named "empty_postproc" was introduced, + so at last go to "Config" -> "Special" in the web-interface and tick the option "empty_postproc". + + Description of this special parameter according to SABnzbd manual: + > Do post-processing and run the user script even if nothing has been downloaded. + This is useful in combination with tools like SickBeard, for which running the script on an empty or failed download is a trigger to try an alternative NZB. + Note that the "Status" parameter for the script will be -1. [0.7.5+ only] + +### NZBGet +If you are using NZBGet perform the following steps to configure postprocessing for "nzbToCouchPotato": -[Notes_On_Method_manage] - method "manage" will make CouchPotato update the list of managed movies if manager - is enabled but renamer is not enabled. - In this case SABnzbd (or your download client) must extract the files directly - to your final movies folder (as configured in CouchPotato manage settings) and Manage must - be enabled. - -If you have added .py to your PATHEXT (in windows) or you have given sabToCouchPotato.py executable -permissions, or you are using the compiled executables you can manually call this process outside of -your nzbclient for testing your configuration or in case a postprocessing event failed. -To do this, execute sabToCouchPotato.py -e.g. via ssl issue the following command: #./sabToCouchPotato.py -when in the directory where sabToCouchPotato.py is located. \ No newline at end of file +1. Replace the config files with the ones from the download below according to the version you are using (0.8.0 or 9.0): + https://github.com/downloads/thorli/nzbToCouchPotato/nzbget-postprocessing-files.zip + + These files enable additional postprocessing settings for CouchPotato (and SickBeard as well) in the NZBGet webinterface. + If NZBGet is running either restart (0.8.0) or reload (9.0) to activate the changes after you have replaced the files. + To be on the safe side, don't forget to make a backup of the existing files! + +2. In NZBGet go to "POSTPROCESSING SCRIPT" -> "PATHS" and apply the option "NzbToCouchpotato" according to your environment, + this setting configures the path where NZBGet has to look for "nzbToCouchpotato.py". + +3. Then go to "POSTPROCESSING SCRIPT" -> "OPTIONS" and set there the category which you want to use for CouchPotato post-processing. \ No newline at end of file diff --git a/nzbToCouchPotato.py b/nzbToCouchPotato.py new file mode 100644 index 00000000..1fc4cd6b --- /dev/null +++ b/nzbToCouchPotato.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python + +import sys +import autoProcessMovie + +# SABnzbd +if len(sys.argv) == 8: +# SABnzbd argv: +# 1 The final directory of the job (full path) +# 2 The original name of the NZB file +# 3 Clean version of the job name (no path info and ".nzb" removed) +# 4 Indexer's report number (if supported) +# 5 User-defined category +# 6 Group that the NZB was posted in e.g. alt.binaries.x +# 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2 + print "Script triggered from SABnzbd, starting autoProcessMovie..." + autoProcessMovie.process(sys.argv[1], sys.argv[2], sys.argv[7]) + +# NZBGet +elif len(sys.argv) == 3: +# NZBGet argv: +# 1 The final directory of the job (full path) +# 2 The original name of the NZB file +# From NZBGet only successful downloads are triggered so status is set to "0" + print "Script triggered from NZBGet, starting autoProcessMovie..." + + autoProcessMovie.process(sys.argv[1], sys.argv[2], 0) + +else: + print "Invalid number of arguments received from client." + print "Running autoProcessMovie as a manual run..." + autoProcessMovie.process('Manual Run', 'Manual Run', 0) diff --git a/sabToCouchPotato.py b/sabToCouchPotato.py deleted file mode 100644 index ef4a4276..00000000 --- a/sabToCouchPotato.py +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python - -import sys -import autoProcessMovie - -if len(sys.argv) < 2: - print "Not enough arguments received from NZBGet." - print "Running autoProcessMovie as a manual run" - autoProcessMovie.process('Manual Run', 'Manual Run', 0) -else: - status = 0 - autoProcessMovie.process(sys.argv[1], sys.argv[2], status) - - -# NZBGet argv: -# 1 The final directory of the job (full path) -# 2 The original name of the NZB file -# 3 Status of post processing. 0 = OK - - From 663947feaf9957f84ee8bda2bc3d5adc225e8a60 Mon Sep 17 00:00:00 2001 From: clinton-hall Date: Thu, 29 Nov 2012 19:00:32 -0800 Subject: [PATCH 06/16] Added more explanation and config details. --- README.md | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6ff47da5..1b3c1673 100644 --- a/README.md +++ b/README.md @@ -3,15 +3,20 @@ nzbToCouchPotato Provides an efficient way to handle postprocessing for [CouchPotatoServer](https://couchpota.to/ "CouchPotatoServer") when using one of the popular NZB download clients like [SABnzbd](http://sabnzbd.org/) and [NZBGet](http://nzbget.sourceforge.net/ "NZBGet") on low performance systems like a NAS. -This script is based on [sabToCouchPotato] (https://github.com/clinton-hall/sabToCouchPotato "sabToCouchPotato") from Clinton Hall, but extends the original script with the support for NZBGet. +This script is based on sabToSickBeard (written by Nic Wolfe and supplied with SickBeard), with the support for NZBGet being added by [thorli](https://github.com/thorli)"thorli"). Introduction ------------ -My Synology DS211j was too weak to provide decent downloads rates with SABnzbd and CouchPotatoServer even by using sabToCouchPotato. -The only alternative was to switch to NZBGet which uses far less resources and helped to reach the full download speed. -But i was still unsatisfied as i could not use sabToCouchPotato anymore. -Even worse the renamer of CouchPotatoServer caused broken downloads by interfering with NZBGet while it was still unpacking the files. -In needed a solution and out of this motivation i started working on a own version of sabToCouchPotato named "nzbToCouchPotato". +Originally this was modifed from teh SickBeard version to allow for "on-demand" renaming and not have My QNAP TS-412 NAS constantly +scanning the downlaod directory. +Later, a few failed downloads prompted me to incorporate "failed download" handling. +Failed downlaod handling is now provided for sabnzbd, by CouchPotatoServer; however on arm processors (small NAS systems) this can be un-reliable. + +thorli's Synology DS211j was too weak to provide decent downloads rates with SABnzbd and CouchPotatoServer even by using sabToCouchPotato. +The only alternative for many QNAP and Synology users is to switch to NZBGet which uses far less resources and helped to reach the full download speed. + +The renamer of CouchPotatoServer caused broken downloads by interfering with NZBGet while it was still unpacking the files. +Hence the solution was this version of sabToCouchPotato which has now been named "nzbToCouchPotato". Installation ------------ @@ -48,17 +53,38 @@ Installation To do this, execute nzbToCouchPotato.py e.g. via ssl issue the following command: $ ./nzbToCouchPotato.py when in the directory where nzbToCouchPotato.py is located. +### CouchPotatoServer +The following must be configured in CouchPotatoServer + +1. Settings -> Downloaders -> Sabnzbd (or NZBGet) + i. "Category" must be set to a category that is used by Sabnzbd/NZBGet (e.g. "movies", or "CouchPotato") + ii. "Delete Failed" should be un-ticked (Sabnzbd only) +2. Settings -> Renamer -> "Rename downloaded movies" should be checked and the settings below applied: + i. "From" must be set to the full path to your completed download movies + if you specify only "movies" here, the completed downlaods will be extracted to + %sabnzbd_completed_folder%/movies [0.7.5+ only] + ii. "To" must be set to the folder where you want your movie library to be kept. this would also usually be added to manage. + iii."Run Every" should be set to a high interval (e.g. 1440 = 24 hours) or disabled by setting "0" + iv. "Force Every" should be set to a high interval (e.g 24 hours) or disabled by setting "0" + v. "Next On_failed" should be un-ticked. + these last 3 settings are "advanced settings" so to change these you will need to select the option + "show advanced settings" on the top right of all settings pages. [0.7.5+ only] + ### SABnzbd If you are using SABnzbd perform the following steps to configure postprocessing for "nzbToCouchPotato": 1. In SABnzbd go to "Config" -> "Folders", then configure in the section "User Folders" the option "Post-Processing Scripts Folder" with the path where you keep the post-processings scripts for SABnzbd. -2. Then go to "Config" -> "Categories" - and configure the category which you want to use for CouchPotato (eg. movies) +2. Go to "Config" -> "Categories" + and configure the category which you want to use for CouchPotato (eg. "movies" as set in the CPS Downloaders settings) then select "nzbToCouchPotato.py" as the script that shall be executed after the job was finished by SABnzbd. + "Folder/Path" should be set to the location where you want your mvies extracted to (the Renamer "From" directory as set up in CPS) + +3. Go to "Config" -> "Switches" and un-tick the option "Post-Process Only Verified Jobs" + in order to allow for snatching of the next best release from CouchPotatoServer when a downlaod fails. -3. For better handling of failed downloads in version 0.7.5 of SABnzbd a new special parameter named "empty_postproc" was introduced, +4. For better handling of failed downloads in version 0.7.5 of SABnzbd a new special parameter named "empty_postproc" was introduced, so at last go to "Config" -> "Special" in the web-interface and tick the option "empty_postproc". Description of this special parameter according to SABnzbd manual: From eb1702ea43cf4fe132d9f3eae7b0e6bdef05bbfc Mon Sep 17 00:00:00 2001 From: clinton-hall Date: Thu, 29 Nov 2012 19:02:51 -0800 Subject: [PATCH 07/16] fixed some spelling and formatting --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1b3c1673..f63bf491 100644 --- a/README.md +++ b/README.md @@ -61,14 +61,14 @@ The following must be configured in CouchPotatoServer ii. "Delete Failed" should be un-ticked (Sabnzbd only) 2. Settings -> Renamer -> "Rename downloaded movies" should be checked and the settings below applied: i. "From" must be set to the full path to your completed download movies - if you specify only "movies" here, the completed downlaods will be extracted to - %sabnzbd_completed_folder%/movies [0.7.5+ only] + > If you specify only "movies" here, the completed downloads will be extracted to + %sabnzbd_completed_folder%/movies ii. "To" must be set to the folder where you want your movie library to be kept. this would also usually be added to manage. iii."Run Every" should be set to a high interval (e.g. 1440 = 24 hours) or disabled by setting "0" iv. "Force Every" should be set to a high interval (e.g 24 hours) or disabled by setting "0" v. "Next On_failed" should be un-ticked. - these last 3 settings are "advanced settings" so to change these you will need to select the option - "show advanced settings" on the top right of all settings pages. [0.7.5+ only] + > These last 3 settings are "advanced settings" so to change these you will need to select the option + "show advanced settings" on the top right of all settings pages. ### SABnzbd If you are using SABnzbd perform the following steps to configure postprocessing for "nzbToCouchPotato": From ba1ce89452cfffbd25ea17e5f7d17f15147bc7d9 Mon Sep 17 00:00:00 2001 From: clinton-hall Date: Thu, 29 Nov 2012 19:28:16 -0800 Subject: [PATCH 08/16] fixed more formatting --- README.md | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index f63bf491..683aea6d 100644 --- a/README.md +++ b/README.md @@ -7,16 +7,13 @@ This script is based on sabToSickBeard (written by Nic Wolfe and supplied with S Introduction ------------ -Originally this was modifed from teh SickBeard version to allow for "on-demand" renaming and not have My QNAP TS-412 NAS constantly -scanning the downlaod directory. +Originally this was modifed from teh SickBeard version to allow for "on-demand" renaming and not have My QNAP TS-412 NAS constantly scanning the downlaod directory. Later, a few failed downloads prompted me to incorporate "failed download" handling. -Failed downlaod handling is now provided for sabnzbd, by CouchPotatoServer; however on arm processors (small NAS systems) this can be un-reliable. +Failed downlaod handling is now provided for sabnzbd, by CouchPotatoServer; however on arm processors (e.g. small NAS systems) this can be un-reliable. -thorli's Synology DS211j was too weak to provide decent downloads rates with SABnzbd and CouchPotatoServer even by using sabToCouchPotato. -The only alternative for many QNAP and Synology users is to switch to NZBGet which uses far less resources and helped to reach the full download speed. +thorli's Synology DS211j was too weak to provide decent downloads rates with SABnzbd and CouchPotatoServer even by using sabToCouchPotato; His only alternative (as with many many QNAP and Synology users) was to switch to NZBGet which uses far less resources and helps to reach the full download speed. -The renamer of CouchPotatoServer caused broken downloads by interfering with NZBGet while it was still unpacking the files. -Hence the solution was this version of sabToCouchPotato which has now been named "nzbToCouchPotato". +The renamer of CouchPotatoServer caused broken downloads by interfering with NZBGet while it was still unpacking the files. Hence the solution was thorli's version of sabToCouchPotato which has now been named "nzbToCouchPotato". Installation ------------ @@ -54,21 +51,30 @@ Installation $ ./nzbToCouchPotato.py when in the directory where nzbToCouchPotato.py is located. ### CouchPotatoServer -The following must be configured in CouchPotatoServer + +The following must be configured in CouchPotatoServer: 1. Settings -> Downloaders -> Sabnzbd (or NZBGet) - i. "Category" must be set to a category that is used by Sabnzbd/NZBGet (e.g. "movies", or "CouchPotato") + + i. "Category" must be set to a category that is used by Sabnzbd/NZBGet (e.g. "movies", or "CouchPotato") + ii. "Delete Failed" should be un-ticked (Sabnzbd only) + 2. Settings -> Renamer -> "Rename downloaded movies" should be checked and the settings below applied: + i. "From" must be set to the full path to your completed download movies - > If you specify only "movies" here, the completed downloads will be extracted to - %sabnzbd_completed_folder%/movies + + > If you specify only "movies" here, the completed downloads will be extracted to %sabnzbd_completed_folder%/movies + ii. "To" must be set to the folder where you want your movie library to be kept. this would also usually be added to manage. + iii."Run Every" should be set to a high interval (e.g. 1440 = 24 hours) or disabled by setting "0" + iv. "Force Every" should be set to a high interval (e.g 24 hours) or disabled by setting "0" + v. "Next On_failed" should be un-ticked. - > These last 3 settings are "advanced settings" so to change these you will need to select the option - "show advanced settings" on the top right of all settings pages. + + > These last 3 settings are "advanced settings" so to change these you will need to select the option "show advanced settings" on the top right of all settings pages. ### SABnzbd If you are using SABnzbd perform the following steps to configure postprocessing for "nzbToCouchPotato": From 3a5cbe7f2b3be53405c77dd9cd2af3195e961a0a Mon Sep 17 00:00:00 2001 From: clinton-hall Date: Thu, 29 Nov 2012 19:31:06 -0800 Subject: [PATCH 09/16] more spelling - not my finest hour. --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 683aea6d..d570cbc1 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,11 @@ nzbToCouchPotato Provides an efficient way to handle postprocessing for [CouchPotatoServer](https://couchpota.to/ "CouchPotatoServer") when using one of the popular NZB download clients like [SABnzbd](http://sabnzbd.org/) and [NZBGet](http://nzbget.sourceforge.net/ "NZBGet") on low performance systems like a NAS. -This script is based on sabToSickBeard (written by Nic Wolfe and supplied with SickBeard), with the support for NZBGet being added by [thorli](https://github.com/thorli)"thorli"). +This script is based on sabToSickBeard (written by Nic Wolfe and supplied with SickBeard), with the support for NZBGet being added by [thorli](https://github.com/thorli "thorli"). Introduction ------------ -Originally this was modifed from teh SickBeard version to allow for "on-demand" renaming and not have My QNAP TS-412 NAS constantly scanning the downlaod directory. +Originally this was modifed from the SickBeard version to allow for "on-demand" renaming and not have My QNAP TS-412 NAS constantly scanning the downlaod directory. Later, a few failed downloads prompted me to incorporate "failed download" handling. Failed downlaod handling is now provided for sabnzbd, by CouchPotatoServer; however on arm processors (e.g. small NAS systems) this can be un-reliable. @@ -58,21 +58,21 @@ The following must be configured in CouchPotatoServer: i. "Category" must be set to a category that is used by Sabnzbd/NZBGet (e.g. "movies", or "CouchPotato") - ii. "Delete Failed" should be un-ticked (Sabnzbd only) + ii. "Delete Failed" should be un-ticked (Sabnzbd only) 2. Settings -> Renamer -> "Rename downloaded movies" should be checked and the settings below applied: - i. "From" must be set to the full path to your completed download movies + i. "From" must be set to the full path to your completed download movies > If you specify only "movies" here, the completed downloads will be extracted to %sabnzbd_completed_folder%/movies - ii. "To" must be set to the folder where you want your movie library to be kept. this would also usually be added to manage. + ii. "To" must be set to the folder where you want your movie library to be kept. this would also usually be added to manage. - iii."Run Every" should be set to a high interval (e.g. 1440 = 24 hours) or disabled by setting "0" + iii. "Run Every" should be set to a high interval (e.g. 1440 = 24 hours) or disabled by setting "0" - iv. "Force Every" should be set to a high interval (e.g 24 hours) or disabled by setting "0" + iv. "Force Every" should be set to a high interval (e.g 24 hours) or disabled by setting "0" - v. "Next On_failed" should be un-ticked. + v. "Next On_failed" should be un-ticked. > These last 3 settings are "advanced settings" so to change these you will need to select the option "show advanced settings" on the top right of all settings pages. From 29c2349fe33facebeee585571d790f8f15e35a2b Mon Sep 17 00:00:00 2001 From: Clinton Hall Date: Fri, 30 Nov 2012 14:06:03 +1030 Subject: [PATCH 10/16] Added NZBGet postprocess scripts As provided by thorli (Jurgen S) --- .../0.8.0/postprocess.conf.tpl | 67 ++++ .../0.8.0/postprocess.sh | 342 ++++++++++++++++++ .../9.0/bin/nzbget-postprocess.sh | 334 +++++++++++++++++ .../9.0/webui/nzbget-postprocess.conf | 87 +++++ 4 files changed, 830 insertions(+) create mode 100644 nzbget-postprocessing-files/0.8.0/postprocess.conf.tpl create mode 100644 nzbget-postprocessing-files/0.8.0/postprocess.sh create mode 100644 nzbget-postprocessing-files/9.0/bin/nzbget-postprocess.sh create mode 100644 nzbget-postprocessing-files/9.0/webui/nzbget-postprocess.conf diff --git a/nzbget-postprocessing-files/0.8.0/postprocess.conf.tpl b/nzbget-postprocessing-files/0.8.0/postprocess.conf.tpl new file mode 100644 index 00000000..3a16d1f1 --- /dev/null +++ b/nzbget-postprocessing-files/0.8.0/postprocess.conf.tpl @@ -0,0 +1,67 @@ +############################################################################## +### PATHS ### + +# Set the full path to unrar if it is not in your PATH. +UnrarCmd=unrar + +# Set the full path to python if it is not in your PATH. +PythonCmd=/usr/local/python/bin/python + +# Set the full path to sabToSickBeard.py for SickBeard's postprocessing. +SabToSickBeard=/usr/local/nzbget/var/sabToSickBeard.py + +# Set the full path to nzbToCouchpotato.py for Couchpotato's postprocessing +NzbToCouchPotato=/usr/local/nzbget/var/nzbToCouchPotato.py + + +############################################################################## +### OPTIONS ### + +# Delete rar-files after unpacking (yes, no). +DeleteRarFiles=yes + +# Temporary directory for unpacking. +ExtractedDir=extracted + +# Rename img-files to iso (yes, no). +RenameIMG=yes + +# Joint TS-files (yes, no). +JoinTS=no + +# Perform SickBeard's postprocessing (yes, no). +SickBeard=no + +# Category for SickBeard's postprocessing. +SickBeardCategory=tv + +# Perform Couchpotato's postprocessing (yes, no). +CouchPotato=yes + +# Category for Couchpotato's postprocessing (eg. movies) +CouchPotatoCategory=movies + + +############################################################################## +### POSTPROCESSING-PARAMETERS ### + +# This section defines parameters, which can be set for each nzb-file +# individually using either web-interface or command line. +# Example command line for setting parameter "password" to value "123" for +# nzb-file with id=2: +# nzbget -E G O Password=123 2 + +# Perform postprocessing (yes, no). +# +# Set to "no" to skip postprocessing for this nzb-file. +PostProcess=yes + +# Password for encrypted posts. +# +# If the post requires a password for unpacking. +Password= + +# Destination directory. +# +# NOTE: NZBGet must have write-access-rights for that directory. +DestDir= diff --git a/nzbget-postprocessing-files/0.8.0/postprocess.sh b/nzbget-postprocessing-files/0.8.0/postprocess.sh new file mode 100644 index 00000000..4fb4b287 --- /dev/null +++ b/nzbget-postprocessing-files/0.8.0/postprocess.sh @@ -0,0 +1,342 @@ +#!/bin/sh +# +# Example postprocessing script for NZBGet +# +# Copyright (C) 2008 Peter Roubos +# Copyright (C) 2008 Otmar Werner +# Copyright (C) 2008-2009 Andrei Prygounkov +# Copyright (C) 2012 Antoine Bertin +# Copyright (C) 2012 Jürgen Seif +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# + +####################### Usage instructions ####################### +# o Script will unrar downloaded rar files, join ts-files and rename img-files +# to iso. +# +# o To use this script with nzbget set the option "PostProcess" in +# nzbget configuration file to point to this script file. E.g.: +# PostProcess=/home/user/nzbget/nzbget-postprocess.sh +# +# o The script needs a configuration file. An example configuration file +# is provided in file "postprocess-example.conf". Put the configuration file +# into the directory where nzbget's configuration file (nzbget.conf) or where +# this script itself is located. Then edit the configuration file in any +# text editor to adjust the settings. +# +# o You can also edit the script's configuration via web-interface (requires +# NZBGetWeb 1.4 or later). Set the options "PostProcessConfigFile" and +# "PostProcessConfigTemplate" to point to "postprocess-example.conf" +# (including full path). The both options are under the section +# "CONFIGURATION OF POSTPROCESSING-SCRIPT" in NZBGetWeb. +# +# o There are few options, which can be ajdusted for each nzb-file +# individually. To view/edit them in web-interface click on a spanner icon +# near the name of nzb-file. +# +# o The script supports the feature called "delayed par-check". +# That means it can try to unpack downloaded files without par-checking +# them fisrt. Only if unpack fails, the script schedules par-check, +# then unpacks again. +# To use delayed par-check set following options in nzbget configuration file: +# ParCheck=no +# ParRepair=yes +# LoadPars=one (or) LoadPars=all +# +# o If you want to par-check/repair all files before trying to unpack them, +# set option "ParCheck=yes". +# +####################### End of Usage instructions ####################### + + + +# NZBGet passes following arguments to postprocess-programm as environment +# variables: +# NZBPP_DIRECTORY - path to destination dir for downloaded files; +# NZBPP_NZBFILENAME - name of processed nzb-file; +# NZBPP_PARFILENAME - name of par-file or empty string (if no collections were +# found); +# NZBPP_PARSTATUS - result of par-check: +# 0 = not checked: par-check disabled or nzb-file does +# not contain any par-files; +# 1 = checked and failed to repair; +# 2 = checked and successfully repaired; +# 3 = checked and can be repaired but repair is disabled; +# NZBPP_NZBCOMPLETED - state of nzb-job: +# 0 = there are more collections in this nzb-file queued; +# 1 = this was the last collection in nzb-file; +# NZBPP_PARFAILED - indication of failed par-jobs for current nzb-file: +# 0 = no failed par-jobs; +# 1 = current par-job or any of the previous par-jobs for +# the same nzb-files failed; +# NZBPP_CATEGORY - category assigned to nzb-file (can be empty string). + + +# Name of script's configuration file +SCRIPT_CONFIG_FILE="postprocess.conf" + +# Exit codes +POSTPROCESS_PARCHECK_CURRENT=91 +POSTPROCESS_PARCHECK_ALL=92 +POSTPROCESS_SUCCESS=93 +POSTPROCESS_ERROR=94 +POSTPROCESS_NONE=95 + + +# Check if the script is called from nzbget +if [ "$NZBPP_DIRECTORY" = "" -o "$NZBOP_CONFIGFILE" = "" ]; then + echo "*** NZBGet post-process script ***" + echo "This script is supposed to be called from nzbget (0.7.0 or later)." + exit $POSTPROCESS_ERROR +fi + +# Check if postprocessing was disabled in postprocessing parameters +# (for current nzb-file) via web-interface or via command line with +# "nzbget -E G O PostProcess=no " +if [ "$NZBPR_PostProcess" = "no" ]; then + echo "[WARNING] Post-Process: Postprocessing disabled for this nzb-file, exiting" + exit $POSTPROCESS_NONE +fi + +echo "[INFO] Post-Process: Post-process script successfully started" + +# Determine the location of configuration file (it must be stored in +# the directory with nzbget.conf or in this script's directory). +ConfigDir="${NZBOP_CONFIGFILE%/*}" +ScriptConfigFile="$ConfigDir/$SCRIPT_CONFIG_FILE" +if [ ! -f "$ScriptConfigFile" ]; then + ConfigDir="${0%/*}" + ScriptConfigFile="$ConfigDir/$SCRIPT_CONFIG_FILE" +fi +if [ ! -f "$ScriptConfigFile" ]; then + echo "[ERROR] Post-Process: Configuration file $ScriptConfigFile not found, exiting" + exit $POSTPROCESS_ERROR +fi + +# Readg configuration file +while read line; do eval "$line"; done < $ScriptConfigFile + +# Check nzbget.conf options +BadConfig=0 + +if [ "$NZBOP_ALLOWREPROCESS" = "yes" ]; then + echo "[ERROR] Post-Process: Please disable option \"AllowReProcess\" in nzbget configuration file" + BadConfig=1 +fi + +if [ "$NZBOP_LOADPARS" = "none" ]; then + echo "[ERROR] Post-Process: Please set option \"LoadPars\" to \"One\" or \"All\" in nzbget configuration file" + BadConfig=1 +fi + +if [ "$NZBOP_PARREPAIR" = "no" ]; then + echo "[ERROR] Post-Process: Please set option \"ParRepair\" to \"Yes\" in nzbget configuration file" + BadConfig=1 +fi + +if [ "$BadConfig" -eq 1 ]; then + echo "[ERROR] Post-Process: Existing because of not compatible nzbget configuration" + exit $POSTPROCESS_ERROR +fi + +# Check if all collections in nzb-file were downloaded +if [ ! "$NZBPP_NZBCOMPLETED" -eq 1 ]; then + echo "[INFO] Post-Process: Not the last collection in nzb-file, exiting" + exit $POSTPROCESS_SUCCESS +fi + +# Check par status +if [ "$NZBPP_PARSTATUS" -eq 1 -o "$NZBPP_PARSTATUS" -eq 3 -o "$NZBPP_PARFAILED" -eq 1 ]; then + if [ "$NZBPP_PARSTATUS" -eq 3 ]; then + echo "[WARNING] Post-Process: Par-check successful, but Par-repair disabled, exiting" + else + echo "[WARNING] Post-Process: Par-check failed, exiting" + fi + exit $POSTPROCESS_ERROR +fi + +# Check if destination directory exists (important for reprocessing of history items) +if [ ! -d "$NZBPP_DIRECTORY" ]; then + echo "[ERROR] Post-Process: Nothing to post-process: destination directory $NZBPP_DIRECTORY doesn't exist" + exit $POSTPROCESS_ERROR +fi + +cd "$NZBPP_DIRECTORY" + +# If not just repaired and file "_brokenlog.txt" exists, the collection is damaged +# exiting with returning code $POSTPROCESS_PARCHECK_ALL to request par-repair +if [ ! "$NZBPP_PARSTATUS" -eq 2 ]; then + if [ -f "_brokenlog.txt" ]; then + if (ls *.[pP][aA][rR]2 >/dev/null 2>&1); then + echo "[INFO] Post-Process: Brokenlog found, requesting par-repair" + exit $POSTPROCESS_PARCHECK_ALL + fi + fi +fi + +# All checks done, now processing the files + +# Flag indicates that something was unrared +Unrared=0 + +# Unrar the files (if any) to the temporary directory, if there are no rar files this will do nothing +if (ls *.rar >/dev/null 2>&1); then + + # Check if unrar exists + $UnrarCmd >/dev/null 2>&1 + if [ "$?" -eq 127 ]; then + echo "[ERROR] Post-Process: Unrar not found. Set the path to unrar in script's configuration" + exit $POSTPROCESS_ERROR + fi + + # Make a temporary directory to store the unrarred files + ExtractedDirExists=0 + if [ -d $ExtractedDir ]; then + ExtractedDirExists=1 + else + mkdir $ExtractedDir + fi + + echo "[INFO] Post-Process: Unraring" + rarpasswordparam="" + if [ "$NZBPR_Password" != "" ]; then + rarpasswordparam="-p$NZBPR_Password" + fi + + $UnrarCmd x -y -p- "$rarpasswordparam" -o+ "*.rar" ./$ExtractedDir/ + if [ "$?" -eq 3 ]; then + echo "[ERROR] Post-Process: Unrar failed" + if [ "$ExtractedDirExists" -eq 0 ]; then + rm -R $ExtractedDir + fi + # for delayed par-check/-repair at least one par-file must be already downloaded + if (ls *.[pP][aA][rR]2 >/dev/null 2>&1); then + echo "[INFO] Post-Process: Requesting par-repair" + exit $POSTPROCESS_PARCHECK_ALL + fi + exit $POSTPROCESS_ERROR + fi + Unrared=1 + + # Remove the rar files + if [ "$DeleteRarFiles" = "yes" ]; then + echo "[INFO] Post-Process: Deleting rar-files" + rm *.r[0-9][0-9] >/dev/null 2>&1 + rm *.rar >/dev/null 2>&1 + rm *.s[0-9][0-9] >/dev/null 2>&1 + fi + + # Go to the temp directory and try to unrar again. + # If there are any rars inside the extracted rars then these will no also be unrarred + cd $ExtractedDir + if (ls *.rar >/dev/null 2>&1); then + echo "[INFO] Post-Process: Unraring (second pass)" + $UnrarCmd x -y -p- -o+ "*.rar" + + if [ "$?" -eq 3 ]; then + echo "[INFO] Post-Process: Unrar (second pass) failed" + exit $POSTPROCESS_ERROR + fi + + # Delete the Rar files + if [ "$DeleteRarFiles" = "yes" ]; then + echo "[INFO] Post-Process: Deleting rar-files (second pass)" + rm *.r[0-9][0-9] >/dev/null 2>&1 + rm *.rar >/dev/null 2>&1 + rm *.s[0-9][0-9] >/dev/null 2>&1 + fi + fi + + # Move everything back to the Download folder + mv * .. + cd .. + rmdir $ExtractedDir +fi + +# If download contains only nzb-files move them into nzb-directory +# for further download +# Check if command "wc" exists +wc -l . >/dev/null 2>&1 +if [ "$?" -ne 127 ]; then + AllFilesCount=`ls -1 2>/dev/null | wc -l` + NZBFilesCount=`ls -1 *.nzb 2>/dev/null | wc -l` + if [ "$AllFilesCount" -eq "$NZBFilesCount" ]; then + echo "[INFO] Moving downloaded nzb-files into incoming nzb-directory for further download" + mv *.nzb $NZBOP_NZBDIR + fi +fi + +# Clean up +echo "[INFO] Post-Process: Cleaning up" +chmod -R a+rw . +rm *.nzb >/dev/null 2>&1 +rm *.sfv >/dev/null 2>&1 +rm *.1 >/dev/null 2>&1 +rm _brokenlog.txt >/dev/null 2>&1 +if [ "$Unrared" -eq 1 ]; then + # Delete par2-file only if there were files for unpacking. + rm *.[pP][aA][rR]2 >/dev/null 2>&1 +fi + +if [ "$JoinTS" = "yes" ]; then + # Join any split .ts files if they are named xxxx.0000.ts xxxx.0001.ts + # They will be joined together to a file called xxxx.0001.ts + if (ls *.ts >/dev/null 2>&1); then + echo "[INFO] Post-Process: Joining ts-files" + tsname=`find . -name "*0001.ts" |awk -F/ '{print $NF}'` + cat *0???.ts > ./$tsname + fi + + # Remove all the split .ts files + echo "[INFO] Post-Process: Deleting source ts-files" + rm *0???.ts >/dev/null 2>&1 +fi + +if [ "$RenameIMG" = "yes" ]; then + # Rename img file to iso + # It will be renamed to .img.iso so you can see that it has been renamed + if (ls *.img >/dev/null 2>&1); then + echo "[INFO] Post-Process: Renaming img-files to iso" + imgname=`find . -name "*.img" |awk -F/ '{print $NF}'` + mv $imgname $imgname.iso + fi +fi + +if [ "$SickBeard" = "yes" -a "$NZBPP_CATEGORY" = "$SickBeardCategory" -a -e "$SabToSickBeard" ]; then + # Call SickBeard's postprocessing script + echo "[INFO] Post-Process: Running SickBeard's postprocessing script" + $PythonCmd $SabToSickBeard "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" >/dev/null 2>&1 +fi + +if [ "$CouchPotato" = "yes" -a "$NZBPP_CATEGORY" = "$CouchPotatoCategory" -a -e "$NzbToCouchPotato" ]; then + # Call Couchpotato's postprocessing script + echo "[INFO] Post-Process: Running CouchPotato's postprocessing script" + $PythonCmd $NzbToCouchPotato "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" >/dev/null 2>&1 +fi + +# Check if destination directory was set in postprocessing parameters +# (for current nzb-file) via web-interface or via command line with +# "nzbget -E G O DestDir=/new/path " +if [ "$NZBPR_DestDir" != "" ]; then + mkdir $NZBPR_DestDir + mv * $NZBPR_DestDir >/dev/null 2>&1 + cd .. + rmdir $NZBPP_DIRECTORY +fi + +# All OK, requesting cleaning up of download queue +exit $POSTPROCESS_SUCCESS diff --git a/nzbget-postprocessing-files/9.0/bin/nzbget-postprocess.sh b/nzbget-postprocessing-files/9.0/bin/nzbget-postprocess.sh new file mode 100644 index 00000000..5394ad2f --- /dev/null +++ b/nzbget-postprocessing-files/9.0/bin/nzbget-postprocess.sh @@ -0,0 +1,334 @@ +#!/bin/sh +# +# This file if part of nzbget +# +# Example postprocessing script for NZBGet +# +# Copyright (C) 2008 Peter Roubos +# Copyright (C) 2008 Otmar Werner +# Copyright (C) 2008-2012 Andrey Prygunkov +# Copyright (C) 2012 Jürgen Seif +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# + +####################### Usage instructions ####################### +# o Script will unrar downloaded rar files, join ts-files and rename img-files +# to iso. +# +# o To use this script with nzbget set the option "PostProcess" in +# nzbget configuration file to point to this script file. E.g.: +# PostProcess=/home/user/nzbget/nzbget-postprocess.sh +# +# o The script needs a configuration file. An example configuration file +# is provided in file "nzbget-postprocess.conf". Put the configuration file +# into the directory where nzbget's configuration file (nzbget.conf) is located. +# Then edit the configuration file in any text editor to adjust the settings. +# +# o You can also edit the script's configuration via web-interface. +# +# o There are few options, which can be ajdusted for each nzb-file individually. +# +# o The script supports the feature called "delayed par-check". +# That means it can try to unpack downloaded files without par-checking +# them fisrt. Only if unpack fails, the script schedules par-check, +# then unpacks again. +# To use delayed par-check set following options in nzbget configuration file: +# ParCheck=no +# ParRepair=yes +# LoadPars=one (or) LoadPars=all +# +# o If you want to par-check/repair all files before trying to unpack them, +# set option "ParCheck=yes". +# +####################### End of Usage instructions ####################### + + +# NZBGet passes following arguments to postprocess-programm as environment +# variables: +# NZBPP_DIRECTORY - path to destination dir for downloaded files; +# NZBPP_NZBFILENAME - name of processed nzb-file; +# NZBPP_PARFILENAME - name of par-file or empty string (if no collections were +# found); +# NZBPP_PARSTATUS - result of par-check: +# 0 = not checked: par-check disabled or nzb-file does +# not contain any par-files; +# 1 = checked and failed to repair; +# 2 = checked and successfully repaired; +# 3 = checked and can be repaired but repair is disabled; +# NZBPP_NZBCOMPLETED - state of nzb-job: +# 0 = there are more collections in this nzb-file queued; +# 1 = this was the last collection in nzb-file; +# NZBPP_PARFAILED - indication of failed par-jobs for current nzb-file: +# 0 = no failed par-jobs; +# 1 = current par-job or any of the previous par-jobs for +# the same nzb-files failed; +# NZBPP_CATEGORY - category assigned to nzb-file (can be empty string). + + +# Name of script's configuration file +SCRIPT_CONFIG_FILE="nzbget-postprocess.conf" + +# Exit codes +POSTPROCESS_PARCHECK_CURRENT=91 +POSTPROCESS_PARCHECK_ALL=92 +POSTPROCESS_SUCCESS=93 +POSTPROCESS_ERROR=94 +POSTPROCESS_NONE=95 + +# Check if the script is called from nzbget +if [ "$NZBPP_DIRECTORY" = "" -o "$NZBOP_CONFIGFILE" = "" ]; then + echo "*** NZBGet post-process script ***" + echo "This script is supposed to be called from nzbget (0.7.0 or later)." + exit $POSTPROCESS_ERROR +fi + +# Check if postprocessing was disabled in postprocessing parameters +# (for current nzb-file) via web-interface or via command line with +# "nzbget -E G O PostProcess=no " +if [ "$NZBPR_PostProcess" = "no" ]; then + echo "[WARNING] Post-Process: Postprocessing disabled for this nzb-file, exiting" + exit $POSTPROCESS_NONE +fi + +echo "[INFO] Post-Process: Post-process script successfully started" + +# Determine the location of configuration file (it must be stored in +# the directory with nzbget.conf or in this script's directory). +ConfigDir="${NZBOP_CONFIGFILE%/*}" +ScriptConfigFile="$ConfigDir/$SCRIPT_CONFIG_FILE" +if [ ! -f "$ScriptConfigFile" ]; then + ConfigDir="${0%/*}" + ScriptConfigFile="$ConfigDir/$SCRIPT_CONFIG_FILE" +fi +if [ ! -f "$ScriptConfigFile" ]; then + echo "[ERROR] Post-Process: Configuration file $ScriptConfigFile not found, exiting" + exit $POSTPROCESS_ERROR +fi + +# Readg configuration file +while read line; do eval "$line"; done < $ScriptConfigFile + +# Check nzbget.conf options +BadConfig=0 + +if [ "$NZBOP_ALLOWREPROCESS" = "yes" ]; then + echo "[ERROR] Post-Process: Please disable option \"AllowReProcess\" in nzbget configuration file" + BadConfig=1 +fi + +if [ "$NZBOP_LOADPARS" = "none" ]; then + echo "[ERROR] Post-Process: Please set option \"LoadPars\" to \"One\" or \"All\" in nzbget configuration file" + BadConfig=1 +fi + +if [ "$NZBOP_PARREPAIR" = "no" ]; then + echo "[ERROR] Post-Process: Please set option \"ParRepair\" to \"Yes\" in nzbget configuration file" + BadConfig=1 +fi + +if [ "$BadConfig" -eq 1 ]; then + echo "[ERROR] Post-Process: Exiting because of not compatible nzbget configuration" + exit $POSTPROCESS_ERROR +fi + +# Check if all collections in nzb-file were downloaded +if [ ! "$NZBPP_NZBCOMPLETED" -eq 1 ]; then + echo "[INFO] Post-Process: Not the last collection in nzb-file, exiting" + exit $POSTPROCESS_SUCCESS +fi + +# Check par status +if [ "$NZBPP_PARSTATUS" -eq 1 -o "$NZBPP_PARSTATUS" -eq 3 -o "$NZBPP_PARFAILED" -eq 1 ]; then + if [ "$NZBPP_PARSTATUS" -eq 3 ]; then + echo "[WARNING] Post-Process: Par-check successful, but Par-repair disabled, exiting" + else + echo "[WARNING] Post-Process: Par-check failed, exiting" + fi + exit $POSTPROCESS_ERROR +fi + +# Check if destination directory exists (important for reprocessing of history items) +if [ ! -d "$NZBPP_DIRECTORY" ]; then + echo "[ERROR] Post-Process: Nothing to post-process: destination directory $NZBPP_DIRECTORY doesn't exist" + exit $POSTPROCESS_ERROR +fi + +cd "$NZBPP_DIRECTORY" + +# If not just repaired and file "_brokenlog.txt" exists, the collection is damaged +# exiting with returning code $POSTPROCESS_PARCHECK_ALL to request par-repair +if [ ! "$NZBPP_PARSTATUS" -eq 2 ]; then + if [ -f "_brokenlog.txt" ]; then + if (ls *.[pP][aA][rR]2 >/dev/null 2>&1); then + echo "[INFO] Post-Process: Brokenlog found, requesting par-repair" + exit $POSTPROCESS_PARCHECK_ALL + fi + fi +fi + +# All checks done, now processing the files + +# Flag indicates that something was unrared +Unrared=0 + +# Unrar the files (if any) to the temporary directory, if there are no rar files this will do nothing +if (ls *.rar >/dev/null 2>&1); then + + # Check if unrar exists + $UnrarCmd >/dev/null 2>&1 + if [ "$?" -eq 127 ]; then + echo "[ERROR] Post-Process: Unrar not found. Set the path to unrar in script's configuration" + exit $POSTPROCESS_ERROR + fi + + # Make a temporary directory to store the unrarred files + ExtractedDirExists=0 + if [ -d extracted ]; then + ExtractedDirExists=1 + else + mkdir extracted + fi + + echo "[INFO] Post-Process: Unraring" + rarpasswordparam="" + if [ "$NZBPR_Password" != "" ]; then + rarpasswordparam="-p$NZBPR_Password" + fi + + $UnrarCmd x -y -p- "$rarpasswordparam" -o+ "*.rar" ./extracted/ + if [ "$?" -ne 0 ]; then + echo "[ERROR] Post-Process: Unrar failed" + if [ "$ExtractedDirExists" -eq 0 ]; then + rm -R extracted + fi + # for delayed par-check/-repair at least one par-file must be already downloaded + if (ls *.[pP][aA][rR]2 >/dev/null 2>&1); then + echo "[INFO] Post-Process: Requesting par-repair" + exit $POSTPROCESS_PARCHECK_ALL + fi + exit $POSTPROCESS_ERROR + fi + Unrared=1 + + # Remove the rar files + if [ "$DeleteRarFiles" = "yes" ]; then + echo "[INFO] Post-Process: Deleting rar-files" + rm *.r[0-9][0-9] >/dev/null 2>&1 + rm *.rar >/dev/null 2>&1 + rm *.s[0-9][0-9] >/dev/null 2>&1 + fi + + # Go to the temp directory and try to unrar again. + # If there are any rars inside the extracted rars then these will no also be unrarred + cd extracted + if (ls *.rar >/dev/null 2>&1); then + echo "[INFO] Post-Process: Unraring (second pass)" + $UnrarCmd x -y -p- -o+ "*.rar" + + if [ "$?" -ne 0 ]; then + echo "[INFO] Post-Process: Unrar (second pass) failed" + exit $POSTPROCESS_ERROR + fi + + # Delete the Rar files + if [ "$DeleteRarFiles" = "yes" ]; then + echo "[INFO] Post-Process: Deleting rar-files (second pass)" + rm *.r[0-9][0-9] >/dev/null 2>&1 + rm *.rar >/dev/null 2>&1 + rm *.s[0-9][0-9] >/dev/null 2>&1 + fi + fi + + # Move everything back to the Download folder + mv * .. + cd .. + rmdir extracted +fi + +# If download contains only nzb-files move them into nzb-directory +# for further download +# Check if command "wc" exists +wc -l . >/dev/null 2>&1 +if [ "$?" -ne 127 ]; then + AllFilesCount=`ls -1 2>/dev/null | wc -l` + NZBFilesCount=`ls -1 *.nzb 2>/dev/null | wc -l` + if [ "$AllFilesCount" -eq "$NZBFilesCount" ]; then + echo "[INFO] Moving downloaded nzb-files into incoming nzb-directory for further download" + mv *.nzb $NZBOP_NZBDIR + fi +fi + +# Clean up +echo "[INFO] Post-Process: Cleaning up" +chmod -R a+rw . +rm *.nzb >/dev/null 2>&1 +rm *.sfv >/dev/null 2>&1 +rm *.1 >/dev/null 2>&1 +rm _brokenlog.txt >/dev/null 2>&1 +if [ "$Unrared" -eq 1 ]; then + # Delete par2-file only if there were files for unpacking. + rm *.[pP][aA][rR]2 >/dev/null 2>&1 +fi + +if [ "$JoinTS" = "yes" ]; then + # Join any split .ts files if they are named xxxx.0000.ts xxxx.0001.ts + # They will be joined together to a file called xxxx.0001.ts + if (ls *.ts >/dev/null 2>&1); then + echo "[INFO] Post-Process: Joining ts-files" + tsname=`find . -name "*0001.ts" |awk -F/ '{print $NF}'` + cat *0???.ts > ./$tsname + fi + + # Remove all the split .ts files + echo "[INFO] Post-Process: Deleting source ts-files" + rm *0???.ts >/dev/null 2>&1 +fi + +if [ "$RenameIMG" = "yes" ]; then + # Rename img file to iso + # It will be renamed to .img.iso so you can see that it has been renamed + if (ls *.img >/dev/null 2>&1); then + echo "[INFO] Post-Process: Renaming img-files to iso" + imgname=`find . -name "*.img" |awk -F/ '{print $NF}'` + mv $imgname $imgname.iso + fi +fi + +if [ "$SickBeard" = "yes" -a "$NZBPP_CATEGORY" = "$SickBeardCategory" -a -e "$SabToSickBeard" ]; then + # Call SickBeard's postprocessing script + echo "[INFO] Post-Process: Running SickBeard's postprocessing script" + $PythonCmd $SabToSickBeard "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" >/dev/null 2>&1 +fi + +if [ "$CouchPotato" = "yes" -a "$NZBPP_CATEGORY" = "$CouchPotatoCategory" -a -e "$NzbToCouchPotato" ]; then + # Call Couchpotato's postprocessing script + echo "[INFO] Post-Process: Running CouchPotato's postprocessing script" + $PythonCmd $NzbToCouchPotato "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" >/dev/null 2>&1 +fi + +# Check if destination directory was set in postprocessing parameters +# (for current nzb-file) via web-interface or via command line with +# "nzbget -E G O DestDir=/new/path " +if [ "$NZBPR_DestDir" != "" ]; then + mkdir $NZBPR_DestDir + mv * $NZBPR_DestDir >/dev/null 2>&1 + cd .. + rmdir $NZBPP_DIRECTORY +fi + +# All OK, requesting cleaning up of download queue +exit $POSTPROCESS_SUCCESS diff --git a/nzbget-postprocessing-files/9.0/webui/nzbget-postprocess.conf b/nzbget-postprocessing-files/9.0/webui/nzbget-postprocess.conf new file mode 100644 index 00000000..e7f31701 --- /dev/null +++ b/nzbget-postprocessing-files/9.0/webui/nzbget-postprocess.conf @@ -0,0 +1,87 @@ +# +# This file if part of nzbget +# +# Template configuration file for postprocessing script "nzbget-postprocess.sh". +# Please refer to "nzbget-postprocess.sh" for usage instructions. +# +# Copyright (C) 2008-2012 Andrey Prygunkov +# Copyright (C) 2012 Jürgen Seif +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# + +############################################################################## +### PATHS ### + +# Set the full path to unrar if it is not in your PATH. +UnrarCmd=unrar + +# Set the full path to python if it is not in your PATH. +PythonCmd=/usr/local/python/bin/python + +# Set the full path to sabToSickBeard.py for SickBeard's postprocessing. +SabToSickBeard=/opt/share/nzbget/scripts/sabToSickBeard.py + +# Set the full path to nzbToCouchpotato.py for Couchpotato's postprocessing +NzbToCouchPotato=/opt/share/nzbget/scripts/nzbToCouchPotato.py + +############################################################################## +### OPTIONS ### + +# Delete rar-files after unpacking (yes, no). +DeleteRarFiles=yes + +# Rename img-files to iso (yes, no). +RenameIMG=yes + +# Joint TS-files (yes, no). +JoinTS=no + +# Perform SickBeard's postprocessing (yes, no). +SickBeard=yes + +# Category for SickBeard's postprocessing. +SickBeardCategory=tv + +# Perform Couchpotato's postprocessing (yes, no). +CouchPotato=yes + +# Category for Couchpotato's postprocessing. +CouchPotatoCategory=movies + +############################################################################## +### POSTPROCESSING-PARAMETERS ### + +# This section defines parameters, which can be set for each nzb-file +# individually using either web-interface or command line. +# Example command line for setting parameter "password" to value "123" for +# nzb-file with id=2: +# nzbget -E G O Password=123 2 + +# Perform postprocessing (yes, no). +# +# Set to "no" to skip postprocessing for this nzb-file. +PostProcess=yes + +# Password for encrypted posts. +# +# If the post requires a password for unpacking. +Password= + +# Destination directory. +# +# NOTE: NZBGet must have write-access-rights for that directory. +DestDir= From 242c95ad5eb176e58faa387aa0b84c0476791239 Mon Sep 17 00:00:00 2001 From: clinton-hall Date: Thu, 29 Nov 2012 19:39:46 -0800 Subject: [PATCH 11/16] removed link to NZBGet PP files. --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index d570cbc1..bda762d6 100644 --- a/README.md +++ b/README.md @@ -101,8 +101,7 @@ If you are using SABnzbd perform the following steps to configure postprocessing ### NZBGet If you are using NZBGet perform the following steps to configure postprocessing for "nzbToCouchPotato": -1. Replace the config files with the ones from the download below according to the version you are using (0.8.0 or 9.0): - https://github.com/downloads/thorli/nzbToCouchPotato/nzbget-postprocessing-files.zip +1. Replace the config files with the ones from the included "nzbget-postprocessing-files" according to the version you are using (0.8.0 or 9.0): These files enable additional postprocessing settings for CouchPotato (and SickBeard as well) in the NZBGet webinterface. If NZBGet is running either restart (0.8.0) or reload (9.0) to activate the changes after you have replaced the files. From 23fbe0bbc995fa80ac6f6532521f3dc14bc4e672 Mon Sep 17 00:00:00 2001 From: Clinton Hall Date: Fri, 30 Nov 2012 15:54:20 +1030 Subject: [PATCH 12/16] Added Customizable Extarct Directories As provided by schumi2004 (on QNAP forums), modified by hugbug (on SourceForge) and then edited here to allow writing of the parameters to the .conf files. --- ...{postprocess.conf.tpl => postprocess.conf} | 10 +- .../0.8.0/postprocess.sh | 720 +++++++++--------- .../9.0/bin/nzbget-postprocess.sh | 712 +++++++++-------- .../9.0/webui/nzbget-postprocess.conf | 12 +- 4 files changed, 775 insertions(+), 679 deletions(-) rename nzbget-postprocessing-files/0.8.0/{postprocess.conf.tpl => postprocess.conf} (84%) diff --git a/nzbget-postprocessing-files/0.8.0/postprocess.conf.tpl b/nzbget-postprocessing-files/0.8.0/postprocess.conf similarity index 84% rename from nzbget-postprocessing-files/0.8.0/postprocess.conf.tpl rename to nzbget-postprocessing-files/0.8.0/postprocess.conf index 3a16d1f1..e6111267 100644 --- a/nzbget-postprocessing-files/0.8.0/postprocess.conf.tpl +++ b/nzbget-postprocessing-files/0.8.0/postprocess.conf @@ -8,10 +8,18 @@ UnrarCmd=unrar PythonCmd=/usr/local/python/bin/python # Set the full path to sabToSickBeard.py for SickBeard's postprocessing. -SabToSickBeard=/usr/local/nzbget/var/sabToSickBeard.py +NzbToSickBeard=/usr/local/nzbget/var/nzbToSickBeard.py + +# Set the full path where completed movies should be placed +# before CouchPotato's Renamer is called +TV_DL_DIR=/usr/local/nzbget/complete/tv # Set the full path to nzbToCouchpotato.py for Couchpotato's postprocessing NzbToCouchPotato=/usr/local/nzbget/var/nzbToCouchPotato.py + +# Set the full path where completed movies should be placed +# before CouchPotato's Renamer is called +MOVIES_DL_DIR=/usr/local/nzbget/complete/movies ############################################################################## diff --git a/nzbget-postprocessing-files/0.8.0/postprocess.sh b/nzbget-postprocessing-files/0.8.0/postprocess.sh index 4fb4b287..67a37127 100644 --- a/nzbget-postprocessing-files/0.8.0/postprocess.sh +++ b/nzbget-postprocessing-files/0.8.0/postprocess.sh @@ -1,342 +1,378 @@ -#!/bin/sh -# -# Example postprocessing script for NZBGet -# -# Copyright (C) 2008 Peter Roubos -# Copyright (C) 2008 Otmar Werner -# Copyright (C) 2008-2009 Andrei Prygounkov -# Copyright (C) 2012 Antoine Bertin -# Copyright (C) 2012 Jürgen Seif -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -# - -####################### Usage instructions ####################### -# o Script will unrar downloaded rar files, join ts-files and rename img-files -# to iso. -# -# o To use this script with nzbget set the option "PostProcess" in -# nzbget configuration file to point to this script file. E.g.: -# PostProcess=/home/user/nzbget/nzbget-postprocess.sh -# -# o The script needs a configuration file. An example configuration file -# is provided in file "postprocess-example.conf". Put the configuration file -# into the directory where nzbget's configuration file (nzbget.conf) or where -# this script itself is located. Then edit the configuration file in any -# text editor to adjust the settings. -# -# o You can also edit the script's configuration via web-interface (requires -# NZBGetWeb 1.4 or later). Set the options "PostProcessConfigFile" and -# "PostProcessConfigTemplate" to point to "postprocess-example.conf" -# (including full path). The both options are under the section -# "CONFIGURATION OF POSTPROCESSING-SCRIPT" in NZBGetWeb. -# -# o There are few options, which can be ajdusted for each nzb-file -# individually. To view/edit them in web-interface click on a spanner icon -# near the name of nzb-file. -# -# o The script supports the feature called "delayed par-check". -# That means it can try to unpack downloaded files without par-checking -# them fisrt. Only if unpack fails, the script schedules par-check, -# then unpacks again. -# To use delayed par-check set following options in nzbget configuration file: -# ParCheck=no -# ParRepair=yes -# LoadPars=one (or) LoadPars=all -# -# o If you want to par-check/repair all files before trying to unpack them, -# set option "ParCheck=yes". -# -####################### End of Usage instructions ####################### - - - -# NZBGet passes following arguments to postprocess-programm as environment -# variables: -# NZBPP_DIRECTORY - path to destination dir for downloaded files; -# NZBPP_NZBFILENAME - name of processed nzb-file; -# NZBPP_PARFILENAME - name of par-file or empty string (if no collections were -# found); -# NZBPP_PARSTATUS - result of par-check: -# 0 = not checked: par-check disabled or nzb-file does -# not contain any par-files; -# 1 = checked and failed to repair; -# 2 = checked and successfully repaired; -# 3 = checked and can be repaired but repair is disabled; -# NZBPP_NZBCOMPLETED - state of nzb-job: -# 0 = there are more collections in this nzb-file queued; -# 1 = this was the last collection in nzb-file; -# NZBPP_PARFAILED - indication of failed par-jobs for current nzb-file: -# 0 = no failed par-jobs; -# 1 = current par-job or any of the previous par-jobs for -# the same nzb-files failed; -# NZBPP_CATEGORY - category assigned to nzb-file (can be empty string). - - -# Name of script's configuration file -SCRIPT_CONFIG_FILE="postprocess.conf" - -# Exit codes -POSTPROCESS_PARCHECK_CURRENT=91 -POSTPROCESS_PARCHECK_ALL=92 -POSTPROCESS_SUCCESS=93 -POSTPROCESS_ERROR=94 -POSTPROCESS_NONE=95 - - -# Check if the script is called from nzbget -if [ "$NZBPP_DIRECTORY" = "" -o "$NZBOP_CONFIGFILE" = "" ]; then - echo "*** NZBGet post-process script ***" - echo "This script is supposed to be called from nzbget (0.7.0 or later)." - exit $POSTPROCESS_ERROR -fi - -# Check if postprocessing was disabled in postprocessing parameters -# (for current nzb-file) via web-interface or via command line with -# "nzbget -E G O PostProcess=no " -if [ "$NZBPR_PostProcess" = "no" ]; then - echo "[WARNING] Post-Process: Postprocessing disabled for this nzb-file, exiting" - exit $POSTPROCESS_NONE -fi - -echo "[INFO] Post-Process: Post-process script successfully started" - -# Determine the location of configuration file (it must be stored in -# the directory with nzbget.conf or in this script's directory). -ConfigDir="${NZBOP_CONFIGFILE%/*}" -ScriptConfigFile="$ConfigDir/$SCRIPT_CONFIG_FILE" -if [ ! -f "$ScriptConfigFile" ]; then - ConfigDir="${0%/*}" - ScriptConfigFile="$ConfigDir/$SCRIPT_CONFIG_FILE" -fi -if [ ! -f "$ScriptConfigFile" ]; then - echo "[ERROR] Post-Process: Configuration file $ScriptConfigFile not found, exiting" - exit $POSTPROCESS_ERROR -fi - -# Readg configuration file -while read line; do eval "$line"; done < $ScriptConfigFile - -# Check nzbget.conf options -BadConfig=0 - -if [ "$NZBOP_ALLOWREPROCESS" = "yes" ]; then - echo "[ERROR] Post-Process: Please disable option \"AllowReProcess\" in nzbget configuration file" - BadConfig=1 -fi - -if [ "$NZBOP_LOADPARS" = "none" ]; then - echo "[ERROR] Post-Process: Please set option \"LoadPars\" to \"One\" or \"All\" in nzbget configuration file" - BadConfig=1 -fi - -if [ "$NZBOP_PARREPAIR" = "no" ]; then - echo "[ERROR] Post-Process: Please set option \"ParRepair\" to \"Yes\" in nzbget configuration file" - BadConfig=1 -fi - -if [ "$BadConfig" -eq 1 ]; then - echo "[ERROR] Post-Process: Existing because of not compatible nzbget configuration" - exit $POSTPROCESS_ERROR -fi - -# Check if all collections in nzb-file were downloaded -if [ ! "$NZBPP_NZBCOMPLETED" -eq 1 ]; then - echo "[INFO] Post-Process: Not the last collection in nzb-file, exiting" - exit $POSTPROCESS_SUCCESS -fi - -# Check par status -if [ "$NZBPP_PARSTATUS" -eq 1 -o "$NZBPP_PARSTATUS" -eq 3 -o "$NZBPP_PARFAILED" -eq 1 ]; then - if [ "$NZBPP_PARSTATUS" -eq 3 ]; then - echo "[WARNING] Post-Process: Par-check successful, but Par-repair disabled, exiting" - else - echo "[WARNING] Post-Process: Par-check failed, exiting" - fi - exit $POSTPROCESS_ERROR -fi - -# Check if destination directory exists (important for reprocessing of history items) -if [ ! -d "$NZBPP_DIRECTORY" ]; then - echo "[ERROR] Post-Process: Nothing to post-process: destination directory $NZBPP_DIRECTORY doesn't exist" - exit $POSTPROCESS_ERROR -fi - -cd "$NZBPP_DIRECTORY" - -# If not just repaired and file "_brokenlog.txt" exists, the collection is damaged -# exiting with returning code $POSTPROCESS_PARCHECK_ALL to request par-repair -if [ ! "$NZBPP_PARSTATUS" -eq 2 ]; then - if [ -f "_brokenlog.txt" ]; then - if (ls *.[pP][aA][rR]2 >/dev/null 2>&1); then - echo "[INFO] Post-Process: Brokenlog found, requesting par-repair" - exit $POSTPROCESS_PARCHECK_ALL - fi - fi -fi - -# All checks done, now processing the files - -# Flag indicates that something was unrared -Unrared=0 - -# Unrar the files (if any) to the temporary directory, if there are no rar files this will do nothing -if (ls *.rar >/dev/null 2>&1); then - - # Check if unrar exists - $UnrarCmd >/dev/null 2>&1 - if [ "$?" -eq 127 ]; then - echo "[ERROR] Post-Process: Unrar not found. Set the path to unrar in script's configuration" - exit $POSTPROCESS_ERROR - fi - - # Make a temporary directory to store the unrarred files - ExtractedDirExists=0 - if [ -d $ExtractedDir ]; then - ExtractedDirExists=1 - else - mkdir $ExtractedDir - fi - - echo "[INFO] Post-Process: Unraring" - rarpasswordparam="" - if [ "$NZBPR_Password" != "" ]; then - rarpasswordparam="-p$NZBPR_Password" - fi - - $UnrarCmd x -y -p- "$rarpasswordparam" -o+ "*.rar" ./$ExtractedDir/ - if [ "$?" -eq 3 ]; then - echo "[ERROR] Post-Process: Unrar failed" - if [ "$ExtractedDirExists" -eq 0 ]; then - rm -R $ExtractedDir - fi - # for delayed par-check/-repair at least one par-file must be already downloaded - if (ls *.[pP][aA][rR]2 >/dev/null 2>&1); then - echo "[INFO] Post-Process: Requesting par-repair" - exit $POSTPROCESS_PARCHECK_ALL - fi - exit $POSTPROCESS_ERROR - fi - Unrared=1 - - # Remove the rar files - if [ "$DeleteRarFiles" = "yes" ]; then - echo "[INFO] Post-Process: Deleting rar-files" - rm *.r[0-9][0-9] >/dev/null 2>&1 - rm *.rar >/dev/null 2>&1 - rm *.s[0-9][0-9] >/dev/null 2>&1 - fi - - # Go to the temp directory and try to unrar again. - # If there are any rars inside the extracted rars then these will no also be unrarred - cd $ExtractedDir - if (ls *.rar >/dev/null 2>&1); then - echo "[INFO] Post-Process: Unraring (second pass)" - $UnrarCmd x -y -p- -o+ "*.rar" - - if [ "$?" -eq 3 ]; then - echo "[INFO] Post-Process: Unrar (second pass) failed" - exit $POSTPROCESS_ERROR - fi - - # Delete the Rar files - if [ "$DeleteRarFiles" = "yes" ]; then - echo "[INFO] Post-Process: Deleting rar-files (second pass)" - rm *.r[0-9][0-9] >/dev/null 2>&1 - rm *.rar >/dev/null 2>&1 - rm *.s[0-9][0-9] >/dev/null 2>&1 - fi - fi - - # Move everything back to the Download folder - mv * .. - cd .. - rmdir $ExtractedDir -fi - -# If download contains only nzb-files move them into nzb-directory -# for further download -# Check if command "wc" exists -wc -l . >/dev/null 2>&1 -if [ "$?" -ne 127 ]; then - AllFilesCount=`ls -1 2>/dev/null | wc -l` - NZBFilesCount=`ls -1 *.nzb 2>/dev/null | wc -l` - if [ "$AllFilesCount" -eq "$NZBFilesCount" ]; then - echo "[INFO] Moving downloaded nzb-files into incoming nzb-directory for further download" - mv *.nzb $NZBOP_NZBDIR - fi -fi - -# Clean up -echo "[INFO] Post-Process: Cleaning up" -chmod -R a+rw . -rm *.nzb >/dev/null 2>&1 -rm *.sfv >/dev/null 2>&1 -rm *.1 >/dev/null 2>&1 -rm _brokenlog.txt >/dev/null 2>&1 -if [ "$Unrared" -eq 1 ]; then - # Delete par2-file only if there were files for unpacking. - rm *.[pP][aA][rR]2 >/dev/null 2>&1 -fi - -if [ "$JoinTS" = "yes" ]; then - # Join any split .ts files if they are named xxxx.0000.ts xxxx.0001.ts - # They will be joined together to a file called xxxx.0001.ts - if (ls *.ts >/dev/null 2>&1); then - echo "[INFO] Post-Process: Joining ts-files" - tsname=`find . -name "*0001.ts" |awk -F/ '{print $NF}'` - cat *0???.ts > ./$tsname - fi - - # Remove all the split .ts files - echo "[INFO] Post-Process: Deleting source ts-files" - rm *0???.ts >/dev/null 2>&1 -fi - -if [ "$RenameIMG" = "yes" ]; then - # Rename img file to iso - # It will be renamed to .img.iso so you can see that it has been renamed - if (ls *.img >/dev/null 2>&1); then - echo "[INFO] Post-Process: Renaming img-files to iso" - imgname=`find . -name "*.img" |awk -F/ '{print $NF}'` - mv $imgname $imgname.iso - fi -fi - -if [ "$SickBeard" = "yes" -a "$NZBPP_CATEGORY" = "$SickBeardCategory" -a -e "$SabToSickBeard" ]; then - # Call SickBeard's postprocessing script - echo "[INFO] Post-Process: Running SickBeard's postprocessing script" - $PythonCmd $SabToSickBeard "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" >/dev/null 2>&1 -fi - -if [ "$CouchPotato" = "yes" -a "$NZBPP_CATEGORY" = "$CouchPotatoCategory" -a -e "$NzbToCouchPotato" ]; then - # Call Couchpotato's postprocessing script - echo "[INFO] Post-Process: Running CouchPotato's postprocessing script" - $PythonCmd $NzbToCouchPotato "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" >/dev/null 2>&1 -fi - -# Check if destination directory was set in postprocessing parameters -# (for current nzb-file) via web-interface or via command line with -# "nzbget -E G O DestDir=/new/path " -if [ "$NZBPR_DestDir" != "" ]; then - mkdir $NZBPR_DestDir - mv * $NZBPR_DestDir >/dev/null 2>&1 - cd .. - rmdir $NZBPP_DIRECTORY -fi - -# All OK, requesting cleaning up of download queue -exit $POSTPROCESS_SUCCESS +#!/bin/sh +# +# This file if part of nzbget +# +# Example postprocessing script for NZBGet +# +# Copyright (C) 2008 Peter Roubos +# Copyright (C) 2008 Otmar Werner +# Copyright (C) 2008-2012 Andrey Prygunkov +# Copyright (C) 2012 Antoine Bertin +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# + +####################### Usage instructions ####################### +# o Script will unrar downloaded rar files, join ts-files and rename img-files +# to iso. +# +# o To use this script with nzbget set the option "PostProcess" in +# nzbget configuration file to point to this script file. E.g.: +# PostProcess=/home/user/nzbget/nzbget-postprocess.sh +# +# o The script needs a configuration file. An example configuration file +# is provided in file "postprocess-example.conf". Put the configuration file +# into the directory where nzbget's configuration file (nzbget.conf) or where +# this script itself is located. Then edit the configuration file in any +# text editor to adjust the settings. +# +# o You can also edit the script's configuration via web-interface (requires +# NZBGetWeb 1.4 or later). Set the options "PostProcessConfigFile" and +# "PostProcessConfigTemplate" to point to "postprocess-example.conf" +# (including full path). The both options are under the section +# "CONFIGURATION OF POSTPROCESSING-SCRIPT" in NZBGetWeb. +# +# o There are few options, which can be ajdusted for each nzb-file +# individually. To view/edit them in web-interface click on a spanner icon +# near the name of nzb-file. +# +# o The script supports the feature called "delayed par-check". +# That means it can try to unpack downloaded files without par-checking +# them fisrt. Only if unpack fails, the script schedules par-check, +# then unpacks again. +# To use delayed par-check set following options in nzbget configuration file: +# ParCheck=no +# ParRepair=yes +# LoadPars=one (or) LoadPars=all +# +# o If you want to par-check/repair all files before trying to unpack them, +# set option "ParCheck=yes". +# +####################### End of Usage instructions ####################### + + +# NZBGet passes following arguments to postprocess-programm as environment +# variables: +# NZBPP_DIRECTORY - path to destination dir for downloaded files; +# NZBPP_NZBFILENAME - name of processed nzb-file; +# NZBPP_PARFILENAME - name of par-file or empty string (if no collections were +# found); +# NZBPP_PARSTATUS - result of par-check: +# 0 = not checked: par-check disabled or nzb-file does +# not contain any par-files; +# 1 = checked and failed to repair; +# 2 = checked and successfully repaired; +# 3 = checked and can be repaired but repair is disabled; +# NZBPP_NZBCOMPLETED - state of nzb-job: +# 0 = there are more collections in this nzb-file queued; +# 1 = this was the last collection in nzb-file; +# NZBPP_PARFAILED - indication of failed par-jobs for current nzb-file: +# 0 = no failed par-jobs; +# 1 = current par-job or any of the previous par-jobs for +# the same nzb-files failed; +# NZBPP_CATEGORY - category assigned to nzb-file (can be empty string). + + +# Name of script's configuration file +SCRIPT_CONFIG_FILE="postprocess.conf" + +# Exit codes +POSTPROCESS_PARCHECK_CURRENT=91 +POSTPROCESS_PARCHECK_ALL=92 +POSTPROCESS_SUCCESS=93 +POSTPROCESS_ERROR=94 +POSTPROCESS_NONE=95 + +# Check if the script is called from nzbget +if [ "$NZBPP_DIRECTORY" = "" -o "$NZBOP_CONFIGFILE" = "" ]; then + echo "*** NZBGet post-process script ***" + echo "This script is supposed to be called from nzbget (0.7.0 or later)." + exit $POSTPROCESS_ERROR +fi + +# Check if postprocessing was disabled in postprocessing parameters +# (for current nzb-file) via web-interface or via command line with +# "nzbget -E G O PostProcess=no " +if [ "$NZBPR_PostProcess" = "no" ]; then + echo "[WARNING] Post-Process: Postprocessing disabled for this nzb-file, exiting" + exit $POSTPROCESS_NONE +fi + +echo "[INFO] Post-Process: Post-process script successfully started" + +# Determine the location of configuration file (it must be stored in +# the directory with nzbget.conf or in this script's directory). +ConfigDir="${NZBOP_CONFIGFILE%/*}" +ScriptConfigFile="$ConfigDir/$SCRIPT_CONFIG_FILE" +if [ ! -f "$ScriptConfigFile" ]; then + ConfigDir="${0%/*}" + ScriptConfigFile="$ConfigDir/$SCRIPT_CONFIG_FILE" +fi +if [ ! -f "$ScriptConfigFile" ]; then + echo "[ERROR] Post-Process: Configuration file $ScriptConfigFile not found, exiting" + exit $POSTPROCESS_ERROR +fi + +# Readg configuration file +while read line; do eval "$line"; done < $ScriptConfigFile + +# Check nzbget.conf options +BadConfig=0 + +if [ "$NZBOP_ALLOWREPROCESS" = "yes" ]; then + echo "[ERROR] Post-Process: Please disable option \"AllowReProcess\" in nzbget configuration file" + BadConfig=1 +fi + +if [ "$NZBOP_LOADPARS" = "none" ]; then + echo "[ERROR] Post-Process: Please set option \"LoadPars\" to \"One\" or \"All\" in nzbget configuration file" + BadConfig=1 +fi + +if [ "$NZBOP_PARREPAIR" = "no" ]; then + echo "[ERROR] Post-Process: Please set option \"ParRepair\" to \"Yes\" in nzbget configuration file" + BadConfig=1 +fi + +if [ "$BadConfig" -eq 1 ]; then + echo "[ERROR] Post-Process: Existing because of not compatible nzbget configuration" + exit $POSTPROCESS_ERROR +fi + +# Check if all collections in nzb-file were downloaded +if [ ! "$NZBPP_NZBCOMPLETED" -eq 1 ]; then + echo "[INFO] Post-Process: Not the last collection in nzb-file, exiting" + exit $POSTPROCESS_SUCCESS +fi + +# Check par status +if [ "$NZBPP_PARSTATUS" -eq 1 -o "$NZBPP_PARSTATUS" -eq 3 -o "$NZBPP_PARFAILED" -eq 1 ]; then + if [ "$NZBPP_PARSTATUS" -eq 3 ]; then + echo "[WARNING] Post-Process: Par-check successful, but Par-repair disabled, exiting" + else + echo "[WARNING] Post-Process: Par-check failed, exiting" + fi + exit $POSTPROCESS_ERROR +fi + +# Check if destination directory exists (important for reprocessing of history items) +if [ ! -d "$NZBPP_DIRECTORY" ]; then + echo "[ERROR] Post-Process: Nothing to post-process: destination directory $NZBPP_DIRECTORY doesn't exist" + exit $POSTPROCESS_ERROR +fi + +cd "$NZBPP_DIRECTORY" + +# If not just repaired and file "_brokenlog.txt" exists, the collection is damaged +# exiting with returning code $POSTPROCESS_PARCHECK_ALL to request par-repair +if [ ! "$NZBPP_PARSTATUS" -eq 2 ]; then + if [ -f "_brokenlog.txt" ]; then + if (ls *.[pP][aA][rR]2 >/dev/null 2>&1); then + echo "[INFO] Post-Process: Brokenlog found, requesting par-repair" + exit $POSTPROCESS_PARCHECK_ALL + fi + fi +fi + +# All checks done, now processing the files + +# Flag indicates that something was unrared +Unrared=0 + +# Unrar the files (if any) to the temporary directory, if there are no rar files this will do nothing +if (ls *.rar >/dev/null 2>&1); then + + # Check if unrar exists + $UnrarCmd >/dev/null 2>&1 + if [ "$?" -eq 127 ]; then + echo "[ERROR] Post-Process: Unrar not found. Set the path to unrar in script's configuration" + exit $POSTPROCESS_ERROR + fi + + # Make a temporary directory to store the unrarred files + ExtractedDirExists=0 + if [ -d $ExtractedDir ]; then + ExtractedDirExists=1 + else + mkdir $ExtractedDir + fi + + echo "[INFO] Post-Process: Unraring" + rarpasswordparam="" + if [ "$NZBPR_Password" != "" ]; then + rarpasswordparam="-p$NZBPR_Password" + fi + + $UnrarCmd x -y -p- "$rarpasswordparam" -o+ "*.rar" ./$ExtractedDir/ + if [ "$?" -eq 3 ]; then + echo "[ERROR] Post-Process: Unrar failed" + if [ "$ExtractedDirExists" -eq 0 ]; then + rm -R $ExtractedDir + fi + # for delayed par-check/-repair at least one par-file must be already downloaded + if (ls *.[pP][aA][rR]2 >/dev/null 2>&1); then + echo "[INFO] Post-Process: Requesting par-repair" + exit $POSTPROCESS_PARCHECK_ALL + fi + exit $POSTPROCESS_ERROR + fi + Unrared=1 + + # Remove the rar files + if [ "$DeleteRarFiles" = "yes" ]; then + echo "[INFO] Post-Process: Deleting rar-files" + rm *.r[0-9][0-9] >/dev/null 2>&1 + rm *.rar >/dev/null 2>&1 + rm *.s[0-9][0-9] >/dev/null 2>&1 + fi + + # Go to the temp directory and try to unrar again. + # If there are any rars inside the extracted rars then these will no also be unrarred + cd $ExtractedDir + if (ls *.rar >/dev/null 2>&1); then + echo "[INFO] Post-Process: Unraring (second pass)" + $UnrarCmd x -y -p- -o+ "*.rar" + + if [ "$?" -eq 3 ]; then + echo "[INFO] Post-Process: Unrar (second pass) failed" + exit $POSTPROCESS_ERROR + fi + + # Delete the Rar files + if [ "$DeleteRarFiles" = "yes" ]; then + echo "[INFO] Post-Process: Deleting rar-files (second pass)" + rm *.r[0-9][0-9] >/dev/null 2>&1 + rm *.rar >/dev/null 2>&1 + rm *.s[0-9][0-9] >/dev/null 2>&1 + fi + fi + + # Move everything back to the Download folder + mv * .. + cd .. + rmdir $ExtractedDir +fi + +# If download contains only nzb-files move them into nzb-directory +# for further download +# Check if command "wc" exists +wc -l . >/dev/null 2>&1 +if [ "$?" -ne 127 ]; then + AllFilesCount=`ls -1 2>/dev/null | wc -l` + NZBFilesCount=`ls -1 *.nzb 2>/dev/null | wc -l` + if [ "$AllFilesCount" -eq "$NZBFilesCount" ]; then + echo "[INFO] Moving downloaded nzb-files into incoming nzb-directory for further download" + mv *.nzb $NZBOP_NZBDIR + fi +fi + +# Clean up +echo "[INFO] Post-Process: Cleaning up" +chmod -R a+rw . +rm *.nzb >/dev/null 2>&1 +rm *.sfv >/dev/null 2>&1 +rm *.1 >/dev/null 2>&1 +rm _brokenlog.txt >/dev/null 2>&1 +if [ "$Unrared" -eq 1 ]; then + # Delete par2-file only if there were files for unpacking. + rm *.[pP][aA][rR]2 >/dev/null 2>&1 +fi + +if [ "$JoinTS" = "yes" ]; then + # Join any split .ts files if they are named xxxx.0000.ts xxxx.0001.ts + # They will be joined together to a file called xxxx.0001.ts + if (ls *.ts >/dev/null 2>&1); then + echo "[INFO] Post-Process: Joining ts-files" + tsname=`find . -name "*0001.ts" |awk -F/ '{print $NF}'` + cat *0???.ts > ./$tsname + fi + + # Remove all the split .ts files + echo "[INFO] Post-Process: Deleting source ts-files" + rm *0???.ts >/dev/null 2>&1 +fi + +if [ "$RenameIMG" = "yes" ]; then + # Rename img file to iso + # It will be renamed to .img.iso so you can see that it has been renamed + if (ls *.img >/dev/null 2>&1); then + echo "[INFO] Post-Process: Renaming img-files to iso" + imgname=`find . -name "*.img" |awk -F/ '{print $NF}'` + mv $imgname $imgname.iso + fi +fi + +############################ +### BEGIN CUSTOMIZATIONS ### +############################ + +# Move categories to /share/yourdirectory and remove download destination directory +if [ "$NZBPP_CATEGORY" = "$SickBeardCategory" ]; then + echo "[INFO] Post-Process: Moving TV shows to $TV_DL_DIR" + cp -R "$NZBPP_DIRECTORY" "$TV_DL_DIR" >/dev/null 2>&1 + if [ "$?" -ne 0 ]; then + echo "[ERROR] Post-Process: Moving to $TV_DL_DIR" + exit $POSTPROCESS_ERROR + else + rm -fr * + cd .. + rmdir "$NZBPP_DIRECTORY" + NZBPP_DIRECTORY="$TV_DL_DIR" + fi +fi + +if [ "$NZBPP_CATEGORY" = "$CouchPotatoCategory" ]; then + echo "[INFO] Post-Process: Moving Movies to $MOVIES_DL_DIR" + cp -R "$NZBPP_DIRECTORY" "$MOVIES_DL_DIR" >/dev/null 2>&1 + if [ "$?" -ne 0 ]; then + echo "[ERROR] Post-Process: Moving to $MOVIES_DL_DIR" + exit $POSTPROCESS_ERROR + else + rm -fr * + cd .. + rmdir "$NZBPP_DIRECTORY" + NZBPP_DIRECTORY="$MOVIES_DL_DIR" + fi +fi + +########################## +### END CUSTOMIZATIONS ### +########################## + +if [ "$SickBeard" = "yes" -a "$NZBPP_CATEGORY" = "$SickBeardCategory" -a -e "$NzbToSickBeard" ]; then + # Call SickBeard's postprocessing script + echo "[INFO] Post-Process: Running SickBeard's postprocessing script" + $PythonCmd $NzbToSickBeard "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" >/dev/null 2>&1 +fi + +if [ "$CouchPotato" = "yes" -a "$NZBPP_CATEGORY" = "$CouchPotatoCategory" -a -e "$NzbToCouchPotato" ]; then + # Call CouchPotato's postprocessing script + echo "[INFO] Post-Process: Running CouchPotato's postprocessing script" + $PythonCmd $NzbToCouchPotato "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" >/dev/null 2>&1 +fi + +# Check if destination directory was set in postprocessing parameters +# (for current nzb-file) via web-interface or via command line with +# "nzbget -E G O DestDir=/new/path " +if [ "$NZBPR_DestDir" != "" ]; then + mkdir $NZBPR_DestDir + mv * $NZBPR_DestDir >/dev/null 2>&1 + cd .. + rmdir $NZBPP_DIRECTORY +fi + +# All OK, requesting cleaning up of download queue +exit $POSTPROCESS_SUCCESS diff --git a/nzbget-postprocessing-files/9.0/bin/nzbget-postprocess.sh b/nzbget-postprocessing-files/9.0/bin/nzbget-postprocess.sh index 5394ad2f..8d680134 100644 --- a/nzbget-postprocessing-files/9.0/bin/nzbget-postprocess.sh +++ b/nzbget-postprocessing-files/9.0/bin/nzbget-postprocess.sh @@ -1,334 +1,378 @@ -#!/bin/sh -# -# This file if part of nzbget -# -# Example postprocessing script for NZBGet -# -# Copyright (C) 2008 Peter Roubos -# Copyright (C) 2008 Otmar Werner -# Copyright (C) 2008-2012 Andrey Prygunkov -# Copyright (C) 2012 Jürgen Seif -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -# - -####################### Usage instructions ####################### -# o Script will unrar downloaded rar files, join ts-files and rename img-files -# to iso. -# -# o To use this script with nzbget set the option "PostProcess" in -# nzbget configuration file to point to this script file. E.g.: -# PostProcess=/home/user/nzbget/nzbget-postprocess.sh -# -# o The script needs a configuration file. An example configuration file -# is provided in file "nzbget-postprocess.conf". Put the configuration file -# into the directory where nzbget's configuration file (nzbget.conf) is located. -# Then edit the configuration file in any text editor to adjust the settings. -# -# o You can also edit the script's configuration via web-interface. -# -# o There are few options, which can be ajdusted for each nzb-file individually. -# -# o The script supports the feature called "delayed par-check". -# That means it can try to unpack downloaded files without par-checking -# them fisrt. Only if unpack fails, the script schedules par-check, -# then unpacks again. -# To use delayed par-check set following options in nzbget configuration file: -# ParCheck=no -# ParRepair=yes -# LoadPars=one (or) LoadPars=all -# -# o If you want to par-check/repair all files before trying to unpack them, -# set option "ParCheck=yes". -# -####################### End of Usage instructions ####################### - - -# NZBGet passes following arguments to postprocess-programm as environment -# variables: -# NZBPP_DIRECTORY - path to destination dir for downloaded files; -# NZBPP_NZBFILENAME - name of processed nzb-file; -# NZBPP_PARFILENAME - name of par-file or empty string (if no collections were -# found); -# NZBPP_PARSTATUS - result of par-check: -# 0 = not checked: par-check disabled or nzb-file does -# not contain any par-files; -# 1 = checked and failed to repair; -# 2 = checked and successfully repaired; -# 3 = checked and can be repaired but repair is disabled; -# NZBPP_NZBCOMPLETED - state of nzb-job: -# 0 = there are more collections in this nzb-file queued; -# 1 = this was the last collection in nzb-file; -# NZBPP_PARFAILED - indication of failed par-jobs for current nzb-file: -# 0 = no failed par-jobs; -# 1 = current par-job or any of the previous par-jobs for -# the same nzb-files failed; -# NZBPP_CATEGORY - category assigned to nzb-file (can be empty string). - - -# Name of script's configuration file -SCRIPT_CONFIG_FILE="nzbget-postprocess.conf" - -# Exit codes -POSTPROCESS_PARCHECK_CURRENT=91 -POSTPROCESS_PARCHECK_ALL=92 -POSTPROCESS_SUCCESS=93 -POSTPROCESS_ERROR=94 -POSTPROCESS_NONE=95 - -# Check if the script is called from nzbget -if [ "$NZBPP_DIRECTORY" = "" -o "$NZBOP_CONFIGFILE" = "" ]; then - echo "*** NZBGet post-process script ***" - echo "This script is supposed to be called from nzbget (0.7.0 or later)." - exit $POSTPROCESS_ERROR -fi - -# Check if postprocessing was disabled in postprocessing parameters -# (for current nzb-file) via web-interface or via command line with -# "nzbget -E G O PostProcess=no " -if [ "$NZBPR_PostProcess" = "no" ]; then - echo "[WARNING] Post-Process: Postprocessing disabled for this nzb-file, exiting" - exit $POSTPROCESS_NONE -fi - -echo "[INFO] Post-Process: Post-process script successfully started" - -# Determine the location of configuration file (it must be stored in -# the directory with nzbget.conf or in this script's directory). -ConfigDir="${NZBOP_CONFIGFILE%/*}" -ScriptConfigFile="$ConfigDir/$SCRIPT_CONFIG_FILE" -if [ ! -f "$ScriptConfigFile" ]; then - ConfigDir="${0%/*}" - ScriptConfigFile="$ConfigDir/$SCRIPT_CONFIG_FILE" -fi -if [ ! -f "$ScriptConfigFile" ]; then - echo "[ERROR] Post-Process: Configuration file $ScriptConfigFile not found, exiting" - exit $POSTPROCESS_ERROR -fi - -# Readg configuration file -while read line; do eval "$line"; done < $ScriptConfigFile - -# Check nzbget.conf options -BadConfig=0 - -if [ "$NZBOP_ALLOWREPROCESS" = "yes" ]; then - echo "[ERROR] Post-Process: Please disable option \"AllowReProcess\" in nzbget configuration file" - BadConfig=1 -fi - -if [ "$NZBOP_LOADPARS" = "none" ]; then - echo "[ERROR] Post-Process: Please set option \"LoadPars\" to \"One\" or \"All\" in nzbget configuration file" - BadConfig=1 -fi - -if [ "$NZBOP_PARREPAIR" = "no" ]; then - echo "[ERROR] Post-Process: Please set option \"ParRepair\" to \"Yes\" in nzbget configuration file" - BadConfig=1 -fi - -if [ "$BadConfig" -eq 1 ]; then - echo "[ERROR] Post-Process: Exiting because of not compatible nzbget configuration" - exit $POSTPROCESS_ERROR -fi - -# Check if all collections in nzb-file were downloaded -if [ ! "$NZBPP_NZBCOMPLETED" -eq 1 ]; then - echo "[INFO] Post-Process: Not the last collection in nzb-file, exiting" - exit $POSTPROCESS_SUCCESS -fi - -# Check par status -if [ "$NZBPP_PARSTATUS" -eq 1 -o "$NZBPP_PARSTATUS" -eq 3 -o "$NZBPP_PARFAILED" -eq 1 ]; then - if [ "$NZBPP_PARSTATUS" -eq 3 ]; then - echo "[WARNING] Post-Process: Par-check successful, but Par-repair disabled, exiting" - else - echo "[WARNING] Post-Process: Par-check failed, exiting" - fi - exit $POSTPROCESS_ERROR -fi - -# Check if destination directory exists (important for reprocessing of history items) -if [ ! -d "$NZBPP_DIRECTORY" ]; then - echo "[ERROR] Post-Process: Nothing to post-process: destination directory $NZBPP_DIRECTORY doesn't exist" - exit $POSTPROCESS_ERROR -fi - -cd "$NZBPP_DIRECTORY" - -# If not just repaired and file "_brokenlog.txt" exists, the collection is damaged -# exiting with returning code $POSTPROCESS_PARCHECK_ALL to request par-repair -if [ ! "$NZBPP_PARSTATUS" -eq 2 ]; then - if [ -f "_brokenlog.txt" ]; then - if (ls *.[pP][aA][rR]2 >/dev/null 2>&1); then - echo "[INFO] Post-Process: Brokenlog found, requesting par-repair" - exit $POSTPROCESS_PARCHECK_ALL - fi - fi -fi - -# All checks done, now processing the files - -# Flag indicates that something was unrared -Unrared=0 - -# Unrar the files (if any) to the temporary directory, if there are no rar files this will do nothing -if (ls *.rar >/dev/null 2>&1); then - - # Check if unrar exists - $UnrarCmd >/dev/null 2>&1 - if [ "$?" -eq 127 ]; then - echo "[ERROR] Post-Process: Unrar not found. Set the path to unrar in script's configuration" - exit $POSTPROCESS_ERROR - fi - - # Make a temporary directory to store the unrarred files - ExtractedDirExists=0 - if [ -d extracted ]; then - ExtractedDirExists=1 - else - mkdir extracted - fi - - echo "[INFO] Post-Process: Unraring" - rarpasswordparam="" - if [ "$NZBPR_Password" != "" ]; then - rarpasswordparam="-p$NZBPR_Password" - fi - - $UnrarCmd x -y -p- "$rarpasswordparam" -o+ "*.rar" ./extracted/ - if [ "$?" -ne 0 ]; then - echo "[ERROR] Post-Process: Unrar failed" - if [ "$ExtractedDirExists" -eq 0 ]; then - rm -R extracted - fi - # for delayed par-check/-repair at least one par-file must be already downloaded - if (ls *.[pP][aA][rR]2 >/dev/null 2>&1); then - echo "[INFO] Post-Process: Requesting par-repair" - exit $POSTPROCESS_PARCHECK_ALL - fi - exit $POSTPROCESS_ERROR - fi - Unrared=1 - - # Remove the rar files - if [ "$DeleteRarFiles" = "yes" ]; then - echo "[INFO] Post-Process: Deleting rar-files" - rm *.r[0-9][0-9] >/dev/null 2>&1 - rm *.rar >/dev/null 2>&1 - rm *.s[0-9][0-9] >/dev/null 2>&1 - fi - - # Go to the temp directory and try to unrar again. - # If there are any rars inside the extracted rars then these will no also be unrarred - cd extracted - if (ls *.rar >/dev/null 2>&1); then - echo "[INFO] Post-Process: Unraring (second pass)" - $UnrarCmd x -y -p- -o+ "*.rar" - - if [ "$?" -ne 0 ]; then - echo "[INFO] Post-Process: Unrar (second pass) failed" - exit $POSTPROCESS_ERROR - fi - - # Delete the Rar files - if [ "$DeleteRarFiles" = "yes" ]; then - echo "[INFO] Post-Process: Deleting rar-files (second pass)" - rm *.r[0-9][0-9] >/dev/null 2>&1 - rm *.rar >/dev/null 2>&1 - rm *.s[0-9][0-9] >/dev/null 2>&1 - fi - fi - - # Move everything back to the Download folder - mv * .. - cd .. - rmdir extracted -fi - -# If download contains only nzb-files move them into nzb-directory -# for further download -# Check if command "wc" exists -wc -l . >/dev/null 2>&1 -if [ "$?" -ne 127 ]; then - AllFilesCount=`ls -1 2>/dev/null | wc -l` - NZBFilesCount=`ls -1 *.nzb 2>/dev/null | wc -l` - if [ "$AllFilesCount" -eq "$NZBFilesCount" ]; then - echo "[INFO] Moving downloaded nzb-files into incoming nzb-directory for further download" - mv *.nzb $NZBOP_NZBDIR - fi -fi - -# Clean up -echo "[INFO] Post-Process: Cleaning up" -chmod -R a+rw . -rm *.nzb >/dev/null 2>&1 -rm *.sfv >/dev/null 2>&1 -rm *.1 >/dev/null 2>&1 -rm _brokenlog.txt >/dev/null 2>&1 -if [ "$Unrared" -eq 1 ]; then - # Delete par2-file only if there were files for unpacking. - rm *.[pP][aA][rR]2 >/dev/null 2>&1 -fi - -if [ "$JoinTS" = "yes" ]; then - # Join any split .ts files if they are named xxxx.0000.ts xxxx.0001.ts - # They will be joined together to a file called xxxx.0001.ts - if (ls *.ts >/dev/null 2>&1); then - echo "[INFO] Post-Process: Joining ts-files" - tsname=`find . -name "*0001.ts" |awk -F/ '{print $NF}'` - cat *0???.ts > ./$tsname - fi - - # Remove all the split .ts files - echo "[INFO] Post-Process: Deleting source ts-files" - rm *0???.ts >/dev/null 2>&1 -fi - -if [ "$RenameIMG" = "yes" ]; then - # Rename img file to iso - # It will be renamed to .img.iso so you can see that it has been renamed - if (ls *.img >/dev/null 2>&1); then - echo "[INFO] Post-Process: Renaming img-files to iso" - imgname=`find . -name "*.img" |awk -F/ '{print $NF}'` - mv $imgname $imgname.iso - fi -fi - -if [ "$SickBeard" = "yes" -a "$NZBPP_CATEGORY" = "$SickBeardCategory" -a -e "$SabToSickBeard" ]; then - # Call SickBeard's postprocessing script - echo "[INFO] Post-Process: Running SickBeard's postprocessing script" - $PythonCmd $SabToSickBeard "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" >/dev/null 2>&1 -fi - -if [ "$CouchPotato" = "yes" -a "$NZBPP_CATEGORY" = "$CouchPotatoCategory" -a -e "$NzbToCouchPotato" ]; then - # Call Couchpotato's postprocessing script - echo "[INFO] Post-Process: Running CouchPotato's postprocessing script" - $PythonCmd $NzbToCouchPotato "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" >/dev/null 2>&1 -fi - -# Check if destination directory was set in postprocessing parameters -# (for current nzb-file) via web-interface or via command line with -# "nzbget -E G O DestDir=/new/path " -if [ "$NZBPR_DestDir" != "" ]; then - mkdir $NZBPR_DestDir - mv * $NZBPR_DestDir >/dev/null 2>&1 - cd .. - rmdir $NZBPP_DIRECTORY -fi - -# All OK, requesting cleaning up of download queue -exit $POSTPROCESS_SUCCESS +#!/bin/sh +# +# This file if part of nzbget +# +# Example postprocessing script for NZBGet +# +# Copyright (C) 2008 Peter Roubos +# Copyright (C) 2008 Otmar Werner +# Copyright (C) 2008-2012 Andrey Prygunkov +# Copyright (C) 2012 Antoine Bertin +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# + +####################### Usage instructions ####################### +# o Script will unrar downloaded rar files, join ts-files and rename img-files +# to iso. +# +# o To use this script with nzbget set the option "PostProcess" in +# nzbget configuration file to point to this script file. E.g.: +# PostProcess=/home/user/nzbget/nzbget-postprocess.sh +# +# o The script needs a configuration file. An example configuration file +# is provided in file "postprocess-example.conf". Put the configuration file +# into the directory where nzbget's configuration file (nzbget.conf) or where +# this script itself is located. Then edit the configuration file in any +# text editor to adjust the settings. +# +# o You can also edit the script's configuration via web-interface (requires +# NZBGetWeb 1.4 or later). Set the options "PostProcessConfigFile" and +# "PostProcessConfigTemplate" to point to "postprocess-example.conf" +# (including full path). The both options are under the section +# "CONFIGURATION OF POSTPROCESSING-SCRIPT" in NZBGetWeb. +# +# o There are few options, which can be ajdusted for each nzb-file +# individually. To view/edit them in web-interface click on a spanner icon +# near the name of nzb-file. +# +# o The script supports the feature called "delayed par-check". +# That means it can try to unpack downloaded files without par-checking +# them fisrt. Only if unpack fails, the script schedules par-check, +# then unpacks again. +# To use delayed par-check set following options in nzbget configuration file: +# ParCheck=no +# ParRepair=yes +# LoadPars=one (or) LoadPars=all +# +# o If you want to par-check/repair all files before trying to unpack them, +# set option "ParCheck=yes". +# +####################### End of Usage instructions ####################### + + +# NZBGet passes following arguments to postprocess-programm as environment +# variables: +# NZBPP_DIRECTORY - path to destination dir for downloaded files; +# NZBPP_NZBFILENAME - name of processed nzb-file; +# NZBPP_PARFILENAME - name of par-file or empty string (if no collections were +# found); +# NZBPP_PARSTATUS - result of par-check: +# 0 = not checked: par-check disabled or nzb-file does +# not contain any par-files; +# 1 = checked and failed to repair; +# 2 = checked and successfully repaired; +# 3 = checked and can be repaired but repair is disabled; +# NZBPP_NZBCOMPLETED - state of nzb-job: +# 0 = there are more collections in this nzb-file queued; +# 1 = this was the last collection in nzb-file; +# NZBPP_PARFAILED - indication of failed par-jobs for current nzb-file: +# 0 = no failed par-jobs; +# 1 = current par-job or any of the previous par-jobs for +# the same nzb-files failed; +# NZBPP_CATEGORY - category assigned to nzb-file (can be empty string). + + +# Name of script's configuration file +SCRIPT_CONFIG_FILE="nzbget-postprocess.conf" + +# Exit codes +POSTPROCESS_PARCHECK_CURRENT=91 +POSTPROCESS_PARCHECK_ALL=92 +POSTPROCESS_SUCCESS=93 +POSTPROCESS_ERROR=94 +POSTPROCESS_NONE=95 + +# Check if the script is called from nzbget +if [ "$NZBPP_DIRECTORY" = "" -o "$NZBOP_CONFIGFILE" = "" ]; then + echo "*** NZBGet post-process script ***" + echo "This script is supposed to be called from nzbget (0.7.0 or later)." + exit $POSTPROCESS_ERROR +fi + +# Check if postprocessing was disabled in postprocessing parameters +# (for current nzb-file) via web-interface or via command line with +# "nzbget -E G O PostProcess=no " +if [ "$NZBPR_PostProcess" = "no" ]; then + echo "[WARNING] Post-Process: Postprocessing disabled for this nzb-file, exiting" + exit $POSTPROCESS_NONE +fi + +echo "[INFO] Post-Process: Post-process script successfully started" + +# Determine the location of configuration file (it must be stored in +# the directory with nzbget.conf or in this script's directory). +ConfigDir="${NZBOP_CONFIGFILE%/*}" +ScriptConfigFile="$ConfigDir/$SCRIPT_CONFIG_FILE" +if [ ! -f "$ScriptConfigFile" ]; then + ConfigDir="${0%/*}" + ScriptConfigFile="$ConfigDir/$SCRIPT_CONFIG_FILE" +fi +if [ ! -f "$ScriptConfigFile" ]; then + echo "[ERROR] Post-Process: Configuration file $ScriptConfigFile not found, exiting" + exit $POSTPROCESS_ERROR +fi + +# Readg configuration file +while read line; do eval "$line"; done < $ScriptConfigFile + +# Check nzbget.conf options +BadConfig=0 + +if [ "$NZBOP_ALLOWREPROCESS" = "yes" ]; then + echo "[ERROR] Post-Process: Please disable option \"AllowReProcess\" in nzbget configuration file" + BadConfig=1 +fi + +if [ "$NZBOP_LOADPARS" = "none" ]; then + echo "[ERROR] Post-Process: Please set option \"LoadPars\" to \"One\" or \"All\" in nzbget configuration file" + BadConfig=1 +fi + +if [ "$NZBOP_PARREPAIR" = "no" ]; then + echo "[ERROR] Post-Process: Please set option \"ParRepair\" to \"Yes\" in nzbget configuration file" + BadConfig=1 +fi + +if [ "$BadConfig" -eq 1 ]; then + echo "[ERROR] Post-Process: Exiting because of not compatible nzbget configuration" + exit $POSTPROCESS_ERROR +fi + +# Check if all collections in nzb-file were downloaded +if [ ! "$NZBPP_NZBCOMPLETED" -eq 1 ]; then + echo "[INFO] Post-Process: Not the last collection in nzb-file, exiting" + exit $POSTPROCESS_SUCCESS +fi + +# Check par status +if [ "$NZBPP_PARSTATUS" -eq 1 -o "$NZBPP_PARSTATUS" -eq 3 -o "$NZBPP_PARFAILED" -eq 1 ]; then + if [ "$NZBPP_PARSTATUS" -eq 3 ]; then + echo "[WARNING] Post-Process: Par-check successful, but Par-repair disabled, exiting" + else + echo "[WARNING] Post-Process: Par-check failed, exiting" + fi + exit $POSTPROCESS_ERROR +fi + +# Check if destination directory exists (important for reprocessing of history items) +if [ ! -d "$NZBPP_DIRECTORY" ]; then + echo "[ERROR] Post-Process: Nothing to post-process: destination directory $NZBPP_DIRECTORY doesn't exist" + exit $POSTPROCESS_ERROR +fi + +cd "$NZBPP_DIRECTORY" + +# If not just repaired and file "_brokenlog.txt" exists, the collection is damaged +# exiting with returning code $POSTPROCESS_PARCHECK_ALL to request par-repair +if [ ! "$NZBPP_PARSTATUS" -eq 2 ]; then + if [ -f "_brokenlog.txt" ]; then + if (ls *.[pP][aA][rR]2 >/dev/null 2>&1); then + echo "[INFO] Post-Process: Brokenlog found, requesting par-repair" + exit $POSTPROCESS_PARCHECK_ALL + fi + fi +fi + +# All checks done, now processing the files + +# Flag indicates that something was unrared +Unrared=0 + +# Unrar the files (if any) to the temporary directory, if there are no rar files this will do nothing +if (ls *.rar >/dev/null 2>&1); then + + # Check if unrar exists + $UnrarCmd >/dev/null 2>&1 + if [ "$?" -eq 127 ]; then + echo "[ERROR] Post-Process: Unrar not found. Set the path to unrar in script's configuration" + exit $POSTPROCESS_ERROR + fi + + # Make a temporary directory to store the unrarred files + ExtractedDirExists=0 + if [ -d extracted ]; then + ExtractedDirExists=1 + else + mkdir extracted + fi + + echo "[INFO] Post-Process: Unraring" + rarpasswordparam="" + if [ "$NZBPR_Password" != "" ]; then + rarpasswordparam="-p$NZBPR_Password" + fi + + $UnrarCmd x -y -p- "$rarpasswordparam" -o+ "*.rar" ./extracted/ + if [ "$?" -ne 0 ]; then + echo "[ERROR] Post-Process: Unrar failed" + if [ "$ExtractedDirExists" -eq 0 ]; then + rm -R extracted + fi + # for delayed par-check/-repair at least one par-file must be already downloaded + if (ls *.[pP][aA][rR]2 >/dev/null 2>&1); then + echo "[INFO] Post-Process: Requesting par-repair" + exit $POSTPROCESS_PARCHECK_ALL + fi + exit $POSTPROCESS_ERROR + fi + Unrared=1 + + # Remove the rar files + if [ "$DeleteRarFiles" = "yes" ]; then + echo "[INFO] Post-Process: Deleting rar-files" + rm *.r[0-9][0-9] >/dev/null 2>&1 + rm *.rar >/dev/null 2>&1 + rm *.s[0-9][0-9] >/dev/null 2>&1 + fi + + # Go to the temp directory and try to unrar again. + # If there are any rars inside the extracted rars then these will no also be unrarred + cd extracted + if (ls *.rar >/dev/null 2>&1); then + echo "[INFO] Post-Process: Unraring (second pass)" + $UnrarCmd x -y -p- -o+ "*.rar" + + if [ "$?" -ne 0 ]; then + echo "[INFO] Post-Process: Unrar (second pass) failed" + exit $POSTPROCESS_ERROR + fi + + # Delete the Rar files + if [ "$DeleteRarFiles" = "yes" ]; then + echo "[INFO] Post-Process: Deleting rar-files (second pass)" + rm *.r[0-9][0-9] >/dev/null 2>&1 + rm *.rar >/dev/null 2>&1 + rm *.s[0-9][0-9] >/dev/null 2>&1 + fi + fi + + # Move everything back to the Download folder + mv * .. + cd .. + rmdir extracted +fi + +# If download contains only nzb-files move them into nzb-directory +# for further download +# Check if command "wc" exists +wc -l . >/dev/null 2>&1 +if [ "$?" -ne 127 ]; then + AllFilesCount=`ls -1 2>/dev/null | wc -l` + NZBFilesCount=`ls -1 *.nzb 2>/dev/null | wc -l` + if [ "$AllFilesCount" -eq "$NZBFilesCount" ]; then + echo "[INFO] Moving downloaded nzb-files into incoming nzb-directory for further download" + mv *.nzb $NZBOP_NZBDIR + fi +fi + +# Clean up +echo "[INFO] Post-Process: Cleaning up" +chmod -R a+rw . +rm *.nzb >/dev/null 2>&1 +rm *.sfv >/dev/null 2>&1 +rm *.1 >/dev/null 2>&1 +rm _brokenlog.txt >/dev/null 2>&1 +if [ "$Unrared" -eq 1 ]; then + # Delete par2-file only if there were files for unpacking. + rm *.[pP][aA][rR]2 >/dev/null 2>&1 +fi + +if [ "$JoinTS" = "yes" ]; then + # Join any split .ts files if they are named xxxx.0000.ts xxxx.0001.ts + # They will be joined together to a file called xxxx.0001.ts + if (ls *.ts >/dev/null 2>&1); then + echo "[INFO] Post-Process: Joining ts-files" + tsname=`find . -name "*0001.ts" |awk -F/ '{print $NF}'` + cat *0???.ts > ./$tsname + fi + + # Remove all the split .ts files + echo "[INFO] Post-Process: Deleting source ts-files" + rm *0???.ts >/dev/null 2>&1 +fi + +if [ "$RenameIMG" = "yes" ]; then + # Rename img file to iso + # It will be renamed to .img.iso so you can see that it has been renamed + if (ls *.img >/dev/null 2>&1); then + echo "[INFO] Post-Process: Renaming img-files to iso" + imgname=`find . -name "*.img" |awk -F/ '{print $NF}'` + mv $imgname $imgname.iso + fi +fi + +############################ +### BEGIN CUSTOMIZATIONS ### +############################ + +# Move categories to /share/yourdirectory and remove download destination directory +if [ "$NZBPP_CATEGORY" = "$SickBeardCategory" ]; then + echo "[INFO] Post-Process: Moving TV shows to $TV_DL_DIR" + cp -R "$NZBPP_DIRECTORY" "$TV_DL_DIR" >/dev/null 2>&1 + if [ "$?" -ne 0 ]; then + echo "[ERROR] Post-Process: Moving to $TV_DL_DIR" + exit $POSTPROCESS_ERROR + else + rm -fr * + cd .. + rmdir "$NZBPP_DIRECTORY" + NZBPP_DIRECTORY="$TV_DL_DIR" + fi +fi + +if [ "$NZBPP_CATEGORY" = "$CouchPotatoCategory" ]; then + echo "[INFO] Post-Process: Moving Movies to $MOVIES_DL_DIR" + cp -R "$NZBPP_DIRECTORY" "$MOVIES_DL_DIR" >/dev/null 2>&1 + if [ "$?" -ne 0 ]; then + echo "[ERROR] Post-Process: Moving to $MOVIES_DL_DIR" + exit $POSTPROCESS_ERROR + else + rm -fr * + cd .. + rmdir "$NZBPP_DIRECTORY" + NZBPP_DIRECTORY="$MOVIES_DL_DIR" + fi +fi + +########################## +### END CUSTOMIZATIONS ### +########################## + +if [ "$SickBeard" = "yes" -a "$NZBPP_CATEGORY" = "$SickBeardCategory" -a -e "$NzbToSickBeard" ]; then + # Call SickBeard's postprocessing script + echo "[INFO] Post-Process: Running SickBeard's postprocessing script" + $PythonCmd $NzbToSickBeard "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" >/dev/null 2>&1 +fi + +if [ "$CouchPotato" = "yes" -a "$NZBPP_CATEGORY" = "$CouchPotatoCategory" -a -e "$NzbToCouchPotato" ]; then + # Call CouchPotato's postprocessing script + echo "[INFO] Post-Process: Running CouchPotato's postprocessing script" + $PythonCmd $NzbToCouchPotato "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" >/dev/null 2>&1 +fi + +# Check if destination directory was set in postprocessing parameters +# (for current nzb-file) via web-interface or via command line with +# "nzbget -E G O DestDir=/new/path " +if [ "$NZBPR_DestDir" != "" ]; then + mkdir $NZBPR_DestDir + mv * $NZBPR_DestDir >/dev/null 2>&1 + cd .. + rmdir $NZBPP_DIRECTORY +fi + +# All OK, requesting cleaning up of download queue +exit $POSTPROCESS_SUCCESS diff --git a/nzbget-postprocessing-files/9.0/webui/nzbget-postprocess.conf b/nzbget-postprocessing-files/9.0/webui/nzbget-postprocess.conf index e7f31701..af6d01c2 100644 --- a/nzbget-postprocessing-files/9.0/webui/nzbget-postprocess.conf +++ b/nzbget-postprocessing-files/9.0/webui/nzbget-postprocess.conf @@ -33,10 +33,18 @@ UnrarCmd=unrar PythonCmd=/usr/local/python/bin/python # Set the full path to sabToSickBeard.py for SickBeard's postprocessing. -SabToSickBeard=/opt/share/nzbget/scripts/sabToSickBeard.py +NzbToSickBeard=/usr/local/nzbget/var/nzbToSickBeard.py + +# Set the full path where completed movies should be placed +# before CouchPotato's Renamer is called +TV_DL_DIR=/usr/local/nzbget/complete/tv # Set the full path to nzbToCouchpotato.py for Couchpotato's postprocessing -NzbToCouchPotato=/opt/share/nzbget/scripts/nzbToCouchPotato.py +NzbToCouchPotato=/usr/local/nzbget/var/nzbToCouchPotato.py + +# Set the full path where completed movies should be placed +# before CouchPotato's Renamer is called +MOVIES_DL_DIR=/usr/local/nzbget/complete/movies ############################################################################## ### OPTIONS ### From be059e6cf31d9a71accc918e5da21922692b15c6 Mon Sep 17 00:00:00 2001 From: Clinton Hall Date: Fri, 30 Nov 2012 16:08:18 +1030 Subject: [PATCH 13/16] Added SickBeard files Includes modified sabToSickBeard (now nzbToSickBeard) that supports NZBGet --- autoProcessTV.cfg.sample | 7 +++ autoProcessTV.py | 108 +++++++++++++++++++++++++++++++++++++++ nzbToSickBeard.py | 53 +++++++++++++++++++ 3 files changed, 168 insertions(+) create mode 100644 autoProcessTV.cfg.sample create mode 100644 autoProcessTV.py create mode 100644 nzbToSickBeard.py diff --git a/autoProcessTV.cfg.sample b/autoProcessTV.cfg.sample new file mode 100644 index 00000000..15dc900c --- /dev/null +++ b/autoProcessTV.cfg.sample @@ -0,0 +1,7 @@ +[SickBeard] +host=localhost +port=8081 +username= +password= +web_root= +ssl=0 \ No newline at end of file diff --git a/autoProcessTV.py b/autoProcessTV.py new file mode 100644 index 00000000..b42ffd58 --- /dev/null +++ b/autoProcessTV.py @@ -0,0 +1,108 @@ +# Author: Nic Wolfe +# URL: http://code.google.com/p/sickbeard/ +# +# This file is part of Sick Beard. +# +# Sick Beard is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sick Beard is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Sick Beard. If not, see . + + +import sys +import urllib +import os.path +import ConfigParser + +class AuthURLOpener(urllib.FancyURLopener): + def __init__(self, user, pw): + self.username = user + self.password = pw + self.numTries = 0 + urllib.FancyURLopener.__init__(self) + + def prompt_user_passwd(self, host, realm): + if self.numTries == 0: + self.numTries = 1 + return (self.username, self.password) + else: + return ('', '') + + def openit(self, url): + self.numTries = 0 + return urllib.FancyURLopener.open(self, url) + + +def processEpisode(dirName, nzbName=None, status=0): + + if status > 0: + print "the download failed. nothing to process" + sys.exit() + + config = ConfigParser.ConfigParser() + configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessTV.cfg") + print "Loading config from", configFilename + + if not os.path.isfile(configFilename): + print "ERROR: You need an autoProcessTV.cfg file - did you rename and edit the .sample?" + sys.exit(-1) + + try: + fp = open(configFilename, "r") + config.readfp(fp) + fp.close() + except IOError, e: + print "Could not read configuration file: ", str(e) + sys.exit(1) + + host = config.get("SickBeard", "host") + port = config.get("SickBeard", "port") + username = config.get("SickBeard", "username") + password = config.get("SickBeard", "password") + try: + ssl = int(config.get("SickBeard", "ssl")) + except (ConfigParser.NoOptionError, ValueError): + ssl = 0 + + try: + web_root = config.get("SickBeard", "web_root") + except ConfigParser.NoOptionError: + web_root = "" + + params = {} + + params['quiet'] = 1 + + params['dir'] = dirName + if nzbName != None: + params['nzbName'] = nzbName + + myOpener = AuthURLOpener(username, password) + + if ssl: + protocol = "https://" + else: + protocol = "http://" + + url = protocol + host + ":" + port + web_root + "/home/postprocess/processEpisode?" + urllib.urlencode(params) + + print "Opening URL:", url + + try: + urlObj = myOpener.openit(url) + except IOError, e: + print "Unable to open URL: ", str(e) + sys.exit(1) + + result = urlObj.readlines() + for line in result: + print line + diff --git a/nzbToSickBeard.py b/nzbToSickBeard.py new file mode 100644 index 00000000..a2cb2d7b --- /dev/null +++ b/nzbToSickBeard.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python + +# Author: Nic Wolfe +# URL: http://code.google.com/p/sickbeard/ +# +# This file is part of Sick Beard. +# +# Sick Beard is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sick Beard is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Sick Beard. If not, see . +# +# Edited by Clinton Hall to prevent processing of failed downloads. +# Also added suppot for NZBGet. With help from thorli + + +import sys +import autoProcessTV + +# SABnzbd +if len(sys.argv) == 8: +# SABnzbd argv: +# 1 The final directory of the job (full path) +# 2 The original name of the NZB file +# 3 Clean version of the job name (no path info and ".nzb" removed) +# 4 Indexer's report number (if supported) +# 5 User-defined category +# 6 Group that the NZB was posted in e.g. alt.binaries.x +# 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2 + print "Script triggered from SABnzbd, starting autoProcessTV..." + autoProcessTV.processEpisode(sys.argv[1], sys.argv[2], sys.argv[7]) + +# NZBGet +elif len(sys.argv) == 3: +# NZBGet argv: +# 1 The final directory of the job (full path) +# 2 The original name of the NZB file +# From NZBGet only successful downloads are triggered so status is set to "0" + print "Script triggered from NZBGet, starting autoProcessTV..." + + autoProcessTV.processEpisode(sys.argv[1], sys.argv[2], 0) + +else: + print "Invalid number of arguments received from client." + sys.exit() From 8211a953cb8b0b291e3ef790fa8abdb84086a7c2 Mon Sep 17 00:00:00 2001 From: clinton-hall Date: Thu, 29 Nov 2012 21:46:41 -0800 Subject: [PATCH 14/16] changed to v 3.0 --- autoProcessMovie.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoProcessMovie.py b/autoProcessMovie.py index 128bcf1b..603bd29a 100644 --- a/autoProcessMovie.py +++ b/autoProcessMovie.py @@ -29,7 +29,7 @@ def process(dirName, nzbName=None, status=0): config = ConfigParser.ConfigParser() configFilename = os.path.join(os.path.dirname(sys.argv[0]), "autoProcessMovie.cfg") - print "autoProcessMovie v 2.2" + print "autoProcessMovie v 3.0" print "Loading config from", configFilename if not os.path.isfile(configFilename): From 0459647c97f867e43405b7083f0bc5beb577f370 Mon Sep 17 00:00:00 2001 From: clinton-hall Date: Thu, 29 Nov 2012 21:50:44 -0800 Subject: [PATCH 15/16] changes to V 3.0 --- changelog.txt.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/changelog.txt.txt b/changelog.txt.txt index 21984f9a..00888ad8 100644 --- a/changelog.txt.txt +++ b/changelog.txt.txt @@ -1,5 +1,10 @@ Change_LOG / History +V3.0 30/11/2012 + +Changed name to nzbToCouchPotato as this now included NZBGet support. +Packaged the NZBGet postprocess files as well as modified version of nzbToSickBeard (from sabToSickBeard). + V2.2 05/10/2012 From dc0c05ed12e8d0c2502f94f2a71690d7cd272161 Mon Sep 17 00:00:00 2001 From: Clinton Hall Date: Fri, 30 Nov 2012 16:26:43 +1030 Subject: [PATCH 16/16] removed extra ".txt" from changelog name. --- changelog.txt.txt => changelog.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename changelog.txt.txt => changelog.txt (100%) diff --git a/changelog.txt.txt b/changelog.txt similarity index 100% rename from changelog.txt.txt rename to changelog.txt