From a2eb80f619f6a8459cede354caa2e6499e5b4319 Mon Sep 17 00:00:00 2001 From: echel0n Date: Sun, 13 Apr 2014 12:27:29 -0700 Subject: [PATCH] Re-added back NZBGet options to our stub files. Added a status check for processed files in HeadPhones. Fixed a bug in HeadPhones with passing params via requests. Fixed SickBeard and CouchPotato conditionals for deleting failed files. --- autoProcessMedia.cfg.spec | 5 +- nzbToCouchPotato.py | 126 ++++++++++++++++++++ nzbToGamez.py | 97 ++++++++++++++++ nzbToHeadPhones.py | 100 ++++++++++++++++ nzbToMedia.py | 33 ++---- nzbToMylar.py | 100 ++++++++++++++++ nzbToNzbDrone.py | 109 +++++++++++++++++ nzbToSickBeard.py | 129 +++++++++++++++++++++ nzbtomedia/autoProcess/autoProcessMovie.py | 29 +++-- nzbtomedia/autoProcess/autoProcessMusic.py | 73 ++++++++---- nzbtomedia/autoProcess/autoProcessTV.py | 23 ++-- nzbtomedia/nzbToMediaUtil.py | 11 ++ 12 files changed, 757 insertions(+), 78 deletions(-) diff --git a/autoProcessMedia.cfg.spec b/autoProcessMedia.cfg.spec index 96e962a5..93c5626e 100644 --- a/autoProcessMedia.cfg.spec +++ b/autoProcessMedia.cfg.spec @@ -23,7 +23,7 @@ method = renamer delete_failed = 0 wait_for = 2 - #### Set the remote path for CouchPotatoServer if its running on a different server then your download client + #### # Set to path where completed downloads go on the remote CouchPotatoServer remote_path = watch_dir = @@ -40,7 +40,6 @@ web_root = ssl = 0 delay = 0 - TimePerGiB = 60 watch_dir = fork = auto delete_failed = 0 @@ -62,7 +61,6 @@ web_root = ssl = 0 delay = 0 - TimePerGiB = 60 watch_dir = delete_failed = 0 nzbExtractionBy = Downloader @@ -80,7 +78,6 @@ ssl = 0 web_root = delay = 65 - TimePerGiB = 60 watch_dir = [Mylar] diff --git a/nzbToCouchPotato.py b/nzbToCouchPotato.py index fe663eaf..aeee8055 100755 --- a/nzbToCouchPotato.py +++ b/nzbToCouchPotato.py @@ -1,5 +1,131 @@ #!/usr/bin/env python # +############################################################################## +### NZBGET POST-PROCESSING SCRIPT ### + +# Post-Process to CouchPotato, SickBeard, NzbDrone, Mylar, Gamez, HeadPhones. +# +# This script sends the download to your automated media management servers. +# +# NOTE: This script requires Python to be installed on your system. + +############################################################################## +### OPTIONS ### + +## General +# +# Set to 1 if you want nzbToMedia to automatically check for and update to the latest version +#auto_update=0 + +## CouchPotato + +# CouchPotato script category. +# +# category that gets called for post-processing with CouchPotatoServer. +#cpsCategory=movie + +# CouchPotato api key. +#cpsapikey= + +# CouchPotato host. +#cpshost=localhost + +# CouchPotato port. +#cpsport=5050 + +# CouchPotato uses ssl (0, 1). +# +# Set to 1 if using ssl, else set to 0. +#cpsssl=0 + +# CouchPotato URL_Base +# +# set this if using a reverse proxy. +#cpsweb_root= + +# CouchPotato watch directory. +# +# set this if CouchPotato and nzbGet are on different systems. +#cpswatch_dir= + +# CouchPotato Postprocess Delay. +# +# must be at least 60 seconds. +#cpsdelay=65 + +# CouchPotato Postprocess Method (renamer, manage). +# +# use "renamer" for CPS renamer (default) or "manage" to call a manage update. +#cpsmethod=renamer + +# CouchPotato Delete Failed Downloads (0, 1). +# +# set to 1 to delete failed, or 0 to leave files in place. +#cpsdelete_failed=0 + +# CouchPotato wait_for +# +# Set the number of minutes to wait after calling the renamer, to check the movie has changed status. +#cpswait_for=2 + +# CouchPotatoServer and NZBGet are a different system (0, 1). +# +# Set to path where completed downloads go on the remote CouchPotatoServer. +#cpsremote_path = + +## Extensions + +# Media Extensions +# +# This is a list of media extensions that are used to verify that the download does contain valid media. +#mediaExtensions=.mkv,.avi,.divx,.xvid,.mov,.wmv,.mp4,.mpg,.mpeg,.vob,.iso + +## Transcoder + +# Transcode (0, 1). +# +# set to 1 to transcode, otherwise set to 0. +#transcode=0 + +# create a duplicate, or replace the original (0, 1). +# +# set to 1 to cretae a new file or 0 to replace the original +#duplicate=1 + +# ignore extensions +# +# list of extensions that won't be transcoded. +#ignoreExtensions=.avi,.mkv + +# ffmpeg output settings. +#outputVideoExtension=.mp4 +#outputVideoCodec=libx264 +#outputVideoPreset=medium +#outputVideoFramerate=24 +#outputVideoBitrate=800k +#outputAudioCodec=libmp3lame +#outputAudioBitrate=128k +#outputSubtitleCodec= + +## WakeOnLan + +# use WOL (0, 1). +# +# set to 1 to send WOL broadcast to the mac and test the server (e.g. xbmc) on the host and port specified. +#wolwake=0 + +# WOL MAC +# +# enter the mac address of the system to be woken. +#wolmac=00:01:2e:2D:64:e1 + +# Set the Host and Port of a server to verify system has woken. +#wolhost=192.168.1.37 +#wolport=80 + +### NZBGET POST-PROCESSING SCRIPT ### +############################################################################## + # Stub file to call nzbToMedia import nzbToMedia diff --git a/nzbToGamez.py b/nzbToGamez.py index fe663eaf..6a022e7a 100755 --- a/nzbToGamez.py +++ b/nzbToGamez.py @@ -1,5 +1,102 @@ #!/usr/bin/env python # +############################################################################## +### NZBGET POST-PROCESSING SCRIPT ### + +# Post-Process to CouchPotato, SickBeard, NzbDrone, Mylar, Gamez, HeadPhones. +# +# This script sends the download to your automated media management servers. +# +# NOTE: This script requires Python to be installed on your system. + +############################################################################## +# +### OPTIONS ### + +## General +# +# Set to 1 if you want nzbToMedia to automatically check for and update to the latest version +#auto_update=0 + +## Gamez + +# Gamez script category. +# +# category that gets called for post-processing with Gamez. +#gzCategory=games + +# Gamez api key. +#gzapikey= + +# Gamez host. +#gzhost=localhost + +# Gamez port. +#gzport=8085 + +# Gamez uses ssl (0, 1). +# +# Set to 1 if using ssl, else set to 0. +#gzssl=0 + +# Gamez web_root +# +# set this if using a reverse proxy. +#gzweb_root= + +## Extensions + +# Media Extensions +# +# This is a list of media extensions that are used to verify that the download does contain valid media. +#mediaExtensions=.mkv,.avi,.divx,.xvid,.mov,.wmv,.mp4,.mpg,.mpeg,.vob,.iso + +## Transcoder + +# Transcode (0, 1). +# +# set to 1 to transcode, otherwise set to 0. +#transcode=0 + +# create a duplicate, or replace the original (0, 1). +# +# set to 1 to cretae a new file or 0 to replace the original +#duplicate=1 + +# ignore extensions +# +# list of extensions that won't be transcoded. +#ignoreExtensions=.avi,.mkv + +# ffmpeg output settings. +#outputVideoExtension=.mp4 +#outputVideoCodec=libx264 +#outputVideoPreset=medium +#outputVideoFramerate=24 +#outputVideoBitrate=800k +#outputAudioCodec=libmp3lame +#outputAudioBitrate=128k +#outputSubtitleCodec= + +## WakeOnLan + +# use WOL (0, 1). +# +# set to 1 to send WOL broadcast to the mac and test the server (e.g. xbmc) on the host and port specified. +#wolwake=0 + +# WOL MAC +# +# enter the mac address of the system to be woken. +#wolmac=00:01:2e:2D:64:e1 + +# Set the Host and Port of a server to verify system has woken. +#wolhost=192.168.1.37 +#wolport=80 + +### NZBGET POST-PROCESSING SCRIPT ### +############################################################################## + # Stub file to call nzbToMedia import nzbToMedia diff --git a/nzbToHeadPhones.py b/nzbToHeadPhones.py index fe663eaf..1e662d0d 100755 --- a/nzbToHeadPhones.py +++ b/nzbToHeadPhones.py @@ -1,5 +1,105 @@ #!/usr/bin/env python # +############################################################################## +### NZBGET POST-PROCESSING SCRIPT ### + +# Post-Process to HeadPhones. +# +# This script sends the download to your automated media management servers. +# +# NOTE: This script requires Python to be installed on your system. + +############################################################################## +### OPTIONS + +## General +# +# Set to 1 if you want nzbToMedia to automatically check for and update to the latest version +#auto_update=0 + +## HeadPhones + +# HeadPhones script category. +# +# category that gets called for post-processing with HeadHones. +#hpCategory=music + +# HeadPhones api key. +#hpapikey= + +# HeadPhones host. +#hphost=localhost + +# HeadPhones port. +#hpport=8181 + +# HeadPhones uses ssl (0, 1). +# +# Set to 1 if using ssl, else set to 0. +#hpssl=0 + +# HeadPhones web_root +# +# set this if using a reverse proxy. +#hpweb_root= + +# HeadPhones Postprocess Delay. +# +# set as required to ensure correct processing. +#hpdelay=65 + +## Extensions + +# Media Extensions +# +# This is a list of media extensions that are used to verify that the download does contain valid media. +#mediaExtensions=.mkv,.avi,.divx,.xvid,.mov,.wmv,.mp4,.mpg,.mpeg,.vob,.iso + +## Transcoder + +# Transcode (0, 1). +# +# set to 1 to transcode, otherwise set to 0. +#transcode=0 + +# create a duplicate, or replace the original (0, 1). +# +# set to 1 to cretae a new file or 0 to replace the original +#duplicate=1 + +# ignore extensions +# +# list of extensions that won't be transcoded. +#ignoreExtensions=.avi,.mkv + +# ffmpeg output settings. +#outputVideoExtension=.mp4 +#outputVideoCodec=libx264 +#outputVideoPreset=medium +#outputVideoFramerate=24 +#outputVideoBitrate=800k +#outputAudioCodec=libmp3lame +#outputAudioBitrate=128k +#outputSubtitleCodec= + +## WakeOnLan + +# use WOL (0, 1). +# +# set to 1 to send WOL broadcast to the mac and test the server (e.g. xbmc) on the host and port specified. +#wolwake=0 + +# WOL MAC +# +# enter the mac address of the system to be woken. +#wolmac=00:01:2e:2D:64:e1 + +# Set the Host and Port of a server to verify system has woken. +#wolhost=192.168.1.37 +#wolport=80 + +### NZBGET POST-PROCESSING SCRIPT ### +############################################################################## # Stub file to call nzbToMedia import nzbToMedia diff --git a/nzbToMedia.py b/nzbToMedia.py index 4e3d93fa..21da803c 100755 --- a/nzbToMedia.py +++ b/nzbToMedia.py @@ -12,6 +12,11 @@ ############################################################################## ### OPTIONS ### +## General +# +# Set to 1 if you want nzbToMedia to automatically check for and update to the latest version +#auto_update=0 + ## CouchPotato # CouchPotato script category. @@ -53,11 +58,6 @@ # set to 1 to delete failed, or 0 to leave files in place. #cpsdelete_failed=0 -# CouchPotato process Time Per GiB -# -# Set the number of seconds to wait, for each GiB of data, before timing out. If transfering files across drives or network, increase this value as needed. -#cpsTimePerGiB=60 - # CouchPotato wait_for # # Set the number of minutes to wait after calling the renamer, to check the movie has changed status. @@ -102,11 +102,6 @@ # Set the number of seconds to wait before calling post-process in SickBeard. #sbdelay=0 -# SickBeard process Time Per GiB -# -# Set the number of seconds to wait, for each GiB of data, before timing out. If transfering files across drives or network, increase this value as needed. -#sbTimePerGiB=60 - # SickBeard watch directory. # # set this if SickBeard and nzbGet are on different systems. @@ -135,26 +130,23 @@ #ndCategory=tv # NzbDrone host. -#ndHost=localhost +#ndhost=localhost # NzbDrone port. -#ndPort=8989 +#ndport=8989 # NzbDrone API key. -#ndAPIKey= +#ndapikey= # NzbDrone uses SSL (0, 1). # # Set to 1 if using SSL, else set to 0. -#ndSSL=0 +#ndssl=0 # NzbDrone web root. # # set this if using a reverse proxy. -#ndWebRoot= - -# Prefer NzbDrone if categories clash (0, 1). -#ndPrefer=0 +#ndweb_root= ## HeadPhones @@ -187,11 +179,6 @@ # set as required to ensure correct processing. #hpdelay=65 -# HeadPhones process Time Per GiB -# -# Set the number of seconds to wait, for each GiB of data, before timing out. If transfering files across drives or network, increase this value as needed. -#hpTimePerGiB=60 - ## Mylar # Mylar script category. diff --git a/nzbToMylar.py b/nzbToMylar.py index fe663eaf..2b2bd9e4 100755 --- a/nzbToMylar.py +++ b/nzbToMylar.py @@ -1,5 +1,105 @@ #!/usr/bin/env python # +############################################################################## +### NZBGET POST-PROCESSING SCRIPT ### + +# Post-Process to Mylar. +# +# This script sends the download to your automated media management servers. +# +# NOTE: This script requires Python to be installed on your system. + +############################################################################## +# +### OPTIONS + +## General +# +# Set to 1 if you want nzbToMedia to automatically check for and update to the latest version +#auto_update=0 + +## Mylar + +# Mylar script category. +# +# category that gets called for post-processing with Mylar. +#myCategory=comics + +# Mylar host. +#myhost=localhost + +# Mylar port. +#myport=8090 + +# Mylar username. +#myusername= + +# Mylar password. +#mypassword= + +# Mylar uses ssl (0, 1). +# +# Set to 1 if using ssl, else set to 0. +#myssl=0 + +# Mylar web_root +# +# set this if using a reverse proxy. +#myweb_root= + +## Extensions + +# Media Extensions +# +# This is a list of media extensions that are used to verify that the download does contain valid media. +#mediaExtensions=.mkv,.avi,.divx,.xvid,.mov,.wmv,.mp4,.mpg,.mpeg,.vob,.iso + +## Transcoder + +# Transcode (0, 1). +# +# set to 1 to transcode, otherwise set to 0. +#transcode=0 + +# create a duplicate, or replace the original (0, 1). +# +# set to 1 to cretae a new file or 0 to replace the original +#duplicate=1 + +# ignore extensions +# +# list of extensions that won't be transcoded. +#ignoreExtensions=.avi,.mkv + +# ffmpeg output settings. +#outputVideoExtension=.mp4 +#outputVideoCodec=libx264 +#outputVideoPreset=medium +#outputVideoFramerate=24 +#outputVideoBitrate=800k +#outputAudioCodec=libmp3lame +#outputAudioBitrate=128k +#outputSubtitleCodec= + +## WakeOnLan + +# use WOL (0, 1). +# +# set to 1 to send WOL broadcast to the mac and test the server (e.g. xbmc) on the host and port specified. +#wolwake=0 + +# WOL MAC +# +# enter the mac address of the system to be woken. +#wolmac=00:01:2e:2D:64:e1 + +# Set the Host and Port of a server to verify system has woken. +#wolhost=192.168.1.37 +#wolport=80 + +### NZBGET POST-PROCESSING SCRIPT ### +############################################################################## + # Stub file to call nzbToMedia import nzbToMedia diff --git a/nzbToNzbDrone.py b/nzbToNzbDrone.py index fe663eaf..c41c72fc 100755 --- a/nzbToNzbDrone.py +++ b/nzbToNzbDrone.py @@ -1,5 +1,114 @@ #!/usr/bin/env python # +############################################################################## +### NZBGET POST-PROCESSING SCRIPT ### + +# Post-Process to NzbDrone. +# +# This script sends the download to your automated media management servers. +# +# NOTE: This script requires Python to be installed on your system. + +############################################################################## +### OPTIONS ### + +## General +# +# Set to 1 if you want nzbToMedia to automatically check for and update to the latest version +#auto_update=0 + +## NzbDrone + +# NzbDrone script category. +# +# category that gets called for post-processing with NzbDrone. +#ndCategory=tv + +# NzbDrone host. +#ndhost=localhost + +# NzbDrone port. +#ndport=8081 + +# NzbDrone username. +#ndusername= + +# NzbDrone password. +#ndpassword= + +# NzbDrone uses ssl (0, 1). +# +# Set to 1 if using ssl, else set to 0. +#ndssl=0 + +# NzbDrone web_root +# +# set this if using a reverse proxy. +#ndweb_root= + +# NzbDrone delay +# +# Set the number of seconds to wait before calling post-process in NzbDrone. +#nddelay=0 + +# NzbDrone watch directory. +# +# set this if NzbDrone and nzbGet are on different systems. +#ndwatch_dir= + +## Extensions + +# Media Extensions +# +# This is a list of media extensions that are used to verify that the download does contain valid media. +#mediaExtensions=.mkv,.avi,.divx,.xvid,.mov,.wmv,.mp4,.mpg,.mpeg,.vob,.iso + +## Transcoder + +# Transcode (0, 1). +# +# set to 1 to transcode, otherwise set to 0. +#transcode=0 + +# create a duplicate, or replace the original (0, 1). +# +# set to 1 to cretae a new file or 0 to replace the original +#duplicate=1 + +# ignore extensions +# +# list of extensions that won't be transcoded. +#ignoreExtensions=.avi,.mkv + +# ffmpeg output settings. +#outputVideoExtension=.mp4 +#outputVideoCodec=libx264 +#outputVideoPreset=medium +#outputVideoFramerate=24 +#outputVideoBitrate=800k +#outputAudioCodec=libmp3lame +#outputAudioBitrate=128k +#outputSubtitleCodec= + +## WakeOnLan + +# use WOL (0, 1). +# +# set to 1 to send WOL broadcast to the mac and test the server (e.g. xbmc) on the host and port specified. +#wolwake=0 + +# WOL MAC +# +# enter the mac address of the system to be woken. +#wolmac=00:01:2e:2D:64:e1 + +# Set the Host and Port of a server to verify system has woken. +#wolhost=192.168.1.37 +#wolport=80 + +### NZBGET POST-PROCESSING SCRIPT ### +############################################################################## + # Stub file to call nzbToMedia import nzbToMedia diff --git a/nzbToSickBeard.py b/nzbToSickBeard.py index fe663eaf..0ed15557 100755 --- a/nzbToSickBeard.py +++ b/nzbToSickBeard.py @@ -1,5 +1,134 @@ #!/usr/bin/env python # +############################################################################## +### NZBGET POST-PROCESSING SCRIPT ### + +# Post-Process to SickBeard. +# +# This script sends the download to your automated media management servers. +# +# NOTE: This script requires Python to be installed on your system. + +############################################################################## +### OPTIONS ### + +## General +# +# Set to 1 if you want nzbToMedia to automatically check for and update to the latest version +#auto_update=0 + +# Media Extensions +# +# This is a list of media extensions that are used to verify that the download does contain valid media. +#mediaExtensions=.mkv,.avi,.divx,.xvid,.mov,.wmv,.mp4,.mpg,.mpeg,.vob,.iso + +## SickBeard + +# SickBeard script category. +# +# category that gets called for post-processing with SickBeard. +#sbCategory=tv + +# SickBeard host. +#sbhost=localhost + +# SickBeard port. +#sbport=8081 + +# SickBeard username. +#sbusername= + +# SickBeard password. +#sbpassword= + +# SickBeard uses ssl (0, 1). +# +# Set to 1 if using ssl, else set to 0. +#sbssl=0 + +# SickBeard web_root +# +# set this if using a reverse proxy. +#sbweb_root= + +# SickBeard delay +# +# Set the number of seconds to wait before calling post-process in SickBeard. +#sbdelay=0 + +# SickBeard watch directory. +# +# set this if SickBeard and nzbGet are on different systems. +#sbwatch_dir= + +# SickBeard fork. +# +# set to default or auto to auto-detect the custom fork type. +#sbfork=auto + +# SickBeard Delete Failed Downloads (0, 1) +# +# set to 1 to delete failed, or 0 to leave files in place. +#sbdelete_failed=0 + +# SickBeard process method. +# +# set this to move, copy, hardlin, symlink as appropriate if you want to over-ride SB defaults. Leave blank to use SB default. +#sbprocess_method= + +## Extensions + +# Media Extensions +# +# This is a list of media extensions that are used to verify that the download does contain valid media. +#mediaExtensions=.mkv,.avi,.divx,.xvid,.mov,.wmv,.mp4,.mpg,.mpeg,.vob,.iso + +## Transcoder + +# Transcode (0, 1). +# +# set to 1 to transcode, otherwise set to 0. +#transcode=0 + +# create a duplicate, or replace the original (0, 1). +# +# set to 1 to cretae a new file or 0 to replace the original +#duplicate=1 + +# ignore extensions +# +# list of extensions that won't be transcoded. +#ignoreExtensions=.avi,.mkv + +# ffmpeg output settings. +#outputVideoExtension=.mp4 +#outputVideoCodec=libx264 +#outputVideoPreset=medium +#outputVideoFramerate=24 +#outputVideoBitrate=800k +#outputAudioCodec=libmp3lame +#outputAudioBitrate=128k +#outputSubtitleCodec= + +## WakeOnLan + +# use WOL (0, 1). +# +# set to 1 to send WOL broadcast to the mac and test the server (e.g. xbmc) on the host and port specified. +#wolwake=0 + +# WOL MAC +# +# enter the mac address of the system to be woken. +#wolmac=00:01:2e:2D:64:e1 + +# Set the Host and Port of a server to verify system has woken. +#wolhost=192.168.1.37 +#wolport=80 + +### NZBGET POST-PROCESSING SCRIPT ### +############################################################################## + # Stub file to call nzbToMedia import nzbToMedia diff --git a/nzbtomedia/autoProcess/autoProcessMovie.py b/nzbtomedia/autoProcess/autoProcessMovie.py index 38184f05..6002c41a 100644 --- a/nzbtomedia/autoProcess/autoProcessMovie.py +++ b/nzbtomedia/autoProcess/autoProcessMovie.py @@ -10,7 +10,7 @@ import nzbtomedia from lib import requests from nzbtomedia.Transcoder import Transcoder from nzbtomedia.nzbToMediaSceneExceptions import process_all_exceptions -from nzbtomedia.nzbToMediaUtil import convert_to_ascii +from nzbtomedia.nzbToMediaUtil import convert_to_ascii, delete from nzbtomedia import logger class autoProcessMovie: @@ -168,15 +168,10 @@ class autoProcessMovie: else: protocol = "http://" - # don't delay when we are calling this script manually. - if clientAgent == "manual": - delay = 0 - baseURL = protocol + host + ":" + port + web_root + "/api/" + apikey media_id, download_id, release_id, release_status = self.find_media_id(baseURL, download_id, dirName, nzbName) # get the CPS database movie id for this movie. - # failed to get a download id if release_status != "snatched": logger.postprocess("%s has is marked with a status of [%s] by CouchPotatoServer, skipping ...", nzbName, release_status.upper()) @@ -217,7 +212,7 @@ class autoProcessMovie: logger.debug("Opening URL: %s", url) try: - r = requests.get(url, data=params) + r = requests.get(url, params=params) except requests.ConnectionError: logger.error("Unable to open URL") return 1 # failure @@ -254,12 +249,9 @@ class autoProcessMovie: if line: logger.postprocess("%s", line) logger.postprocess("%s FAILED!, Trying the next best release on CouchPotatoServer", nzbName) - if delete_failed and not dirName in [sys.argv[0],'/','']: + if delete_failed and not os.path.dirname(dirName) == dirName: logger.postprocess("Deleting failed files and folder %s", dirName) - try: - shutil.rmtree(dirName) - except: - logger.error("Unable to delete folder %s", dirName) + delete(dirName) return 0 # success if not release_id: @@ -269,15 +261,20 @@ class autoProcessMovie: return 0 # success # we will now check to see if CPS has finished renaming before returning to TorrentToMedia and unpausing. + timeout = time.time() + 60 * int(wait_for) while (True): # only wait 2 (default) minutes, then return. + if time.time() > timeout: + break + current_status = self.get_status(baseURL, release_id) if current_status is None: - logger.error("Could not find a current status for %s", nzbName) + logger.error("Could not find a current status for %s on CouchPotatoServer", nzbName) return 1 if current_status != release_status: # Something has changed. CPS must have processed this movie. logger.postprocess("SUCCESS: This release is now marked as status [%s] in CouchPotatoServer", current_status.upper()) return 0 # success - else: # The status hasn't changed. we have waited 2 minutes which is more than enough. uTorrent can resule seeding now. - logger.warning("The movie does not appear to have changed status after %s minutes. Please check CouchPotato Logs", wait_for) - return 1 # failure + + # The status hasn't changed. we have waited 2 minutes which is more than enough. uTorrent can resule seeding now. + logger.warning("The movie does not appear to have changed status after %s minutes. Please check CouchPotato Logs", wait_for) + return 1 # failure \ No newline at end of file diff --git a/nzbtomedia/autoProcess/autoProcessMusic.py b/nzbtomedia/autoProcess/autoProcessMusic.py index 90150ca5..fb899e94 100644 --- a/nzbtomedia/autoProcess/autoProcessMusic.py +++ b/nzbtomedia/autoProcess/autoProcessMusic.py @@ -1,3 +1,4 @@ +import os import time import datetime import urllib @@ -7,6 +8,35 @@ from nzbtomedia.nzbToMediaUtil import convert_to_ascii from nzbtomedia import logger class autoProcessMusic: + def get_status(self, baseURL, apikey, dirName): + release_status = None + + logger.debug("Attempting to get current status for release:%s", os.path.basename(dirName)) + + url = baseURL + + params = {} + params['apikey'] = apikey + params['cmd'] = "getHistory" + + logger.debug("Opening URL: %s", url) + + try: + r = requests.get(url, params=params) + except requests.ConnectionError: + logger.error("Unable to open URL") + return None, None + + try: + result = r.json() + for album in result: + if os.path.basename(dirName) == album['FolderName']: + release_status = album["Status"] + except: + pass + + return release_status + def process(self, dirName, nzbName=None, status=0, clientAgent="manual", inputCategory=None): if dirName is None: logger.error("No directory was given!") @@ -43,13 +73,10 @@ class autoProcessMusic: protocol = "https://" else: protocol = "http://" - # don't delay when we are calling this script manually. - if clientAgent == "manual": - delay = 0 nzbName, dirName = convert_to_ascii(nzbName, dirName) - baseURL = protocol + host + ":" + port + web_root + "/api?" + baseURL = protocol + host + ":" + port + web_root + "/api" if status == 0: @@ -60,14 +87,15 @@ class autoProcessMusic: url = baseURL - logger.postprocess("Waiting for %s seconds to allow HeadPhones to process newly extracted files", str(delay)) - - time.sleep(delay) + release_status = self.get_status(url, apikey, dirName) + if release_status != "Unprocessed": + logger.error("%s is marked with a status of %s on HeadPhones, skipping ...", nzbName, release_status) + return 1 logger.debug("Opening URL: %s", url) try: - r = requests.get(url, data=params) + r = requests.get(url, params=params) except requests.ConnectionError: logger.error("Unable to open URL") return 1 # failure @@ -83,16 +111,21 @@ class autoProcessMusic: logger.postprocess("The download failed. Nothing to process") return 0 # Success (as far as this script is concerned) - if clientAgent == "manual": - return 0 # success - # we will now wait 1 minutes for this album to be processed before returning to TorrentToMedia and unpausing. - ## Hopefully we can use a "getHistory" check in here to confirm processing complete... - start = datetime.datetime.now() # set time for timeout - while (datetime.datetime.now() - start) < datetime.timedelta(minutes=1): # only wait 2 minutes, then return to TorrentToMedia - time.sleep(20) # Just stop this looping infinitely and hogging resources for 2 minutes ;) - else: # The status hasn't changed. we have waited 2 minutes which is more than enough. uTorrent can resume seeding now. - logger.postprocess("This album should have completed processing. Please check HeadPhones Logs") - # logger.warning("The album does not appear to have changed status after 2 minutes. Please check HeadPhones Logs") - # return 1 # failure - return 0 # success for now. + timeout = time.time() + 60 * 2 + while (True): # only wait 2 (default) minutes, then return. + if time.time() > timeout: + break + + current_status = self.get_status(url, apikey, dirName) + if current_status is None: + logger.error("Could not find a current status for %s on HeadPhones", nzbName) + return 1 + + if current_status != release_status: # Something has changed. CPS must have processed this movie. + logger.postprocess("SUCCESS: This release is now marked as status [%s] in HeadPhones",current_status.upper()) + return 0 # success + + # The status hasn't changed. we have waited 2 minutes which is more than enough. uTorrent can resule seeding now. + logger.warning("The music album does not appear to have changed status after %s minutes. Please check HeadPhones Logs",2) + return 1 # failure diff --git a/nzbtomedia/autoProcess/autoProcessTV.py b/nzbtomedia/autoProcess/autoProcessTV.py index a924ddd3..6e825200 100644 --- a/nzbtomedia/autoProcess/autoProcessTV.py +++ b/nzbtomedia/autoProcess/autoProcessTV.py @@ -3,12 +3,13 @@ import json import os import urllib import time +import sys import nzbtomedia from lib import requests from nzbtomedia.Transcoder import Transcoder from nzbtomedia.nzbToMediaAutoFork import autoFork from nzbtomedia.nzbToMediaSceneExceptions import process_all_exceptions -from nzbtomedia.nzbToMediaUtil import convert_to_ascii, is_sample, flatten, delete +from nzbtomedia.nzbToMediaUtil import convert_to_ascii, is_sample, flatten, delete, is_subdir from nzbtomedia import logger class autoProcessTV: @@ -58,10 +59,6 @@ class autoProcessTV: delete_failed = int(nzbtomedia.CFG[section][inputCategory]["delete_failed"]) except: delete_failed = 0 - try: - delay = float(nzbtomedia.CFG[section][inputCategory]["delay"]) - except: - delay = 0 try: SampleIDs = (nzbtomedia.CFG["Extensions"]["SampleIDs"]) except: @@ -165,25 +162,20 @@ class autoProcessTV: url = None if section == "SickBeard": - url = protocol + host + ":" + port + web_root + "/home/postprocess/processEpisode?" + urllib.urlencode(fork_params) + url = protocol + host + ":" + port + web_root + "/home/postprocess/processEpisode" elif section == "NzbDrone": url = protocol + host + ":" + port + web_root + "/api/command" - if clientAgent == "manual":delay = 0 - logger.postprocess("Waiting for %s seconds to allow %s to process newly extracted files", str(delay), section) - - time.sleep(delay) - logger.debug("Opening URL: %s", url) try: r = None if section == "SickBeard": - r = requests.get(url, auth=(username, password), stream=True) + r = requests.get(url, auth=(username, password), params=fork_params, stream=True) elif section == "NzbDrone": - data = json.dumps({"name": "DownloadedEpisodesScan", "path": dirName}) + params = {"name": "DownloadedEpisodesScan", "path": dirName} headers = {"X-Api-Key": apikey} - r = requests.get(url, data=data, headers=headers, stream=True) + r = requests.get(url, params=params, headers=headers, stream=True) except requests.ConnectionError: logger.error("Unable to open URL") return 1 # failure @@ -191,6 +183,7 @@ class autoProcessTV: for line in r.iter_lines(): if line: logger.postprocess("%s", line) - if status != 0 and delete_failed and not dirName in ['sys.argv[0]','/','']: + if status != 0 and delete_failed and not os.path.dirname(dirName) == dirName: + logger.postprocess("Deleting failed files and folder %s", dirName) delete(dirName) return 0 # Success diff --git a/nzbtomedia/nzbToMediaUtil.py b/nzbtomedia/nzbToMediaUtil.py index 3fb03839..005b551c 100644 --- a/nzbtomedia/nzbToMediaUtil.py +++ b/nzbtomedia/nzbToMediaUtil.py @@ -443,3 +443,14 @@ def cleanup_directories(inputCategory, processCategories, result, directory): logger.info("Directory %s still contains %s media and/or meta files. This directory will not be removed.", directory, num_files_new) for item in file_list: logger.debug("media/meta file found: %s", item) + +def is_subdir(path, directory): + path = os.path.realpath(path) + directory = os.path.realpath(directory) + + relative = os.path.relpath(path, directory) + + if relative.startswith(os.pardir + os.sep): + return False + else: + return True \ No newline at end of file