diff --git a/TorrentToMedia.py b/TorrentToMedia.py index d83a5144..f07cc570 100755 --- a/TorrentToMedia.py +++ b/TorrentToMedia.py @@ -184,14 +184,18 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, logger.info("Calling Gamez:" + inputCategory + " to post-process: %s" % (inputName)) result = nzbtomedia.autoProcessGames().process(outputDestination, inputName, status, clientAgent, inputCategory) - if result != 0 and clientAgent != 'manual': - logger.error("A problem was reported in the autoProcess* script. If torrent was paused we will resume seeding") - nzbtomedia.resume_torrent(clientAgent, inputHash, inputID, result, inputName) + if result != 0: + if clientAgent != 'manual': + logger.error("A problem was reported in the autoProcess* script. If torrent was paused we will resume seeding") + nzbtomedia.resume_torrent(clientAgent, inputHash, inputID, inputName) else: if clientAgent != 'manual': # update download status in our DB nzbtomedia.update_downloadInfoStatus(inputName, 1) + # remove torrent + nzbtomedia.remove_torrent(clientAgent,inputHash,inputID,inputName) + # cleanup our processing folders of any misc unwanted files and empty directories nzbtomedia.cleanProcDirs() diff --git a/nzbtomedia/__init__.py b/nzbtomedia/__init__.py index ae0e34a4..cf3e3214 100644 --- a/nzbtomedia/__init__.py +++ b/nzbtomedia/__init__.py @@ -28,7 +28,7 @@ from nzbtomedia.autoProcess.autoProcessTV import autoProcessTV from nzbtomedia import logger, versionCheck, nzbToMediaDB from nzbtomedia.nzbToMediaConfig import config from nzbtomedia.nzbToMediaUtil import category_search, sanitizeFileName, copy_link, parse_args, flatten, get_dirnames, \ - remove_read_only, pause_torrent, resume_torrent, listMediaFiles, joinPath, \ + remove_read_only, pause_torrent, resume_torrent, remove_torrent, listMediaFiles, joinPath, \ extractFiles, cleanProcDirs, update_downloadInfoStatus, get_downloadInfo, WakeUp, makeDir, joinPath, cleanProcDirs, \ create_torrent_class, listMediaFiles from nzbtomedia.transcoder import transcoder @@ -336,9 +336,6 @@ def initialize(section=None): # create torrent class TORRENT_CLASS = create_torrent_class(TORRENT_CLIENTAGENT) - # cleanup our processing folders of any misc unwanted files and empty directories - cleanProcDirs() - return True diff --git a/nzbtomedia/nzbToMediaUtil.py b/nzbtomedia/nzbToMediaUtil.py index fa50f2f3..5cf051da 100644 --- a/nzbtomedia/nzbToMediaUtil.py +++ b/nzbtomedia/nzbToMediaUtil.py @@ -501,39 +501,42 @@ def create_torrent_class(clientAgent): 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 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 + + time.sleep(5) -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 (nzbtomedia.DELETE_ORIGINAL == 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 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 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]) +def resume_torrent(clientAgent, inputHash, inputID, inputName): + logger.debug("Starting torrent %s in %s" % (inputName, clientAgent)) + + 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 remove_torrent(clientAgent, inputHash, inputID, inputName): + if nzbtomedia.DELETE_ORIGINAL == 1 or nzbtomedia.USELINK == 'move': + logger.debug("Deleting torrent %s from %s" % (inputName, clientAgent)) + + 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) + time.sleep(5) def find_download(clientAgent, download_id):