mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-20 05:13:16 -07:00
All processing sections now can enable/disable linking for torrents via TorrentNoLink option in autoProcessMedia.cfg
Cleanup/removal of processed files on start and finish of our nzbToMedia and TorrentToMedia scripts to insure things stay nice and polished :) Code tweaked and cleaned and fed a energy drink so stay on the look out this things alive ! lol
This commit is contained in:
parent
0053fdcf3e
commit
27d722e8b1
5 changed files with 69 additions and 64 deletions
|
@ -14,7 +14,7 @@ from nzbtomedia.autoProcess.autoProcessMovie import autoProcessMovie
|
|||
from nzbtomedia.autoProcess.autoProcessMusic import autoProcessMusic
|
||||
from nzbtomedia.autoProcess.autoProcessTV import autoProcessTV
|
||||
from nzbtomedia.nzbToMediaUtil import category_search, sanitizeFileName, copy_link, parse_args, flatten, get_dirnames, \
|
||||
remove_read_only, create_torrent_class, pause_torrent, resume_torrent, listMediaFiles, joinPath, \
|
||||
remove_read_only, pause_torrent, resume_torrent, listMediaFiles, joinPath, \
|
||||
extractFiles, cleanProcDirs
|
||||
from nzbtomedia import logger
|
||||
|
||||
|
@ -41,10 +41,10 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
|
|||
"We could not find a section with containing a download category labeled %s in your autoProcessMedia.cfg, Exiting!" % inputCategory)
|
||||
return -1
|
||||
|
||||
TorrentClass = None
|
||||
Torrent_NoLink = int(nzbtomedia.CFG[section][inputCategory]["Torrent_NoLink"])
|
||||
|
||||
if clientAgent != 'manual':
|
||||
TorrentClass = create_torrent_class(clientAgent)
|
||||
pause_torrent(clientAgent, TorrentClass, inputHash, inputID, inputName)
|
||||
pause_torrent(clientAgent, inputHash, inputID, inputName)
|
||||
|
||||
processCategories = nzbtomedia.CFG[nzbtomedia.SECTIONS].sections
|
||||
|
||||
|
@ -53,19 +53,6 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
|
|||
outputDestination = os.path.normpath(joinPath(nzbtomedia.OUTPUTDIRECTORY, inputCategory, sanitizeFileName(inputName)))
|
||||
logger.info("Output directory set to: %s" % (outputDestination))
|
||||
|
||||
if nzbtomedia.CFG["SickBeard"][inputCategory]:
|
||||
Torrent_NoLink = int(nzbtomedia.CFG["SickBeard"][inputCategory]["Torrent_NoLink"]) # 0
|
||||
if Torrent_NoLink == 1:
|
||||
logger.info("Calling autoProcessTV to post-process: %s",inputName)
|
||||
result = autoProcessTV().processEpisode(inputDirectory, inputName, 0, clientAgent=clientAgent, inputCategory=inputCategory)
|
||||
if result != 0:
|
||||
logger.error("A problem was reported in the autoProcessTV script.")
|
||||
|
||||
if clientAgent != 'manual':
|
||||
resume_torrent(clientAgent, TorrentClass, inputHash, inputID, result, inputName)
|
||||
|
||||
return result
|
||||
|
||||
processOnly = nzbtomedia.CFG[nzbtomedia.SECTIONS].sections
|
||||
if not "NONE" in nzbtomedia.USER_SCRIPT_CATEGORIES: # if None, we only process the 5 listed.
|
||||
if "ALL" in nzbtomedia.USER_SCRIPT_CATEGORIES: # All defined categories
|
||||
|
@ -120,6 +107,7 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
|
|||
else:
|
||||
continue # This file has not been recently moved or created, skip it
|
||||
|
||||
if Torrent_NoLink == 0:
|
||||
try:
|
||||
copy_link(inputFile, targetDirectory, nzbtomedia.USELINK, outputDestination)
|
||||
copy_list.append([inputFile, joinPath(outputDestination, fullFileName)])
|
||||
|
@ -127,6 +115,7 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
|
|||
logger.error("Failed to link file: %s" % (fullFileName))
|
||||
|
||||
outputDestination = outputDestinationMaster # Reset here.
|
||||
|
||||
if not inputCategory in nzbtomedia.NOFLATTEN: #don't flatten hp in case multi cd albums, and we need to copy this back later.
|
||||
flatten(outputDestination)
|
||||
|
||||
|
@ -187,7 +176,10 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID,
|
|||
|
||||
if result != 0 and clientAgent != 'manual':
|
||||
logger.error("A problem was reported in the autoProcess* script. If torrent was paused we will resume seeding")
|
||||
resume_torrent(clientAgent, TorrentClass, inputHash, inputID, result, inputName)
|
||||
resume_torrent(clientAgent, inputHash, inputID, result, inputName)
|
||||
else:
|
||||
# cleanup our processing folders of any misc unwanted files and empty directories
|
||||
cleanProcDirs()
|
||||
|
||||
return result
|
||||
|
||||
|
@ -309,9 +301,6 @@ def main(args):
|
|||
logger.warning("%s:%s is DISABLED, you can enable this in autoProcessMedia.cfg ..." % (section, category))
|
||||
|
||||
if result == 0:
|
||||
# cleanup our processing folders of any misc unwanted files and empty directories
|
||||
cleanProcDirs()
|
||||
|
||||
logger.info("The %s script completed successfully." % (args[0]))
|
||||
else:
|
||||
logger.error("A problem was reported in the %s script." % (args[0]))
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
###### ADVANCED USE - ONLY EDIT IF YOU KNOW WHAT YOU'RE DOING ######
|
||||
ssl = 0
|
||||
web_root =
|
||||
# Enable/Disable linking for Torrents
|
||||
Torrent_NoLink = 0
|
||||
method = renamer
|
||||
delete_failed = 0
|
||||
wait_for = 2
|
||||
|
@ -52,6 +54,7 @@
|
|||
ssl = 0
|
||||
fork = auto
|
||||
delete_failed = 0
|
||||
# Enable/Disable linking for Torrents
|
||||
Torrent_NoLink = 0
|
||||
process_method =
|
||||
extract = 1
|
||||
|
@ -74,6 +77,7 @@
|
|||
web_root =
|
||||
ssl = 0
|
||||
delete_failed = 0
|
||||
# Enable/Disable linking for Torrents
|
||||
Torrent_NoLink = 0
|
||||
extract = 1
|
||||
##### Set to path where completed downloads are found on remote server for this category
|
||||
|
@ -93,6 +97,8 @@
|
|||
ssl = 0
|
||||
web_root =
|
||||
wait_for = 2
|
||||
# Enable/Disable linking for Torrents
|
||||
Torrent_NoLink = 0
|
||||
extract = 1
|
||||
##### Set to path where completed downloads are found on remote server for this category
|
||||
remote_path =
|
||||
|
@ -111,6 +117,8 @@
|
|||
###### ADVANCED USE - ONLY EDIT IF YOU KNOW WHAT YOU'RE DOING ######
|
||||
web_root=
|
||||
ssl=0
|
||||
# Enable/Disable linking for Torrents
|
||||
Torrent_NoLink = 0
|
||||
extract = 1
|
||||
##### Set to path where completed downloads are found on remote server for this category
|
||||
remote_path =
|
||||
|
@ -128,6 +136,8 @@
|
|||
###### ADVANCED USE - ONLY EDIT IF YOU KNOW WHAT YOU'RE DOING ######
|
||||
ssl = 0
|
||||
web_root =
|
||||
# Enable/Disable linking for Torrents
|
||||
Torrent_NoLink = 0
|
||||
extract = 1
|
||||
##### Set to path where completed downloads are found on remote server for this category
|
||||
remote_path =
|
||||
|
|
|
@ -311,6 +311,10 @@ def process(nzbDir, inputName=None, status=0, clientAgent='manual', download_id=
|
|||
logger.error("We could not find a section with containing a download category labeled %s in your autoProcessMedia.cfg, Exiting!" % inputCategory)
|
||||
result = -1
|
||||
|
||||
if result == 0:
|
||||
# cleanup our processing folders of any misc unwanted files and empty directories
|
||||
cleanProcDirs()
|
||||
|
||||
return result
|
||||
|
||||
def main(args, section=None):
|
||||
|
@ -423,13 +427,13 @@ def main(args, section=None):
|
|||
if results != 0:
|
||||
logger.error("A problem was reported when trying to perform a manual run for %s:%s." % (section, category))
|
||||
result = results
|
||||
|
||||
if len(dirNames) == 0:
|
||||
logger.info('[%s] - No directories found to post-process ...' % (str(category).upper()), section)
|
||||
else:
|
||||
logger.debug("nzbToMedia %s:%s is DISABLED" % (section, category))
|
||||
|
||||
if result == 0:
|
||||
# cleanup our processing folders of any misc unwanted files and empty directories
|
||||
cleanProcDirs()
|
||||
|
||||
logger.info("The %s script completed successfully." % args[0])
|
||||
if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11
|
||||
sys.exit(nzbtomedia.NZBGET_POSTPROCESS_SUCCESS)
|
||||
|
|
|
@ -21,7 +21,7 @@ sys.path.insert(0, os.path.abspath(os.path.join(PROGRAM_DIR, 'lib')))
|
|||
|
||||
from nzbtomedia import logger, versionCheck
|
||||
from nzbtomedia.nzbToMediaConfig import config
|
||||
from nzbtomedia.nzbToMediaUtil import WakeUp, makeDir, joinPath, cleanProcDirs
|
||||
from nzbtomedia.nzbToMediaUtil import WakeUp, makeDir, joinPath, cleanProcDirs, create_torrent_class
|
||||
|
||||
# sabnzbd constants
|
||||
SABNZB_NO_OF_ARGUMENTS = 8
|
||||
|
@ -65,6 +65,7 @@ SABNZBDPORT = None
|
|||
SABNZBDAPIKEY = None
|
||||
|
||||
TORRENT_CLIENTAGENT = None
|
||||
TORRENT_CLASS = None
|
||||
USELINK = None
|
||||
OUTPUTDIRECTORY = None
|
||||
CATEGORIES = []
|
||||
|
@ -137,7 +138,7 @@ def initialize(section=None):
|
|||
TRANSCODE, GIT_PATH, GIT_USER, GIT_BRANCH, GIT_REPO, SYS_ENCODING, NZB_CLIENTAGENT, SABNZBDHOST, SABNZBDPORT, SABNZBDAPIKEY, \
|
||||
DUPLICATE, IGNOREEXTENSIONS, OUTPUTVIDEOEXTENSION, OUTPUTVIDEOCODEC, OUTPUTVIDEOPRESET, OUTPUTVIDEOFRAMERATE, \
|
||||
OUTPUTVIDEOBITRATE, OUTPUTAUDIOCODEC, OUTPUTAUDIOBITRATE, OUTPUTSUBTITLECODEC, OUTPUTFASTSTART, OUTPUTQUALITYPERCENT, \
|
||||
NICENESS, LOG_DEBUG, FORCE_CLEAN, FFMPEG_PATH, FFMPEG, FFPROBE, AUDIOCONTAINER, EXTCONTAINER
|
||||
NICENESS, LOG_DEBUG, FORCE_CLEAN, FFMPEG_PATH, FFMPEG, FFPROBE, AUDIOCONTAINER, EXTCONTAINER, TORRENT_CLASS
|
||||
|
||||
if __INITIALIZED__:
|
||||
return False
|
||||
|
@ -310,6 +311,9 @@ def initialize(section=None):
|
|||
SUBSECTIONS = CFG[SECTIONS]
|
||||
CATEGORIES += SUBSECTIONS.sections
|
||||
|
||||
# create torrent class
|
||||
TORRENT_CLASS = create_torrent_class(TORRENT_CLIENTAGENT)
|
||||
|
||||
# cleanup our processing folders of any misc unwanted files and empty directories
|
||||
cleanProcDirs()
|
||||
|
||||
|
|
|
@ -423,7 +423,7 @@ def get_dirnames(section, subsections=None):
|
|||
os.path.isdir(joinPath(outputDirectory, o))])
|
||||
|
||||
if not dirNames:
|
||||
logger.warning("%s:%s has no directories identified for post-processing" % (section, subsection))
|
||||
logger.debug("No directories identified in %s for post-processing" % (subsection), section)
|
||||
|
||||
return list(set(dirNames))
|
||||
|
||||
|
@ -454,11 +454,12 @@ def cleanProcDirs():
|
|||
|
||||
def create_torrent_class(clientAgent):
|
||||
# Hardlink solution for Torrents
|
||||
TorrentClass = None
|
||||
tc = None
|
||||
|
||||
if clientAgent == 'utorrent':
|
||||
try:
|
||||
logger.debug("Connecting to %s: %s" % (clientAgent, nzbtomedia.UTORRENTWEBUI))
|
||||
TorrentClass = UTorrentClient(nzbtomedia.UTORRENTWEBUI, nzbtomedia.UTORRENTUSR, nzbtomedia.UTORRENTPWD)
|
||||
tc = UTorrentClient(nzbtomedia.UTORRENTWEBUI, nzbtomedia.UTORRENTUSR, nzbtomedia.UTORRENTPWD)
|
||||
except:
|
||||
logger.error("Failed to connect to uTorrent")
|
||||
|
||||
|
@ -466,7 +467,7 @@ def create_torrent_class(clientAgent):
|
|||
try:
|
||||
logger.debug("Connecting to %s: http://%s:%s" % (
|
||||
clientAgent, nzbtomedia.TRANSMISSIONHOST, nzbtomedia.TRANSMISSIONPORT))
|
||||
TorrentClass = TransmissionClient(nzbtomedia.TRANSMISSIONHOST, nzbtomedia.TRANSMISSIONPORT,
|
||||
tc = TransmissionClient(nzbtomedia.TRANSMISSIONHOST, nzbtomedia.TRANSMISSIONPORT,
|
||||
nzbtomedia.TRANSMISSIONUSR,
|
||||
nzbtomedia.TRANSMISSIONPWD)
|
||||
except:
|
||||
|
@ -475,64 +476,61 @@ def create_torrent_class(clientAgent):
|
|||
if clientAgent == 'deluge':
|
||||
try:
|
||||
logger.debug("Connecting to %s: http://%s:%s" % (clientAgent, nzbtomedia.DELUGEHOST, nzbtomedia.DELUGEPORT))
|
||||
TorrentClass = DelugeClient()
|
||||
TorrentClass.connect(host=nzbtomedia.DELUGEHOST, port=nzbtomedia.DELUGEPORT, username=nzbtomedia.DELUGEUSR,
|
||||
tc = DelugeClient()
|
||||
tc.connect(host=nzbtomedia.DELUGEHOST, port=nzbtomedia.DELUGEPORT, username=nzbtomedia.DELUGEUSR,
|
||||
password=nzbtomedia.DELUGEPWD)
|
||||
except:
|
||||
logger.error("Failed to connect to Deluge")
|
||||
|
||||
return TorrentClass
|
||||
return tc
|
||||
|
||||
|
||||
def pause_torrent(clientAgent, TorrentClass, inputHash, inputID, inputName):
|
||||
def pause_torrent(clientAgent, inputHash, inputID, inputName):
|
||||
# if we are using links with Torrents it means we need to pause it in order to access the files
|
||||
logger.debug("Stoping torrent %s in %s while processing" % (inputName, clientAgent))
|
||||
if clientAgent == 'utorrent' and TorrentClass != "":
|
||||
TorrentClass.stop(inputHash)
|
||||
if clientAgent == 'transmission' and TorrentClass != "":
|
||||
TorrentClass.stop_torrent(inputID)
|
||||
if clientAgent == 'deluge' and TorrentClass != "":
|
||||
TorrentClass.core.pause_torrent([inputID])
|
||||
if clientAgent == 'utorrent' and nzbtomedia.TORRENT_CLASS != "":
|
||||
nzbtomedia.TORRENT_CLASS.stop(inputHash)
|
||||
if clientAgent == 'transmission' and nzbtomedia.TORRENT_CLASS != "":
|
||||
nzbtomedia.TORRENT_CLASS.stop_torrent(inputID)
|
||||
if clientAgent == 'deluge' and nzbtomedia.TORRENT_CLASS != "":
|
||||
nzbtomedia.TORRENT_CLASS.core.pause_torrent([inputID])
|
||||
time.sleep(5) # Give Torrent client some time to catch up with the change
|
||||
|
||||
|
||||
def resume_torrent(clientAgent, TorrentClass, inputHash, inputID, result, inputName):
|
||||
def resume_torrent(clientAgent, inputHash, inputID, result, inputName):
|
||||
# Hardlink solution for uTorrent, need to implent support for deluge, transmission
|
||||
if clientAgent in ['utorrent', 'transmission', 'deluge'] and inputHash:
|
||||
# Delete torrent and torrentdata from Torrent client if processing was successful.
|
||||
if (int(nzbtomedia.CFG["Torrent"][
|
||||
"deleteOriginal"]) is 1 and result != 1) or nzbtomedia.USELINK == 'move': # if we move files, nothing to resume seeding.
|
||||
logger.debug("Deleting torrent %s from %s" % (inputName, clientAgent))
|
||||
if clientAgent == 'utorrent' and TorrentClass != "":
|
||||
TorrentClass.removedata(inputHash)
|
||||
TorrentClass.remove(inputHash)
|
||||
if clientAgent == 'transmission' and TorrentClass != "":
|
||||
TorrentClass.remove_torrent(inputID, True)
|
||||
if clientAgent == 'deluge' and TorrentClass != "":
|
||||
TorrentClass.core.remove_torrent(inputID, True)
|
||||
if clientAgent == 'utorrent' and nzbtomedia.TORRENT_CLASS != "":
|
||||
nzbtomedia.TORRENT_CLASS.removedata(inputHash)
|
||||
nzbtomedia.TORRENT_CLASS.remove(inputHash)
|
||||
if clientAgent == 'transmission' and nzbtomedia.TORRENT_CLASS != "":
|
||||
nzbtomedia.TORRENT_CLASS.remove_torrent(inputID, True)
|
||||
if clientAgent == 'deluge' and nzbtomedia.TORRENT_CLASS != "":
|
||||
nzbtomedia.TORRENT_CLASS.core.remove_torrent(inputID, True)
|
||||
# we always want to resume seeding, for now manually find out what is wrong when extraction fails
|
||||
else:
|
||||
logger.debug("Starting torrent %s in %s" % (inputName, clientAgent))
|
||||
if clientAgent == 'utorrent' and TorrentClass != "":
|
||||
TorrentClass.start(inputHash)
|
||||
if clientAgent == 'transmission' and TorrentClass != "":
|
||||
TorrentClass.start_torrent(inputID)
|
||||
if clientAgent == 'deluge' and TorrentClass != "":
|
||||
TorrentClass.core.resume_torrent([inputID])
|
||||
if clientAgent == 'utorrent' and nzbtomedia.TORRENT_CLASS != "":
|
||||
nzbtomedia.TORRENT_CLASS.start(inputHash)
|
||||
if clientAgent == 'transmission' and nzbtomedia.TORRENT_CLASS != "":
|
||||
nzbtomedia.TORRENT_CLASS.start_torrent(inputID)
|
||||
if clientAgent == 'deluge' and nzbtomedia.TORRENT_CLASS != "":
|
||||
nzbtomedia.TORRENT_CLASS.core.resume_torrent([inputID])
|
||||
time.sleep(5)
|
||||
|
||||
|
||||
def find_download(clientAgent, download_id):
|
||||
tc = create_torrent_class(clientAgent)
|
||||
|
||||
logger.debug("Searching for Download on %s ..." % (clientAgent))
|
||||
if clientAgent == 'utorrent':
|
||||
torrents = tc.list()[1]['torrents']
|
||||
torrents = nzbtomedia.TORRENT_CLASS.list()[1]['torrents']
|
||||
for torrent in torrents:
|
||||
if download_id in torrent:
|
||||
return True
|
||||
if clientAgent == 'transmission':
|
||||
torrents = tc.get_torrents()
|
||||
torrents = nzbtomedia.TORRENT_CLASS.get_torrents()
|
||||
for torrent in torrents:
|
||||
hash = torrent.hashString
|
||||
if hash == download_id:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue