Normalize line endings

This commit is contained in:
Clinton Hall 2012-12-21 09:41:35 +10:30
commit 7fbd9a775c
6 changed files with 1517 additions and 1517 deletions

600
README.md
View file

@ -1,300 +1,300 @@
nzbToMedia
================
Provides an efficient way to handle postprocessing for [CouchPotatoServer](https://couchpota.to/ "CouchPotatoServer") and [SickBeard](http://sickbeard.com/ "SickBeard")
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") and further contributions by [schumi2004](https://github.com/schumi2004 "schumi2004") and [hugbug](https://sourceforge.net/apps/phpbb/nzbget/memberlist.php?mode=viewprofile&u=67 "hugbug")
Introduction
------------
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 download directory.
Later, a few failed downloads prompted me to incorporate "failed download" handling.
Failed download 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 download 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 thorli's version of sabToCouchPotato which has now been named "nzbToCouchPotato".
Failed download handling for SickBeard is available by using the development branch from fork [SickBeard-failed](https://github.com/Tolstyak/Sick-Beard.git "SickBeard-failed")
To use this feature, in autoProcessTV.cfg set the parameter "failed_fork=1". Default is 0 and will work with standard version of SickBeard and just ignores failed downloads.
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.
### nzbToSickBeard
1. Rename the file autoProcessTV.cfg.sample to autoProcessTV.cfg and fill in the appropriate
fields as they apply to your installation.
host: Set this to "localhost" if SickBeard and your download client are on the same system. otherwise enter the ipaddress of the system SickBeard is insatlled on.
port: Set this to the port that SickBeard is running on.
username: Set this to the user name required to log on to the SickBeard web GUI. (optional)
password: Set this to the password required to log on to the SickBeard web GUI. (optional)
web_root: Set this to the web_root value specified in SickBeard for Apache Reverse Proxy. (optional)
ssl: Set this to "1" if you access SickBeard via ssl (https) otherwise leave this as "0" for http.
watch_dir: Set this only if SickBeard is on another PC to your download client and the directory structure is different.(optional)
failed_fork: Set this to "1" if you are using the failed fork branch. Otherwise set this to "0". (optional)
### nzbToCouchPotato
1. Rename the file autoProcessMovie.cfg.sample to autoProcessMovie.cfg and fill in the appropriate
fields as they apply to your installation.
host: Set this to "localhost" if CouchPotatoServer and your download client are on the same system. otherwise enter the ipaddress of the system SickBeard is insatlled on.
port: Set this to the port that CouchPotatoServer is running on.
username: Set this to the user name required to log on to the CouchPotatoServer web GUI. (optional)
password: Set this to the password required to log on to the CouchPotatoServer web GUI. (optional)
web_root: Set this to the web_root value specified in CouchPotatoServer for Apache Reverse Proxy. (optional)
ssl: Set this to "1" if you access CouchPotatoServer via ssl (https) otherwise leave this as "0" for http.
Delay: Delay must be a minimum of 60 seconds for the renamer.scan to run successfully. CouchPotatoServer performs a test to ensure files/folder are not newer than 1 minute to prevent renaming of files that are still extracting.
apikey: Enter the api key used for CouchPotatoServer. Found in CouchPotatoServer->settings->general (addvanced setting)
Method: Method "renamer" is the default which will cause CouchPotatoserver to move and rename downloaded files as specified in the CouchPotatoServer 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 CouchPotatoServer renamer settings. Renamer must be enabled but automatic scan can be disabled by setting "Run Every" to "0".
Method "manage" will make CouchPotatoServer 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 CouchPotatoServer manage settings) and Manage must be enabled.
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.
### SickBeard
The following must be configured in SickBeard:
1. Config -> Search Settings -> NZB Search
i. NZB Method = Either SABnzbd or NZBget as appropriate
ii. NZBget HOST:PORT - SABnzbd URL = the url/host and port for your download client.
iii. SABnzbd Username = The username required to log in to sabnzbd web GUI
iv. NZBget Password - SABnzbd Passowrd = The password required to log in to your download client's web GUI.
v. SABnzbd API Key = The api key used by SABnzbd (Found in sabnzbd -> config -> general -> SABnzbd Web Server)
vi. NZBGet Category - SABnzbd Category = A category that is used by your download client (e.g. "TV", or "SickBeard")
2. Settings -> Post Processing -> Post Processing
i. TV Download Dir = blank
ii. Keep Original Files = user choice. (option)
iii. Move Associated Files = user choice. (option)
iv. Rename Episodes = must be ticked.
v. Scan and Process = must be unticked.
3. Settings -> Post Processing -> Naming
The naming must be specified as per user choice.
This naming will be applied to all shows processed via the postprocess script.
4. Settings -> Post Processing -> Metadata
The metadata wanted must be specified as per user choice.
This metadata creationg will be applied to all shows processed via the postprocess script.
### CouchPotatoServer
The following must be configured in CouchPotatoServer:
1. Settings -> Downloaders -> Sabnzbd (or NZBGet)
i. Host = The url/host and port for your download client.
ii. Api Key = The api key used by SABnzbd (Sabnzbd only: Found in sabnzbd -> config -> general -> SABnzbd Web Server)
iii. Password = The password required to log in to NZBget's web GUI. (NZBget only)
iv. Category = A category that is used by your downlaod client (e.g. "movies", or "CouchPotato")
v. Delete Failed = Should be unticked (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 (including any additional category paths)
e.g. %sabnzbd_download_complete/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 unticked.
> 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":
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. 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.
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:
> 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":
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 as a "Custom" postprocess script, 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 change as needed:
i. Set the full path to python if it is not in your PATH.
PythonCmd=/usr/local/python/bin/python
ii. Set the full path to sabToSickBeard.py for SickBeard's postprocessing.
NzbToSickBeard=/usr/local/nzbget/var/nzbToSickBeard.py
iii. Set the full path where completed movies should be placed before SickBeard's Renamer is called (option)
TvDownloadDir=
iv. Set the full path to nzbToCouchpotato.py for Couchpotato's postprocessing
NzbToCouchPotato=/usr/local/nzbget/var/nzbToCouchPotato.py
v. Set the full path where completed movies should be placed before CouchPotato's Renamer is called (option)
MoviesDownloadDir=
vi. Set the full path to any dependency required for your Custom Postprocess script if it is not in your PATH.
CustomCmd=/usr/local/python/bin/python
vii. Set the full path to the Custom Postprocess script. (option)
CustomScript=
viii.Set the full path where completed downloads should be placed before the Custom postprocess is called (option)
CustomDownloadDir=
3. Then go to "POSTPROCESSING SCRIPT" -> "OPTIONS" and set:
i. Perform SickBeard's postprocessing (yes, no).
SickBeard=yes
ii. Category for SickBeard's postprocessing.
SickBeardCategory=tv
iii. Perform Couchpotato's postprocessing (yes, no).
CouchPotato=yes
iv. Category for Couchpotato's postprocessing. (option)
CouchPotatoCategory=movies
v. Perform Custom postprocessing (yes, no). (option)
Custom=
vi. Category for Custom postprocessing (eg. movies) (option)
CustomCategory=
4. Then go to "POSTPROCESSING SCRIPT" -> "EMAIL-PARAMETERS" and set:
i. Specify if you want emails to be sent for successful downloads.
Email_successful=yes
ii. Specify if you want emails to be sent for failed downloads.
Email_failed=yes
iii. Set the full path and file name for sendEmail application (as supplied in this repository).
sendEmail=/usr/local/nzbget/var/sendEmail/sendEmail
iv. Enter the email address you want this email to be sent from.
Email_From=nzbget@nas.home
v. Enter the email address you want this email to be sent to.
Email_To=me@home.net
vi. Enter smtp server and port. eg smtp.live.com:25
Email_Server=smtp.live.com:25
vii. Enter your smtp server user name (if required)
Email_User=
viii.Enter your smtp server password (if required)
Email_Pass=
ix. Enter your email subject in quotes.
Use <status> to add 'completed'/'failed'
Use <name> to add the nzb name
Use <cat> to add the download categoty.
Use <script> to name the external script used.
Email_Subject="The Download of <name> has <status>"
x. Enter your email message in quotes.
Use the same substitutes as described above.
Use /n for new line.
Email_Message="The download of <name> has <status> /n This has been processed by the script <script> for category <cat>"
nzbToMedia
================
Provides an efficient way to handle postprocessing for [CouchPotatoServer](https://couchpota.to/ "CouchPotatoServer") and [SickBeard](http://sickbeard.com/ "SickBeard")
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") and further contributions by [schumi2004](https://github.com/schumi2004 "schumi2004") and [hugbug](https://sourceforge.net/apps/phpbb/nzbget/memberlist.php?mode=viewprofile&u=67 "hugbug")
Introduction
------------
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 download directory.
Later, a few failed downloads prompted me to incorporate "failed download" handling.
Failed download 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 download 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 thorli's version of sabToCouchPotato which has now been named "nzbToCouchPotato".
Failed download handling for SickBeard is available by using the development branch from fork [SickBeard-failed](https://github.com/Tolstyak/Sick-Beard.git "SickBeard-failed")
To use this feature, in autoProcessTV.cfg set the parameter "failed_fork=1". Default is 0 and will work with standard version of SickBeard and just ignores failed downloads.
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.
### nzbToSickBeard
1. Rename the file autoProcessTV.cfg.sample to autoProcessTV.cfg and fill in the appropriate
fields as they apply to your installation.
host: Set this to "localhost" if SickBeard and your download client are on the same system. otherwise enter the ipaddress of the system SickBeard is insatlled on.
port: Set this to the port that SickBeard is running on.
username: Set this to the user name required to log on to the SickBeard web GUI. (optional)
password: Set this to the password required to log on to the SickBeard web GUI. (optional)
web_root: Set this to the web_root value specified in SickBeard for Apache Reverse Proxy. (optional)
ssl: Set this to "1" if you access SickBeard via ssl (https) otherwise leave this as "0" for http.
watch_dir: Set this only if SickBeard is on another PC to your download client and the directory structure is different.(optional)
failed_fork: Set this to "1" if you are using the failed fork branch. Otherwise set this to "0". (optional)
### nzbToCouchPotato
1. Rename the file autoProcessMovie.cfg.sample to autoProcessMovie.cfg and fill in the appropriate
fields as they apply to your installation.
host: Set this to "localhost" if CouchPotatoServer and your download client are on the same system. otherwise enter the ipaddress of the system SickBeard is insatlled on.
port: Set this to the port that CouchPotatoServer is running on.
username: Set this to the user name required to log on to the CouchPotatoServer web GUI. (optional)
password: Set this to the password required to log on to the CouchPotatoServer web GUI. (optional)
web_root: Set this to the web_root value specified in CouchPotatoServer for Apache Reverse Proxy. (optional)
ssl: Set this to "1" if you access CouchPotatoServer via ssl (https) otherwise leave this as "0" for http.
Delay: Delay must be a minimum of 60 seconds for the renamer.scan to run successfully. CouchPotatoServer performs a test to ensure files/folder are not newer than 1 minute to prevent renaming of files that are still extracting.
apikey: Enter the api key used for CouchPotatoServer. Found in CouchPotatoServer->settings->general (addvanced setting)
Method: Method "renamer" is the default which will cause CouchPotatoserver to move and rename downloaded files as specified in the CouchPotatoServer 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 CouchPotatoServer renamer settings. Renamer must be enabled but automatic scan can be disabled by setting "Run Every" to "0".
Method "manage" will make CouchPotatoServer 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 CouchPotatoServer manage settings) and Manage must be enabled.
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.
### SickBeard
The following must be configured in SickBeard:
1. Config -> Search Settings -> NZB Search
i. NZB Method = Either SABnzbd or NZBget as appropriate
ii. NZBget HOST:PORT - SABnzbd URL = the url/host and port for your download client.
iii. SABnzbd Username = The username required to log in to sabnzbd web GUI
iv. NZBget Password - SABnzbd Passowrd = The password required to log in to your download client's web GUI.
v. SABnzbd API Key = The api key used by SABnzbd (Found in sabnzbd -> config -> general -> SABnzbd Web Server)
vi. NZBGet Category - SABnzbd Category = A category that is used by your download client (e.g. "TV", or "SickBeard")
2. Settings -> Post Processing -> Post Processing
i. TV Download Dir = blank
ii. Keep Original Files = user choice. (option)
iii. Move Associated Files = user choice. (option)
iv. Rename Episodes = must be ticked.
v. Scan and Process = must be unticked.
3. Settings -> Post Processing -> Naming
The naming must be specified as per user choice.
This naming will be applied to all shows processed via the postprocess script.
4. Settings -> Post Processing -> Metadata
The metadata wanted must be specified as per user choice.
This metadata creationg will be applied to all shows processed via the postprocess script.
### CouchPotatoServer
The following must be configured in CouchPotatoServer:
1. Settings -> Downloaders -> Sabnzbd (or NZBGet)
i. Host = The url/host and port for your download client.
ii. Api Key = The api key used by SABnzbd (Sabnzbd only: Found in sabnzbd -> config -> general -> SABnzbd Web Server)
iii. Password = The password required to log in to NZBget's web GUI. (NZBget only)
iv. Category = A category that is used by your downlaod client (e.g. "movies", or "CouchPotato")
v. Delete Failed = Should be unticked (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 (including any additional category paths)
e.g. %sabnzbd_download_complete/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 unticked.
> 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":
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. 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.
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:
> 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":
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 as a "Custom" postprocess script, 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 change as needed:
i. Set the full path to python if it is not in your PATH.
PythonCmd=/usr/local/python/bin/python
ii. Set the full path to sabToSickBeard.py for SickBeard's postprocessing.
NzbToSickBeard=/usr/local/nzbget/var/nzbToSickBeard.py
iii. Set the full path where completed movies should be placed before SickBeard's Renamer is called (option)
TvDownloadDir=
iv. Set the full path to nzbToCouchpotato.py for Couchpotato's postprocessing
NzbToCouchPotato=/usr/local/nzbget/var/nzbToCouchPotato.py
v. Set the full path where completed movies should be placed before CouchPotato's Renamer is called (option)
MoviesDownloadDir=
vi. Set the full path to any dependency required for your Custom Postprocess script if it is not in your PATH.
CustomCmd=/usr/local/python/bin/python
vii. Set the full path to the Custom Postprocess script. (option)
CustomScript=
viii.Set the full path where completed downloads should be placed before the Custom postprocess is called (option)
CustomDownloadDir=
3. Then go to "POSTPROCESSING SCRIPT" -> "OPTIONS" and set:
i. Perform SickBeard's postprocessing (yes, no).
SickBeard=yes
ii. Category for SickBeard's postprocessing.
SickBeardCategory=tv
iii. Perform Couchpotato's postprocessing (yes, no).
CouchPotato=yes
iv. Category for Couchpotato's postprocessing. (option)
CouchPotatoCategory=movies
v. Perform Custom postprocessing (yes, no). (option)
Custom=
vi. Category for Custom postprocessing (eg. movies) (option)
CustomCategory=
4. Then go to "POSTPROCESSING SCRIPT" -> "EMAIL-PARAMETERS" and set:
i. Specify if you want emails to be sent for successful downloads.
Email_successful=yes
ii. Specify if you want emails to be sent for failed downloads.
Email_failed=yes
iii. Set the full path and file name for sendEmail application (as supplied in this repository).
sendEmail=/usr/local/nzbget/var/sendEmail/sendEmail
iv. Enter the email address you want this email to be sent from.
Email_From=nzbget@nas.home
v. Enter the email address you want this email to be sent to.
Email_To=me@home.net
vi. Enter smtp server and port. eg smtp.live.com:25
Email_Server=smtp.live.com:25
vii. Enter your smtp server user name (if required)
Email_User=
viii.Enter your smtp server password (if required)
Email_Pass=
ix. Enter your email subject in quotes.
Use <status> to add 'completed'/'failed'
Use <name> to add the nzb name
Use <cat> to add the download categoty.
Use <script> to name the external script used.
Email_Subject="The Download of <name> has <status>"
x. Enter your email message in quotes.
Use the same substitutes as described above.
Use /n for new line.
Email_Message="The download of <name> has <status> /n This has been processed by the script <script> for category <cat>"

View file

@ -1,9 +1,9 @@
[SickBeard]
host=localhost
port=8081
username=
password=
web_root=
ssl=0
watch_dir=
[SickBeard]
host=localhost
port=8081
username=
password=
web_root=
ssl=0
watch_dir=
failed_fork=0

View file

@ -1,137 +1,137 @@
Change_LOG / History
V4.0 21/12/2012
Changed name from nzbToCouchPotato to nzbToMedia; Now supports mltiple post-processing from two nzb download clients.
Added email support for nzbget.
Version printing now for each of the nzbTo* scripts.
Added "custom" post-process support in nzbget.
Added post-process script output logging in nzbget.
V3.2 11/12/2012
Added failed handling from NZBGet. Thanks to schumi2004.
Also added support for the "failed download" development branch of SickBeard from https://github.com/Tolstyak/Sick-Beard.git
V3.1 02/12/2012
Added conversion to ensure the status passed to the autoProcessTV and autoProcessMovie is always handled as an integer.
V3.0 30/11/2012
Changed name from sabToCouchPotato 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
Re-wrote the failed downlaod handling to just search for the imdb ttXXXX identifier (as received from the nzb name)
Now issues only two api calls. movie.list and searcher.try_next
Should be more robust with regards changes to CPS and also utilises less resources (i.e. less api call and and less processing).
V2.1 04/10/2012
detected a change in the movie release info format. Fixed the script to work with new format.
V2.0 04/10/2012
Fixed an issue with the failed download handling in that the status id for "snatched" can be different on each installation. now performs a status.list via api to verify the status.
Also including a version print (currently 2.0... yeah original I know) so you know if you are current.
removed the multiple versions. The former _recue version will perform the standard renamer only if "postprocess only verified downloads" (default) is enabled in SABnzbd. Also, the "unix" version works fine in Windows, only the "dos" version gave issue in Linux. In other words, this one version should work for all systems.
For historical reasons, the former download stats apply to the old versions:
sabToCouchPotato-dos - downloaded 143 times
sabToCouchPotato-unix - downloaded 205 times
sabToCouchPotato_recue - downloaded 105 times
Also updated the Windows Build to include the same changes. I have removed the link to the linux build as this didn't work on all systems and it really shouldn't be necessary. Let me know if you need this updated.
V1.9 18/09/2012
compiled (build) versions of sabToSickBeard and sabToCouchPotato added for both Linux and Windows. links at top of post.
V1.9 16/09/2012
Added a compiled .exe version for windows. Should prevent the "python not recognised" issue and allow this to be used in conjunction with the windows build on systems that do not have python installed.
This is the full (_recue version) if sabnzbd is set to post ptocess only verified jobs, this will not recue and will function as a standard renamer.
V1.9 27/08/2012
Following the latest CPS update on the master branch, this script is not really needed as CPS actually polls the SABnzbd api and does the same as this script (internally).
However, if you have any issues with CPS constantly downloading the same movies, or filling the log with polling SABnzbd for completed movies, or otherwise prefer to use this method, then you can still use this script and make the following changes in CPS:
Settings, renamer, run every (advanced) = set to 1440 (or some longer interval)
Settings, renamer, next On_failed = off
Settings, downloaders, SABnzbd, Delete failed = off.
V1.9 06/08/2012
Also added the integer handling of status in the sabToSickBeard.py script to prevent SickBeard trying to postprocess a failed TV download. Only impacts the _recue version
V1.8 05/08/2012
Modified the _recue version as SABnzbd 0.7.3 now appears to pass the "status" variable as a string not an integer!!! (or i had it wrong on first attempt :~)
This causes the old script to identify completed downloads as failed and recues the next download!
The fix here should work with any conceivable subsequent updates in that I now make the sys.argv[7] an integer before passing it. if the variable already is an integer, this shouldn't cause any issues.
status = int(sys.argv[7])
autoProcessMovie.process(sys.argv[1], sys.argv[2], status)
V1.7 02/08/2012
Added a new version sabToCouchPotato_recue
This works the same as the other versions, but includes support for recuing failed downloads.
This is new, and only tested once (with success ) at my end.
To get this to run you will need to uncheck the "post-process only verified jobs" option in SABnzbd. Also, to avoid issues with SickBeard postprocessing, I have included a modified postprocessing for SickBeard that just checks for failed status and then exits (the SickBeard Team are currently working on failed download handling and I will hopefully make this script work with that in the future)
This re-cue works as follows:
Performs an api call to CPS to get a list of all wanted movies (with all data including the releases and status etc)
It finds the nzbname (from SABnzbd) in the json list returned from the api call (movie.list) and identifies the movie id and release id.
It performs an api call to make the release as "ignore" and then performs another api call to refresh the movie.
If another (next best) release that meets your criteria is already available it will send that to SABnzbd, otherwise it will wait until a new release becomes availabe.
I have left the old versions here for now for those who don't want to try this. Also, if you don't uncheck the "post-process only verified jobs" in SABnzbd this code will perform the same as the previous versions.
The next issue to tackle (if this works) is automating the deletion of failed download files in SABnzbd.... but I figured this was a start.
V1.6 22/07/2012
no functionality change, but providing scripts in both unix and dos format to prevent exit(127) errors.
if you are using windows, use the dos format. if you are using linux, use the unix format and unzip the files in linux.
V1.5 17/07/2012
add back the web_root parameter to set the URL base.
V1.4 17/07/2012
Have uploaded the latest version.
changes
Removed support for a movie.downlaoded api call that was only used in a seperate branch and is not expected to be merged.
Modified the passthrough to allow a manual call to this script (i.e. does not need to be called from SABnzbd).
Have added a helpfile that explains the setup options in a bit more detail.
Modified the .cfg.sample file to use 60 as a default delay and now specify that 60 should be your minimum to ensure the renamer.scan finds newly extracted movies.
V1.3 and earlier were not fully tracked, as the script itself (not files) was posted on the QNAP forums.
Change_LOG / History
V4.0 21/12/2012
Changed name from nzbToCouchPotato to nzbToMedia; Now supports mltiple post-processing from two nzb download clients.
Added email support for nzbget.
Version printing now for each of the nzbTo* scripts.
Added "custom" post-process support in nzbget.
Added post-process script output logging in nzbget.
V3.2 11/12/2012
Added failed handling from NZBGet. Thanks to schumi2004.
Also added support for the "failed download" development branch of SickBeard from https://github.com/Tolstyak/Sick-Beard.git
V3.1 02/12/2012
Added conversion to ensure the status passed to the autoProcessTV and autoProcessMovie is always handled as an integer.
V3.0 30/11/2012
Changed name from sabToCouchPotato 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
Re-wrote the failed downlaod handling to just search for the imdb ttXXXX identifier (as received from the nzb name)
Now issues only two api calls. movie.list and searcher.try_next
Should be more robust with regards changes to CPS and also utilises less resources (i.e. less api call and and less processing).
V2.1 04/10/2012
detected a change in the movie release info format. Fixed the script to work with new format.
V2.0 04/10/2012
Fixed an issue with the failed download handling in that the status id for "snatched" can be different on each installation. now performs a status.list via api to verify the status.
Also including a version print (currently 2.0... yeah original I know) so you know if you are current.
removed the multiple versions. The former _recue version will perform the standard renamer only if "postprocess only verified downloads" (default) is enabled in SABnzbd. Also, the "unix" version works fine in Windows, only the "dos" version gave issue in Linux. In other words, this one version should work for all systems.
For historical reasons, the former download stats apply to the old versions:
sabToCouchPotato-dos - downloaded 143 times
sabToCouchPotato-unix - downloaded 205 times
sabToCouchPotato_recue - downloaded 105 times
Also updated the Windows Build to include the same changes. I have removed the link to the linux build as this didn't work on all systems and it really shouldn't be necessary. Let me know if you need this updated.
V1.9 18/09/2012
compiled (build) versions of sabToSickBeard and sabToCouchPotato added for both Linux and Windows. links at top of post.
V1.9 16/09/2012
Added a compiled .exe version for windows. Should prevent the "python not recognised" issue and allow this to be used in conjunction with the windows build on systems that do not have python installed.
This is the full (_recue version) if sabnzbd is set to post ptocess only verified jobs, this will not recue and will function as a standard renamer.
V1.9 27/08/2012
Following the latest CPS update on the master branch, this script is not really needed as CPS actually polls the SABnzbd api and does the same as this script (internally).
However, if you have any issues with CPS constantly downloading the same movies, or filling the log with polling SABnzbd for completed movies, or otherwise prefer to use this method, then you can still use this script and make the following changes in CPS:
Settings, renamer, run every (advanced) = set to 1440 (or some longer interval)
Settings, renamer, next On_failed = off
Settings, downloaders, SABnzbd, Delete failed = off.
V1.9 06/08/2012
Also added the integer handling of status in the sabToSickBeard.py script to prevent SickBeard trying to postprocess a failed TV download. Only impacts the _recue version
V1.8 05/08/2012
Modified the _recue version as SABnzbd 0.7.3 now appears to pass the "status" variable as a string not an integer!!! (or i had it wrong on first attempt :~)
This causes the old script to identify completed downloads as failed and recues the next download!
The fix here should work with any conceivable subsequent updates in that I now make the sys.argv[7] an integer before passing it. if the variable already is an integer, this shouldn't cause any issues.
status = int(sys.argv[7])
autoProcessMovie.process(sys.argv[1], sys.argv[2], status)
V1.7 02/08/2012
Added a new version sabToCouchPotato_recue
This works the same as the other versions, but includes support for recuing failed downloads.
This is new, and only tested once (with success ) at my end.
To get this to run you will need to uncheck the "post-process only verified jobs" option in SABnzbd. Also, to avoid issues with SickBeard postprocessing, I have included a modified postprocessing for SickBeard that just checks for failed status and then exits (the SickBeard Team are currently working on failed download handling and I will hopefully make this script work with that in the future)
This re-cue works as follows:
Performs an api call to CPS to get a list of all wanted movies (with all data including the releases and status etc)
It finds the nzbname (from SABnzbd) in the json list returned from the api call (movie.list) and identifies the movie id and release id.
It performs an api call to make the release as "ignore" and then performs another api call to refresh the movie.
If another (next best) release that meets your criteria is already available it will send that to SABnzbd, otherwise it will wait until a new release becomes availabe.
I have left the old versions here for now for those who don't want to try this. Also, if you don't uncheck the "post-process only verified jobs" in SABnzbd this code will perform the same as the previous versions.
The next issue to tackle (if this works) is automating the deletion of failed download files in SABnzbd.... but I figured this was a start.
V1.6 22/07/2012
no functionality change, but providing scripts in both unix and dos format to prevent exit(127) errors.
if you are using windows, use the dos format. if you are using linux, use the unix format and unzip the files in linux.
V1.5 17/07/2012
add back the web_root parameter to set the URL base.
V1.4 17/07/2012
Have uploaded the latest version.
changes
Removed support for a movie.downlaoded api call that was only used in a seperate branch and is not expected to be merged.
Modified the passthrough to allow a manual call to this script (i.e. does not need to be called from SABnzbd).
Have added a helpfile that explains the setup options in a bit more detail.
Modified the .cfg.sample file to use 60 as a default delay and now specify that 60 should be your minimum to ensure the renamer.scan finds newly extracted movies.
V1.3 and earlier were not fully tracked, as the script itself (not files) was posted on the QNAP forums.

View file

@ -1,475 +1,475 @@
#!/bin/sh
# -*- coding: cp1252 -*-
#
# Example postprocessing script for NZBGet
#
# Copyright (C) 2008 Peter Roubos <peterroubos@hotmail.com>
# Copyright (C) 2008 Otmar Werner
# Copyright (C) 2008-2012 Andrei Prygunkov <hugbug@users.sourceforge.net>
# Copyright (C) 2012 Antoine Bertin <diaoulael@gmail.com>
# Copyright (C) 2012 J<>rgen Seif <thor78@gmx.at>
#
# 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
# Postprocessing function for nzbToCouchPotato and nzbToSickBeard
nzbToMedia() {
if [ "$Debug" = "yes" ]; then echo "[DETAIL] Post-Process: Executing external postprocessing with argument $1" ; fi
PostProcessStatus=0
if [ -n "$1" ]; then PostProcessStatus=$1 ; fi
if [ "$Debug" = "yes" ]; then echo "[DETAIL] Post-Process: comparing '$NZBPP_CATEGORY' to '$CouchPotatoCategory' and '$SickBeardCategory'" ; fi
if [ "$NZBPP_CATEGORY" = "$CouchPotatoCategory" ]; then
if [ "$CouchPotato" = "yes" -a -e "$NzbToCouchPotato" ]; then
script=$NzbToCouchPotato
# Call Couchpotato's postprocessing script
echo "[INFO] Post-Process: Running CouchPotato's postprocessing script"
if [ "$Debug" = "yes" ]; then
echo "[DETAIL] Post-Process: CouchPotato-Script-Path=$NzbToCouchPotato"
echo "[DETAIL] Post-Process: CouchPotato-Script-ARGV1=$NZBPP_DIRECTORY"
echo "[DETAIL] Post-Process: CouchPotato-Script-ARGV2=$NZBPP_NZBFILENAME"
echo "[DETAIL] Post-Process: CouchPotato-Script-ARGV3=$PostProcessStatus"
fi
$PythonCmd $NzbToCouchPotato "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "$PostProcessStatus" | while read line ; do if [ "$line" != "" ] ; then echo "[INFO] Post-Process: $line" ; fi ; done
else
if [ "$CouchPotato" != "yes" ]; then echo "[DETAIL] Post-Process: Ignored to run CouchPotato's postprocessing script as it is disabled by user ('$CouchPotato')"; fi
if [ ! -e "$NzbToCouchPotato" ]; then echo "[DETAIL] Post-Process: Ignored to run CouchPotato's postprocessing script as the specified script ('$NzbToCouchPotato') does not exist"; fi
fi
fi
if [ "$NZBPP_CATEGORY" = "$SickBeardCategory" ]; then
if [ "$SickBeard" = "yes" -a -e "$NzbToSickBeard" ]; then
script=$NzbToSickBeard
# Call SickBeard's postprocessing script
echo "[INFO] Post-Process: Running SickBeard's postprocessing script"
if [ "$Debug" = "yes" ]; then
echo "[DETAIL] Post-Process: SickBeard-Script-Path=$NzbToSickBeard"
echo "[DETAIL] Post-Process: SickBeard-Script-ARGV1=$NZBPP_DIRECTORY"
echo "[DETAIL] Post-Process: SickBeard-Script-ARGV2=$NZBPP_NZBFILENAME"
echo "[DETAIL] Post-Process: SickBeard-Script-ARGV3=$PostProcessStatus"
fi
$PythonCmd $NzbToSickBeard "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "$PostProcessStatus" | while read line ; do if [ "$line" != "" ] ; then echo "[INFO] Post-Process: $line" ; fi ; done
else
if [ "$SickBeard" != "yes" ]; then echo "[DETAIL] Post-Process: Ignored to run SickBeard's postprocessing script as it is disabled by user ('$SickBeard')"; fi
if [ ! -e "$NzbToSickBeard" ]; then echo "[DETAIL] Post-Process: Ignored to run SickBeard's postprocessing script as the specified script ('$NzbToSickBeard') does not exist"; fi
fi
fi
if [ "$NZBPP_CATEGORY" = "$CustomCategory" ]; then
if [ "$Custom" = "yes" -a -e "$CustomScript" ]; then
script=$CustomScript
# Call Custom postprocessing script
echo "[INFO] Post-Process: Running the Custom postprocessing script"
if [ "$Debug" = "yes" ]; then
echo "[DETAIL] Post-Process: Custom-Script-Path=$CustomScript"
echo "[DETAIL] Post-Process: Custom-Script-ARGV1=$NZBPP_DIRECTORY"
echo "[DETAIL] Post-Process: Custom-Script-ARGV2=$NZBPP_NZBFILENAME"
echo "[DETAIL] Post-Process: Custom-Script-ARGV3=$PostProcessStatus"
fi
$CustomCmd $CustomScript "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "$PostProcessStatus" | while read line ; do if [ "$line" != "" ] ; then echo "[INFO] Post-Process: $line" ; fi ; done
else
if [ "$Custom" != "yes" ]; then echo "[DETAIL] Post-Process: Ignored to run the Custom postprocessing script as it is disabled by user ('$Custom')"; fi
if [ ! -e "$CustomScript" ]; then echo "[DETAIL] Post-Process: Ignored to run the Custom postprocessing script as the specified script ('$CustomScript') does not exist"; fi
fi
fi
}
# Pass on postprocess exit codes to external scripts for handling failed downloads
do_exit() {
if [ "$Debug" = "yes" ]; then echo "[DETAIL] Post-Process: Executing function 'do_exit' with argument $1" ; fi
nzbStatus=0
if [ "$1" -ne "$POSTPROCESS_SUCCESS" ]; then nzbStatus=1 ; fi
script=none
nzbToMedia $nzbStatus
Email_Subject="${Email_Subject/<name>/$NZBPP_NZBFILENAME}"
Email_Subject="${Email_Subject/<cat>/$NZBPP_CATEGORY}"
Email_Subject="${Email_Subject/<script>/$script}"
Email_Message="${Email_Message/<name>/$NZBPP_NZBFILENAME}"
Email_Message="${Email_Message/<cat>/$NZBPP_CATEGORY}"
Email_Message="${Email_Message/<script>/$script}"
if [ "$Email_successful" = "yes" -a "$nzbStatus" = 0 ]; then
User=""
if [ -n "$Email_User" -a -n "$Email_Pass" ]; then User="-xu $Email_User -xp $Email_Pass" ; fi
Email_Subject="${Email_Subject/<status>/completed}"
Email_Message="${Email_Message/<status>/completed}"
$sendEmail -f "$Email_From" -t "$Email_To" -s "$Email_Server" $User -u "$Email_Subject" -m "$Email_Message"
fi
if [ "$Email_failed" = "yes" -a "$nzbStatus" != 0 ]; then
User=""
if [ -n "$Email_User" -a -n "$Email_Pass" ]; then User="-xu $Email_User -xp $Email_Pass" ; fi
Email_Subject="${Email_Subject/<status>/failed}"
Email_Message="${Email_Message/<status>/failed}"
$sendEmail -f "$Email_From" -t "$Email_To" -s "$Email_Server" $User -u "$Email_Subject" -m "$Email_Message"
fi
exit $1
}
# 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 <ID>"
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
do_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"
do_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"
do_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"
do_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"
do_exit $POSTPROCESS_PARCHECK_ALL
fi
do_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"
do_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 .
# Clean up list, space seperated array from GUI
for item in ${FileCleanUp[*]} ; do rm $item >/dev/null 2>&1 ; done
# Removed by default
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/your_directory and remove download destination directory
# Test for category and ensure the passed directory exists as a directory.
if [ "$NZBPP_CATEGORY" = "$SickBeardCategory" -a -d "$TvDownloadDir" ]; then
echo "[INFO] Post-Process: Moving TV shows to $TvDownloadDir"
cp -R "$NZBPP_DIRECTORY" "$TvDownloadDir"
if [ "$?" -ne 0 ]; then
echo "[ERROR] Post-Process: Moving to $TvDownloadDir"
exit $POSTPROCESS_ERROR
else
rm -fr *
cd ..
rmdir "$NZBPP_DIRECTORY"
NZBPP_DIRECTORY="$TvDownloadDir"
cd "$NZBPP_DIRECTORY"
fi
fi
# Test for category and ensure the passed directory exists as a directory.
if [ "$NZBPP_CATEGORY" = "$CouchPotatoCategory" -a -d "$MoviesDownloadDir" ]; then
echo "[INFO] Post-Process: Moving Movies to $MoviesDownloadDir"
cp -R "$NZBPP_DIRECTORY" "$MoviesDownloadDir"
if [ "$?" -ne 0 ]; then
echo "[ERROR] Post-Process: Moving to $MoviesDownloadDir"
exit $POSTPROCESS_ERROR
else
rm -fr *
cd ..
rmdir "$NZBPP_DIRECTORY"
NZBPP_DIRECTORY="$MoviesDownloadDir"
cd "$NZBPP_DIRECTORY"
fi
fi
# Test for category and ensure the passed directory exists as a directory.
if [ "$NZBPP_CATEGORY" = "$CustomCategory" -a -d "$CustomDownloadDir" ]; then
echo "[INFO] Post-Process: Moving $CustomCategory to $CustomDownloadDir"
cp -R "$NZBPP_DIRECTORY" "$CustomDownloadDir"
if [ "$?" -ne 0 ]; then
echo "[ERROR] Post-Process: Moving to $CustomDownloadDir"
exit $POSTPROCESS_ERROR
else
rm -fr *
cd ..
rmdir "$NZBPP_DIRECTORY"
NZBPP_DIRECTORY="$CustomDownloadDir"
cd "$NZBPP_DIRECTORY"
fi
fi
##########################
### END CUSTOMIZATIONS ###
##########################
# 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 <ID>"
if [ "$NZBPR_DestDir" != "" ]; then
mkdir $NZBPR_DestDir
mv * $NZBPR_DestDir >/dev/null 2>&1
cd ..
rmdir $NZBPP_DIRECTORY
NZBPP_DIRECTORY=$NZBPR_DestDir
cd "$NZBPP_DIRECTORY"
fi
# All OK, requesting cleaning up of download queue
do_exit $POSTPROCESS_SUCCESS
#!/bin/sh
# -*- coding: cp1252 -*-
#
# Example postprocessing script for NZBGet
#
# Copyright (C) 2008 Peter Roubos <peterroubos@hotmail.com>
# Copyright (C) 2008 Otmar Werner
# Copyright (C) 2008-2012 Andrei Prygunkov <hugbug@users.sourceforge.net>
# Copyright (C) 2012 Antoine Bertin <diaoulael@gmail.com>
# Copyright (C) 2012 J<>rgen Seif <thor78@gmx.at>
#
# 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
# Postprocessing function for nzbToCouchPotato and nzbToSickBeard
nzbToMedia() {
if [ "$Debug" = "yes" ]; then echo "[DETAIL] Post-Process: Executing external postprocessing with argument $1" ; fi
PostProcessStatus=0
if [ -n "$1" ]; then PostProcessStatus=$1 ; fi
if [ "$Debug" = "yes" ]; then echo "[DETAIL] Post-Process: comparing '$NZBPP_CATEGORY' to '$CouchPotatoCategory' and '$SickBeardCategory'" ; fi
if [ "$NZBPP_CATEGORY" = "$CouchPotatoCategory" ]; then
if [ "$CouchPotato" = "yes" -a -e "$NzbToCouchPotato" ]; then
script=$NzbToCouchPotato
# Call Couchpotato's postprocessing script
echo "[INFO] Post-Process: Running CouchPotato's postprocessing script"
if [ "$Debug" = "yes" ]; then
echo "[DETAIL] Post-Process: CouchPotato-Script-Path=$NzbToCouchPotato"
echo "[DETAIL] Post-Process: CouchPotato-Script-ARGV1=$NZBPP_DIRECTORY"
echo "[DETAIL] Post-Process: CouchPotato-Script-ARGV2=$NZBPP_NZBFILENAME"
echo "[DETAIL] Post-Process: CouchPotato-Script-ARGV3=$PostProcessStatus"
fi
$PythonCmd $NzbToCouchPotato "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "$PostProcessStatus" | while read line ; do if [ "$line" != "" ] ; then echo "[INFO] Post-Process: $line" ; fi ; done
else
if [ "$CouchPotato" != "yes" ]; then echo "[DETAIL] Post-Process: Ignored to run CouchPotato's postprocessing script as it is disabled by user ('$CouchPotato')"; fi
if [ ! -e "$NzbToCouchPotato" ]; then echo "[DETAIL] Post-Process: Ignored to run CouchPotato's postprocessing script as the specified script ('$NzbToCouchPotato') does not exist"; fi
fi
fi
if [ "$NZBPP_CATEGORY" = "$SickBeardCategory" ]; then
if [ "$SickBeard" = "yes" -a -e "$NzbToSickBeard" ]; then
script=$NzbToSickBeard
# Call SickBeard's postprocessing script
echo "[INFO] Post-Process: Running SickBeard's postprocessing script"
if [ "$Debug" = "yes" ]; then
echo "[DETAIL] Post-Process: SickBeard-Script-Path=$NzbToSickBeard"
echo "[DETAIL] Post-Process: SickBeard-Script-ARGV1=$NZBPP_DIRECTORY"
echo "[DETAIL] Post-Process: SickBeard-Script-ARGV2=$NZBPP_NZBFILENAME"
echo "[DETAIL] Post-Process: SickBeard-Script-ARGV3=$PostProcessStatus"
fi
$PythonCmd $NzbToSickBeard "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "$PostProcessStatus" | while read line ; do if [ "$line" != "" ] ; then echo "[INFO] Post-Process: $line" ; fi ; done
else
if [ "$SickBeard" != "yes" ]; then echo "[DETAIL] Post-Process: Ignored to run SickBeard's postprocessing script as it is disabled by user ('$SickBeard')"; fi
if [ ! -e "$NzbToSickBeard" ]; then echo "[DETAIL] Post-Process: Ignored to run SickBeard's postprocessing script as the specified script ('$NzbToSickBeard') does not exist"; fi
fi
fi
if [ "$NZBPP_CATEGORY" = "$CustomCategory" ]; then
if [ "$Custom" = "yes" -a -e "$CustomScript" ]; then
script=$CustomScript
# Call Custom postprocessing script
echo "[INFO] Post-Process: Running the Custom postprocessing script"
if [ "$Debug" = "yes" ]; then
echo "[DETAIL] Post-Process: Custom-Script-Path=$CustomScript"
echo "[DETAIL] Post-Process: Custom-Script-ARGV1=$NZBPP_DIRECTORY"
echo "[DETAIL] Post-Process: Custom-Script-ARGV2=$NZBPP_NZBFILENAME"
echo "[DETAIL] Post-Process: Custom-Script-ARGV3=$PostProcessStatus"
fi
$CustomCmd $CustomScript "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "$PostProcessStatus" | while read line ; do if [ "$line" != "" ] ; then echo "[INFO] Post-Process: $line" ; fi ; done
else
if [ "$Custom" != "yes" ]; then echo "[DETAIL] Post-Process: Ignored to run the Custom postprocessing script as it is disabled by user ('$Custom')"; fi
if [ ! -e "$CustomScript" ]; then echo "[DETAIL] Post-Process: Ignored to run the Custom postprocessing script as the specified script ('$CustomScript') does not exist"; fi
fi
fi
}
# Pass on postprocess exit codes to external scripts for handling failed downloads
do_exit() {
if [ "$Debug" = "yes" ]; then echo "[DETAIL] Post-Process: Executing function 'do_exit' with argument $1" ; fi
nzbStatus=0
if [ "$1" -ne "$POSTPROCESS_SUCCESS" ]; then nzbStatus=1 ; fi
script=none
nzbToMedia $nzbStatus
Email_Subject="${Email_Subject/<name>/$NZBPP_NZBFILENAME}"
Email_Subject="${Email_Subject/<cat>/$NZBPP_CATEGORY}"
Email_Subject="${Email_Subject/<script>/$script}"
Email_Message="${Email_Message/<name>/$NZBPP_NZBFILENAME}"
Email_Message="${Email_Message/<cat>/$NZBPP_CATEGORY}"
Email_Message="${Email_Message/<script>/$script}"
if [ "$Email_successful" = "yes" -a "$nzbStatus" = 0 ]; then
User=""
if [ -n "$Email_User" -a -n "$Email_Pass" ]; then User="-xu $Email_User -xp $Email_Pass" ; fi
Email_Subject="${Email_Subject/<status>/completed}"
Email_Message="${Email_Message/<status>/completed}"
$sendEmail -f "$Email_From" -t "$Email_To" -s "$Email_Server" $User -u "$Email_Subject" -m "$Email_Message"
fi
if [ "$Email_failed" = "yes" -a "$nzbStatus" != 0 ]; then
User=""
if [ -n "$Email_User" -a -n "$Email_Pass" ]; then User="-xu $Email_User -xp $Email_Pass" ; fi
Email_Subject="${Email_Subject/<status>/failed}"
Email_Message="${Email_Message/<status>/failed}"
$sendEmail -f "$Email_From" -t "$Email_To" -s "$Email_Server" $User -u "$Email_Subject" -m "$Email_Message"
fi
exit $1
}
# 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 <ID>"
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
do_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"
do_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"
do_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"
do_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"
do_exit $POSTPROCESS_PARCHECK_ALL
fi
do_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"
do_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 .
# Clean up list, space seperated array from GUI
for item in ${FileCleanUp[*]} ; do rm $item >/dev/null 2>&1 ; done
# Removed by default
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/your_directory and remove download destination directory
# Test for category and ensure the passed directory exists as a directory.
if [ "$NZBPP_CATEGORY" = "$SickBeardCategory" -a -d "$TvDownloadDir" ]; then
echo "[INFO] Post-Process: Moving TV shows to $TvDownloadDir"
cp -R "$NZBPP_DIRECTORY" "$TvDownloadDir"
if [ "$?" -ne 0 ]; then
echo "[ERROR] Post-Process: Moving to $TvDownloadDir"
exit $POSTPROCESS_ERROR
else
rm -fr *
cd ..
rmdir "$NZBPP_DIRECTORY"
NZBPP_DIRECTORY="$TvDownloadDir"
cd "$NZBPP_DIRECTORY"
fi
fi
# Test for category and ensure the passed directory exists as a directory.
if [ "$NZBPP_CATEGORY" = "$CouchPotatoCategory" -a -d "$MoviesDownloadDir" ]; then
echo "[INFO] Post-Process: Moving Movies to $MoviesDownloadDir"
cp -R "$NZBPP_DIRECTORY" "$MoviesDownloadDir"
if [ "$?" -ne 0 ]; then
echo "[ERROR] Post-Process: Moving to $MoviesDownloadDir"
exit $POSTPROCESS_ERROR
else
rm -fr *
cd ..
rmdir "$NZBPP_DIRECTORY"
NZBPP_DIRECTORY="$MoviesDownloadDir"
cd "$NZBPP_DIRECTORY"
fi
fi
# Test for category and ensure the passed directory exists as a directory.
if [ "$NZBPP_CATEGORY" = "$CustomCategory" -a -d "$CustomDownloadDir" ]; then
echo "[INFO] Post-Process: Moving $CustomCategory to $CustomDownloadDir"
cp -R "$NZBPP_DIRECTORY" "$CustomDownloadDir"
if [ "$?" -ne 0 ]; then
echo "[ERROR] Post-Process: Moving to $CustomDownloadDir"
exit $POSTPROCESS_ERROR
else
rm -fr *
cd ..
rmdir "$NZBPP_DIRECTORY"
NZBPP_DIRECTORY="$CustomDownloadDir"
cd "$NZBPP_DIRECTORY"
fi
fi
##########################
### END CUSTOMIZATIONS ###
##########################
# 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 <ID>"
if [ "$NZBPR_DestDir" != "" ]; then
mkdir $NZBPR_DestDir
mv * $NZBPR_DestDir >/dev/null 2>&1
cd ..
rmdir $NZBPP_DIRECTORY
NZBPP_DIRECTORY=$NZBPR_DestDir
cd "$NZBPP_DIRECTORY"
fi
# All OK, requesting cleaning up of download queue
do_exit $POSTPROCESS_SUCCESS

View file

@ -1,477 +1,477 @@
#!/bin/sh
# -*- coding: cp1252 -*-
#
# Example postprocessing script for NZBGet
#
# Copyright (C) 2008 Peter Roubos <peterroubos@hotmail.com>
# Copyright (C) 2008 Otmar Werner
# Copyright (C) 2008-2012 Andrei Prygunkov <hugbug@users.sourceforge.net>
# Copyright (C) 2012 Antoine Bertin <diaoulael@gmail.com>
# Copyright (C) 2012 J<>rgen Seif <thor78@gmx.at>
#
# 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="nzbget-postprocess.conf"
# Exit codes
POSTPROCESS_PARCHECK_CURRENT=91
POSTPROCESS_PARCHECK_ALL=92
POSTPROCESS_SUCCESS=93
POSTPROCESS_ERROR=94
POSTPROCESS_NONE=95
# Postprocessing function for nzbToCouchPotato and nzbToSickBeard
nzbToMedia() {
if [ "$Debug" = "yes" ]; then echo "[DETAIL] Post-Process: Executing external postprocessing with argument $1" ; fi
PostProcessStatus=0
if [ -n "$1" ]; then PostProcessStatus=$1 ; fi
if [ "$Debug" = "yes" ]; then echo "[DETAIL] Post-Process: comparing '$NZBPP_CATEGORY' to '$CouchPotatoCategory' and '$SickBeardCategory'" ; fi
if [ "$NZBPP_CATEGORY" = "$CouchPotatoCategory" ]; then
if [ "$CouchPotato" = "yes" -a -e "$NzbToCouchPotato" ]; then
script=$NzbToCouchPotato
# Call Couchpotato's postprocessing script
echo "[INFO] Post-Process: Running CouchPotato's postprocessing script"
if [ "$Debug" = "yes" ]; then
echo "[DETAIL] Post-Process: CouchPotato-Script-Path=$NzbToCouchPotato"
echo "[DETAIL] Post-Process: CouchPotato-Script-ARGV1=$NZBPP_DIRECTORY"
echo "[DETAIL] Post-Process: CouchPotato-Script-ARGV2=$NZBPP_NZBFILENAME"
echo "[DETAIL] Post-Process: CouchPotato-Script-ARGV3=$PostProcessStatus"
fi
$PythonCmd $NzbToCouchPotato "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "$PostProcessStatus" | while read line ; do if [ "$line" != "" ] ; then echo "[INFO] Post-Process: $line" ; fi ; done
else
if [ "$CouchPotato" != "yes" ]; then echo "[DETAIL] Post-Process: Ignored to run CouchPotato's postprocessing script as it is disabled by user ('$CouchPotato')"; fi
if [ ! -e "$NzbToCouchPotato" ]; then echo "[DETAIL] Post-Process: Ignored to run CouchPotato's postprocessing script as the specified script ('$NzbToCouchPotato') does not exist"; fi
fi
fi
if [ "$NZBPP_CATEGORY" = "$SickBeardCategory" ]; then
if [ "$SickBeard" = "yes" -a -e "$NzbToSickBeard" ]; then
script=$NzbToSickBeard
# Call SickBeard's postprocessing script
echo "[INFO] Post-Process: Running SickBeard's postprocessing script"
if [ "$Debug" = "yes" ]; then
echo "[DETAIL] Post-Process: SickBeard-Script-Path=$NzbToSickBeard"
echo "[DETAIL] Post-Process: SickBeard-Script-ARGV1=$NZBPP_DIRECTORY"
echo "[DETAIL] Post-Process: SickBeard-Script-ARGV2=$NZBPP_NZBFILENAME"
echo "[DETAIL] Post-Process: SickBeard-Script-ARGV3=$PostProcessStatus"
fi
$PythonCmd $NzbToSickBeard "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "$PostProcessStatus" | while read line ; do if [ "$line" != "" ] ; then echo "[INFO] Post-Process: $line" ; fi ; done
else
if [ "$SickBeard" != "yes" ]; then echo "[DETAIL] Post-Process: Ignored to run SickBeard's postprocessing script as it is disabled by user ('$SickBeard')"; fi
if [ ! -e "$NzbToSickBeard" ]; then echo "[DETAIL] Post-Process: Ignored to run SickBeard's postprocessing script as the specified script ('$NzbToSickBeard') does not exist"; fi
fi
fi
if [ "$NZBPP_CATEGORY" = "$CustomCategory" ]; then
if [ "$Custom" = "yes" -a -e "$CustomScript" ]; then
script=$CustomScript
# Call Custom postprocessing script
echo "[INFO] Post-Process: Running the Custom postprocessing script"
if [ "$Debug" = "yes" ]; then
echo "[DETAIL] Post-Process: Custom-Script-Path=$CustomScript"
echo "[DETAIL] Post-Process: Custom-Script-ARGV1=$NZBPP_DIRECTORY"
echo "[DETAIL] Post-Process: Custom-Script-ARGV2=$NZBPP_NZBFILENAME"
echo "[DETAIL] Post-Process: Custom-Script-ARGV3=$PostProcessStatus"
fi
$CustomCmd $CustomScript "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "$PostProcessStatus" | while read line ; do if [ "$line" != "" ] ; then echo "[INFO] Post-Process: $line" ; fi ; done
else
if [ "$Custom" != "yes" ]; then echo "[DETAIL] Post-Process: Ignored to run the Custom postprocessing script as it is disabled by user ('$Custom')"; fi
if [ ! -e "$CustomScript" ]; then echo "[DETAIL] Post-Process: Ignored to run the Custom postprocessing script as the specified script ('$CustomScript') does not exist"; fi
fi
fi
}
# Pass on postprocess exit codes to external scripts for handling failed downloads
do_exit() {
if [ "$Debug" = "yes" ]; then echo "[DETAIL] Post-Process: Executing function 'do_exit' with argument $1" ; fi
nzbStatus=0
if [ "$1" -ne "$POSTPROCESS_SUCCESS" ]; then nzbStatus=1 ; fi
script=none
nzbToMedia $nzbStatus
Email_Subject="${Email_Subject/<name>/$NZBPP_NZBFILENAME}"
Email_Subject="${Email_Subject/<cat>/$NZBPP_CATEGORY}"
Email_Subject="${Email_Subject/<script>/$script}"
Email_Message="${Email_Message/<name>/$NZBPP_NZBFILENAME}"
Email_Message="${Email_Message/<cat>/$NZBPP_CATEGORY}"
Email_Message="${Email_Message/<script>/$script}"
if [ "$Email_successful" = "yes" -a "$nzbStatus" = 0 ]; then
User=""
if [ -n "$Email_User" -a -n "$Email_Pass" ]; then User="-xu $Email_User -xp $Email_Pass" ; fi
Email_Subject="${Email_Subject/<status>/completed}"
Email_Message="${Email_Message/<status>/completed}"
$sendEmail -f "$Email_From" -t "$Email_To" -s "$Email_Server" $User -u "$Email_Subject" -m "$Email_Message"
fi
if [ "$Email_failed" = "yes" -a "$nzbStatus" != 0 ]; then
User=""
if [ -n "$Email_User" -a -n "$Email_Pass" ]; then User="-xu $Email_User -xp $Email_Pass" ; fi
Email_Subject="${Email_Subject/<status>/failed}"
Email_Message="${Email_Message/<status>/failed}"
$sendEmail -f "$Email_From" -t "$Email_To" -s "$Email_Server" $User -u "$Email_Subject" -m "$Email_Message"
fi
exit $1
}
# 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 <ID>"
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
do_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"
do_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"
do_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"
do_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"
do_exit $POSTPROCESS_PARCHECK_ALL
fi
do_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"
do_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 .
# Clean up list, space seperated array from GUI
for item in ${FileCleanUp[*]} ; do rm $item >/dev/null 2>&1 ; done
# Removed by default
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/your_directory and remove download destination directory
# Test for category and ensure the passed directory exists as a directory.
if [ "$NZBPP_CATEGORY" = "$SickBeardCategory" -a -d "$TvDownloadDir" ]; then
echo "[INFO] Post-Process: Moving TV shows to $TvDownloadDir"
cp -R "$NZBPP_DIRECTORY" "$TvDownloadDir"
if [ "$?" -ne 0 ]; then
echo "[ERROR] Post-Process: Moving to $TvDownloadDir"
exit $POSTPROCESS_ERROR
else
rm -fr *
cd ..
rmdir "$NZBPP_DIRECTORY"
NZBPP_DIRECTORY="$TvDownloadDir"
cd "$NZBPP_DIRECTORY"
fi
fi
# Test for category and ensure the passed directory exists as a directory.
if [ "$NZBPP_CATEGORY" = "$CouchPotatoCategory" -a -d "$MoviesDownloadDir" ]; then
echo "[INFO] Post-Process: Moving Movies to $MoviesDownloadDir"
cp -R "$NZBPP_DIRECTORY" "$MoviesDownloadDir"
if [ "$?" -ne 0 ]; then
echo "[ERROR] Post-Process: Moving to $MoviesDownloadDir"
exit $POSTPROCESS_ERROR
else
rm -fr *
cd ..
rmdir "$NZBPP_DIRECTORY"
NZBPP_DIRECTORY="$MoviesDownloadDir"
cd "$NZBPP_DIRECTORY"
fi
fi
# Test for category and ensure the passed directory exists as a directory.
if [ "$NZBPP_CATEGORY" = "$CustomCategory" -a -d "$CustomDownloadDir" ]; then
echo "[INFO] Post-Process: Moving $CustomCategory to $CustomDownloadDir"
cp -R "$NZBPP_DIRECTORY" "$CustomDownloadDir"
if [ "$?" -ne 0 ]; then
echo "[ERROR] Post-Process: Moving to $CustomDownloadDir"
exit $POSTPROCESS_ERROR
else
rm -fr *
cd ..
rmdir "$NZBPP_DIRECTORY"
NZBPP_DIRECTORY="$CustomDownloadDir"
cd "$NZBPP_DIRECTORY"
fi
fi
##########################
### END CUSTOMIZATIONS ###
##########################
# 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 <ID>"
if [ "$NZBPR_DestDir" != "" ]; then
mkdir $NZBPR_DestDir
mv * $NZBPR_DestDir >/dev/null 2>&1
cd ..
rmdir $NZBPP_DIRECTORY
NZBPP_DIRECTORY=$NZBPR_DestDir
cd "$NZBPP_DIRECTORY"
fi
# All OK, requesting cleaning up of download queue
do_exit $POSTPROCESS_SUCCESS
#!/bin/sh
# -*- coding: cp1252 -*-
#
# Example postprocessing script for NZBGet
#
# Copyright (C) 2008 Peter Roubos <peterroubos@hotmail.com>
# Copyright (C) 2008 Otmar Werner
# Copyright (C) 2008-2012 Andrei Prygunkov <hugbug@users.sourceforge.net>
# Copyright (C) 2012 Antoine Bertin <diaoulael@gmail.com>
# Copyright (C) 2012 J<>rgen Seif <thor78@gmx.at>
#
# 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="nzbget-postprocess.conf"
# Exit codes
POSTPROCESS_PARCHECK_CURRENT=91
POSTPROCESS_PARCHECK_ALL=92
POSTPROCESS_SUCCESS=93
POSTPROCESS_ERROR=94
POSTPROCESS_NONE=95
# Postprocessing function for nzbToCouchPotato and nzbToSickBeard
nzbToMedia() {
if [ "$Debug" = "yes" ]; then echo "[DETAIL] Post-Process: Executing external postprocessing with argument $1" ; fi
PostProcessStatus=0
if [ -n "$1" ]; then PostProcessStatus=$1 ; fi
if [ "$Debug" = "yes" ]; then echo "[DETAIL] Post-Process: comparing '$NZBPP_CATEGORY' to '$CouchPotatoCategory' and '$SickBeardCategory'" ; fi
if [ "$NZBPP_CATEGORY" = "$CouchPotatoCategory" ]; then
if [ "$CouchPotato" = "yes" -a -e "$NzbToCouchPotato" ]; then
script=$NzbToCouchPotato
# Call Couchpotato's postprocessing script
echo "[INFO] Post-Process: Running CouchPotato's postprocessing script"
if [ "$Debug" = "yes" ]; then
echo "[DETAIL] Post-Process: CouchPotato-Script-Path=$NzbToCouchPotato"
echo "[DETAIL] Post-Process: CouchPotato-Script-ARGV1=$NZBPP_DIRECTORY"
echo "[DETAIL] Post-Process: CouchPotato-Script-ARGV2=$NZBPP_NZBFILENAME"
echo "[DETAIL] Post-Process: CouchPotato-Script-ARGV3=$PostProcessStatus"
fi
$PythonCmd $NzbToCouchPotato "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "$PostProcessStatus" | while read line ; do if [ "$line" != "" ] ; then echo "[INFO] Post-Process: $line" ; fi ; done
else
if [ "$CouchPotato" != "yes" ]; then echo "[DETAIL] Post-Process: Ignored to run CouchPotato's postprocessing script as it is disabled by user ('$CouchPotato')"; fi
if [ ! -e "$NzbToCouchPotato" ]; then echo "[DETAIL] Post-Process: Ignored to run CouchPotato's postprocessing script as the specified script ('$NzbToCouchPotato') does not exist"; fi
fi
fi
if [ "$NZBPP_CATEGORY" = "$SickBeardCategory" ]; then
if [ "$SickBeard" = "yes" -a -e "$NzbToSickBeard" ]; then
script=$NzbToSickBeard
# Call SickBeard's postprocessing script
echo "[INFO] Post-Process: Running SickBeard's postprocessing script"
if [ "$Debug" = "yes" ]; then
echo "[DETAIL] Post-Process: SickBeard-Script-Path=$NzbToSickBeard"
echo "[DETAIL] Post-Process: SickBeard-Script-ARGV1=$NZBPP_DIRECTORY"
echo "[DETAIL] Post-Process: SickBeard-Script-ARGV2=$NZBPP_NZBFILENAME"
echo "[DETAIL] Post-Process: SickBeard-Script-ARGV3=$PostProcessStatus"
fi
$PythonCmd $NzbToSickBeard "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "$PostProcessStatus" | while read line ; do if [ "$line" != "" ] ; then echo "[INFO] Post-Process: $line" ; fi ; done
else
if [ "$SickBeard" != "yes" ]; then echo "[DETAIL] Post-Process: Ignored to run SickBeard's postprocessing script as it is disabled by user ('$SickBeard')"; fi
if [ ! -e "$NzbToSickBeard" ]; then echo "[DETAIL] Post-Process: Ignored to run SickBeard's postprocessing script as the specified script ('$NzbToSickBeard') does not exist"; fi
fi
fi
if [ "$NZBPP_CATEGORY" = "$CustomCategory" ]; then
if [ "$Custom" = "yes" -a -e "$CustomScript" ]; then
script=$CustomScript
# Call Custom postprocessing script
echo "[INFO] Post-Process: Running the Custom postprocessing script"
if [ "$Debug" = "yes" ]; then
echo "[DETAIL] Post-Process: Custom-Script-Path=$CustomScript"
echo "[DETAIL] Post-Process: Custom-Script-ARGV1=$NZBPP_DIRECTORY"
echo "[DETAIL] Post-Process: Custom-Script-ARGV2=$NZBPP_NZBFILENAME"
echo "[DETAIL] Post-Process: Custom-Script-ARGV3=$PostProcessStatus"
fi
$CustomCmd $CustomScript "$NZBPP_DIRECTORY" "$NZBPP_NZBFILENAME" "$PostProcessStatus" | while read line ; do if [ "$line" != "" ] ; then echo "[INFO] Post-Process: $line" ; fi ; done
else
if [ "$Custom" != "yes" ]; then echo "[DETAIL] Post-Process: Ignored to run the Custom postprocessing script as it is disabled by user ('$Custom')"; fi
if [ ! -e "$CustomScript" ]; then echo "[DETAIL] Post-Process: Ignored to run the Custom postprocessing script as the specified script ('$CustomScript') does not exist"; fi
fi
fi
}
# Pass on postprocess exit codes to external scripts for handling failed downloads
do_exit() {
if [ "$Debug" = "yes" ]; then echo "[DETAIL] Post-Process: Executing function 'do_exit' with argument $1" ; fi
nzbStatus=0
if [ "$1" -ne "$POSTPROCESS_SUCCESS" ]; then nzbStatus=1 ; fi
script=none
nzbToMedia $nzbStatus
Email_Subject="${Email_Subject/<name>/$NZBPP_NZBFILENAME}"
Email_Subject="${Email_Subject/<cat>/$NZBPP_CATEGORY}"
Email_Subject="${Email_Subject/<script>/$script}"
Email_Message="${Email_Message/<name>/$NZBPP_NZBFILENAME}"
Email_Message="${Email_Message/<cat>/$NZBPP_CATEGORY}"
Email_Message="${Email_Message/<script>/$script}"
if [ "$Email_successful" = "yes" -a "$nzbStatus" = 0 ]; then
User=""
if [ -n "$Email_User" -a -n "$Email_Pass" ]; then User="-xu $Email_User -xp $Email_Pass" ; fi
Email_Subject="${Email_Subject/<status>/completed}"
Email_Message="${Email_Message/<status>/completed}"
$sendEmail -f "$Email_From" -t "$Email_To" -s "$Email_Server" $User -u "$Email_Subject" -m "$Email_Message"
fi
if [ "$Email_failed" = "yes" -a "$nzbStatus" != 0 ]; then
User=""
if [ -n "$Email_User" -a -n "$Email_Pass" ]; then User="-xu $Email_User -xp $Email_Pass" ; fi
Email_Subject="${Email_Subject/<status>/failed}"
Email_Message="${Email_Message/<status>/failed}"
$sendEmail -f "$Email_From" -t "$Email_To" -s "$Email_Server" $User -u "$Email_Subject" -m "$Email_Message"
fi
exit $1
}
# 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 <ID>"
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
do_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"
do_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"
do_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"
do_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"
do_exit $POSTPROCESS_PARCHECK_ALL
fi
do_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"
do_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 .
# Clean up list, space seperated array from GUI
for item in ${FileCleanUp[*]} ; do rm $item >/dev/null 2>&1 ; done
# Removed by default
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/your_directory and remove download destination directory
# Test for category and ensure the passed directory exists as a directory.
if [ "$NZBPP_CATEGORY" = "$SickBeardCategory" -a -d "$TvDownloadDir" ]; then
echo "[INFO] Post-Process: Moving TV shows to $TvDownloadDir"
cp -R "$NZBPP_DIRECTORY" "$TvDownloadDir"
if [ "$?" -ne 0 ]; then
echo "[ERROR] Post-Process: Moving to $TvDownloadDir"
exit $POSTPROCESS_ERROR
else
rm -fr *
cd ..
rmdir "$NZBPP_DIRECTORY"
NZBPP_DIRECTORY="$TvDownloadDir"
cd "$NZBPP_DIRECTORY"
fi
fi
# Test for category and ensure the passed directory exists as a directory.
if [ "$NZBPP_CATEGORY" = "$CouchPotatoCategory" -a -d "$MoviesDownloadDir" ]; then
echo "[INFO] Post-Process: Moving Movies to $MoviesDownloadDir"
cp -R "$NZBPP_DIRECTORY" "$MoviesDownloadDir"
if [ "$?" -ne 0 ]; then
echo "[ERROR] Post-Process: Moving to $MoviesDownloadDir"
exit $POSTPROCESS_ERROR
else
rm -fr *
cd ..
rmdir "$NZBPP_DIRECTORY"
NZBPP_DIRECTORY="$MoviesDownloadDir"
cd "$NZBPP_DIRECTORY"
fi
fi
# Test for category and ensure the passed directory exists as a directory.
if [ "$NZBPP_CATEGORY" = "$CustomCategory" -a -d "$CustomDownloadDir" ]; then
echo "[INFO] Post-Process: Moving $CustomCategory to $CustomDownloadDir"
cp -R "$NZBPP_DIRECTORY" "$CustomDownloadDir"
if [ "$?" -ne 0 ]; then
echo "[ERROR] Post-Process: Moving to $CustomDownloadDir"
exit $POSTPROCESS_ERROR
else
rm -fr *
cd ..
rmdir "$NZBPP_DIRECTORY"
NZBPP_DIRECTORY="$CustomDownloadDir"
cd "$NZBPP_DIRECTORY"
fi
fi
##########################
### END CUSTOMIZATIONS ###
##########################
# 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 <ID>"
if [ "$NZBPR_DestDir" != "" ]; then
mkdir $NZBPR_DestDir
mv * $NZBPR_DestDir >/dev/null 2>&1
cd ..
rmdir $NZBPP_DIRECTORY
NZBPP_DIRECTORY=$NZBPR_DestDir
cd "$NZBPP_DIRECTORY"
fi
# All OK, requesting cleaning up of download queue
do_exit $POSTPROCESS_SUCCESS

View file

@ -1,120 +1,120 @@
sendEmail - Send email from a console near you!
Written by: Brandon Zehm <caspian@dotconf.net>
http://caspian.dotconf.net/
http://www.tsheets.com/
// Language: Portuguese (Brazil)
// Traduzido por: nogueira_jr@ig.com.br
-----------------
Instru‡äes de uso
-----------------
sendEmail-1.55 by Brandon Zehm <caspian@dotconf.net>
Comando: sendEmail -f ENDERE€O [op‡äes]
Necess rio:
-f ENDERE€O endere‡o de quem est  enviando o email
* Pelo menos um destinat rio, via -t, -cc, ou -bcc
* Corpo da mensagem, via -m, STDIN, ou -o message-file=FILE
Comum:
-t ENDERE€O [ENDERE€OS...] destinat rio(s)
-u "ASSUNTO" assunto da mensagem
-m "MENSAGEM" corpo da mensagem
-s SERVER[:PORT] servidor smtp, default e' a porta localhost:25
Opcional:
-a ARQ [ARQ...] Arquivo(s) anexado
-cc ENDERE€O [ENDERE€O...] cc endere‡os(s)
-bcc ENDERE€O [ENDERE€O...] bcc endere‡o(s)
-xu USUARIO nome do usuario para autentica‡Æo
-xp SENHA senha para autentica‡Æo
Extras:
-b BINDADDR[:PORT] endere‡o do host local bind
-l ARQLOG fazer LOG no arquivo indicado
-v verbal, use v rias vezes para grandes efeitos
-q silencioso (nÆo ecoa saidas)
-o NOME=VALOR op‡äes avan‡adas, para detalhes use: --help misc
-o message-content-type=<auto|text|html>
-o message-file=ARQUIVO -o message-format=RAW
-o message-header=HEADER -o message-charset=CHARSET
-o reply-to=ENDERE€O -o timeout=SEGUNDOS
-o username=USUARIO -o password=SENHA
-o tls=<auto|yes|no> -o fqdn=FQDN
Help:
--help informa‡äes gerais (que voce le agora)
--help addressing detalhes de endere‡os e suas op‡äes
--help message detalhes do corpo da mensagem e suas op‡äes
--help networking detalhes -s, -b, etc
--help output detalhes de saidas e suas op‡äes
--help misc detalhes op‡Æo -o, TLS, autent SMTP auth etc
---------------
Exemplos
---------------
Simples Email:
sendEmail -f myaddress@isp.net \
-t nogueira_jr@ig.com.br \
-s relay.isp.net \
-u "Teste email" \
-m "Ola, isso e' um teste de email."
Enviando para v rias pessoas:
sendEmail -f myaddress@isp.net \
-t "Scott Thomas <scott@isp.net>" nogueira_jr@ig.com.br renee@isp.net \
-s relay.isp.net \
-u "Teste email" \
-m "Ola, isso e' um teste de email."
Enviando para v rias pessoas e enviando copias cc e bcc:
(existe diferentes formas de enviar para varios destinatarios, usando TO
mas voce pode usar CC e BCC para destinatarios tambem)
sendEmail -f myaddress@isp.net \
-t scott@isp.net;jason@isp.net;nogueira_jr@ig.com.br \
-cc jennifer@isp.net paul@isp.net jeremiah@isp.net \
-bcc troy@isp.net miranda@isp.net jay@isp.net \
-s relay.isp.net \
-u "Teste email com copias cc e bcc" \
-m "Ola, isso e' um teste de email."
Enviando para v rias pessoas com v rios anexos:
sendEmail -f myaddress@isp.net \
-t nogueira_jr@ig.com.br \
-cc jennifer@isp.net paul@isp.net jeremiah@isp.net \
-s relay.isp.net \
-u "Teste email com c¢pias cc e bcc" \
-m "Ola, isso e' um teste de email."
-a /mnt/storage/document.sxw "/root/My Documents/Work Schedule.kwd"
Enviando um email com o conteudo de um arquivo no corpo da mensagem:
cat /tmp/file.txt | sendEmail -f myaddress@isp.net \
-t nogueira_jr@ig.com.br \
-s relay.isp.net \
-u "Ola, isso e' um teste de email com anexo."
Enviando um email com o conteudo de um arquivo no corpo da mensagem (mtodo 2):
sendEmail -f myaddress@isp.net \
-t nogueira_jr@ig.com.br \
-s relay.isp.net \
-o message-file=/tmp/file.txt \
-u "Ola, isso e' um teste de email com anexo."
Enviando um email HTML: (certifique-se que o arquivo tem <html> no in¡cio)
cat /tmp/file.html | sendEmail -f myaddress@isp.net \
-t nogueira_jr@ig.com.br \
-s relay.isp.net \
-u "Ola, isso e' um teste de email com HTML."
sendEmail - Send email from a console near you!
Written by: Brandon Zehm <caspian@dotconf.net>
http://caspian.dotconf.net/
http://www.tsheets.com/
// Language: Portuguese (Brazil)
// Traduzido por: nogueira_jr@ig.com.br
-----------------
Instru‡äes de uso
-----------------
sendEmail-1.55 by Brandon Zehm <caspian@dotconf.net>
Comando: sendEmail -f ENDERE€O [op‡äes]
Necess rio:
-f ENDERE€O endere‡o de quem est  enviando o email
* Pelo menos um destinat rio, via -t, -cc, ou -bcc
* Corpo da mensagem, via -m, STDIN, ou -o message-file=FILE
Comum:
-t ENDERE€O [ENDERE€OS...] destinat rio(s)
-u "ASSUNTO" assunto da mensagem
-m "MENSAGEM" corpo da mensagem
-s SERVER[:PORT] servidor smtp, default e' a porta localhost:25
Opcional:
-a ARQ [ARQ...] Arquivo(s) anexado
-cc ENDERE€O [ENDERE€O...] cc endere‡os(s)
-bcc ENDERE€O [ENDERE€O...] bcc endere‡o(s)
-xu USUARIO nome do usuario para autentica‡Æo
-xp SENHA senha para autentica‡Æo
Extras:
-b BINDADDR[:PORT] endere‡o do host local bind
-l ARQLOG fazer LOG no arquivo indicado
-v verbal, use v rias vezes para grandes efeitos
-q silencioso (nÆo ecoa saidas)
-o NOME=VALOR op‡äes avan‡adas, para detalhes use: --help misc
-o message-content-type=<auto|text|html>
-o message-file=ARQUIVO -o message-format=RAW
-o message-header=HEADER -o message-charset=CHARSET
-o reply-to=ENDERE€O -o timeout=SEGUNDOS
-o username=USUARIO -o password=SENHA
-o tls=<auto|yes|no> -o fqdn=FQDN
Help:
--help informa‡äes gerais (que voce le agora)
--help addressing detalhes de endere‡os e suas op‡äes
--help message detalhes do corpo da mensagem e suas op‡äes
--help networking detalhes -s, -b, etc
--help output detalhes de saidas e suas op‡äes
--help misc detalhes op‡Æo -o, TLS, autent SMTP auth etc
---------------
Exemplos
---------------
Simples Email:
sendEmail -f myaddress@isp.net \
-t nogueira_jr@ig.com.br \
-s relay.isp.net \
-u "Teste email" \
-m "Ola, isso e' um teste de email."
Enviando para v rias pessoas:
sendEmail -f myaddress@isp.net \
-t "Scott Thomas <scott@isp.net>" nogueira_jr@ig.com.br renee@isp.net \
-s relay.isp.net \
-u "Teste email" \
-m "Ola, isso e' um teste de email."
Enviando para v rias pessoas e enviando copias cc e bcc:
(existe diferentes formas de enviar para varios destinatarios, usando TO
mas voce pode usar CC e BCC para destinatarios tambem)
sendEmail -f myaddress@isp.net \
-t scott@isp.net;jason@isp.net;nogueira_jr@ig.com.br \
-cc jennifer@isp.net paul@isp.net jeremiah@isp.net \
-bcc troy@isp.net miranda@isp.net jay@isp.net \
-s relay.isp.net \
-u "Teste email com copias cc e bcc" \
-m "Ola, isso e' um teste de email."
Enviando para v rias pessoas com v rios anexos:
sendEmail -f myaddress@isp.net \
-t nogueira_jr@ig.com.br \
-cc jennifer@isp.net paul@isp.net jeremiah@isp.net \
-s relay.isp.net \
-u "Teste email com c¢pias cc e bcc" \
-m "Ola, isso e' um teste de email."
-a /mnt/storage/document.sxw "/root/My Documents/Work Schedule.kwd"
Enviando um email com o conteudo de um arquivo no corpo da mensagem:
cat /tmp/file.txt | sendEmail -f myaddress@isp.net \
-t nogueira_jr@ig.com.br \
-s relay.isp.net \
-u "Ola, isso e' um teste de email com anexo."
Enviando um email com o conteudo de um arquivo no corpo da mensagem (mtodo 2):
sendEmail -f myaddress@isp.net \
-t nogueira_jr@ig.com.br \
-s relay.isp.net \
-o message-file=/tmp/file.txt \
-u "Ola, isso e' um teste de email com anexo."
Enviando um email HTML: (certifique-se que o arquivo tem <html> no in¡cio)
cat /tmp/file.html | sendEmail -f myaddress@isp.net \
-t nogueira_jr@ig.com.br \
-s relay.isp.net \
-u "Ola, isso e' um teste de email com HTML."