diff --git a/TorrentToMedia.py b/TorrentToMedia.py index accb9998..ff728cd6 100755 --- a/TorrentToMedia.py +++ b/TorrentToMedia.py @@ -249,6 +249,10 @@ def processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, core.update_downloadInfoStatus(inputName, 1) # remove torrent + if core.USELINK == 'move-sym' and not core.DELETE_ORIGINAL == 1: + inputFiles = core.listMediaFiles(inputDirectory) + for link in inputFiles: + core.replace_links(link) core.remove_torrent(clientAgent, inputHash, inputID, inputName) if not sectionName == 'UserScript': # for user script, we assume this is cleaned by the script or option USER_SCRIPT_CLEAN diff --git a/autoProcessMedia.cfg.spec b/autoProcessMedia.cfg.spec index 45f7e53b..e0dc3c7d 100644 --- a/autoProcessMedia.cfg.spec +++ b/autoProcessMedia.cfg.spec @@ -221,7 +221,7 @@ [Torrent] ###### clientAgent - Supported clients: utorrent, transmission, deluge, rtorrent, vuze, other clientAgent = other - ###### useLink - Set to hard for physical links, sym for symbolic links, move to move, and no to not use links (copy) + ###### useLink - Set to hard for physical links, sym for symbolic links, move to move, move-sym to move and link back, and no to not use links (copy) useLink = hard ###### outputDirectory - Default output directory (categories will be appended as sub directory to outputDirectory) outputDirectory = /abs/path/to/complete/ diff --git a/core/nzbToMediaUtil.py b/core/nzbToMediaUtil.py index 39e3e7a1..8029daa6 100644 --- a/core/nzbToMediaUtil.py +++ b/core/nzbToMediaUtil.py @@ -232,10 +232,13 @@ def copy_link(src, targetLink, useLink): return True elif useLink == "sym": logger.info("Sym linking SOURCE MEDIAFILE -> TARGET FOLDER", 'COPYLINK') - #shutil.move(src, targetLink) - #linktastic.symlink(targetLink, src) linktastic.symlink(src, targetLink) return True + elif useLink == "move-sym": + logger.info("Sym linking SOURCE MEDIAFILE -> TARGET FOLDER", 'COPYLINK') + shutil.move(src, targetLink) + linktastic.symlink(targetLink, src) + return True elif useLink == "move": logger.info("Moving SOURCE MEDIAFILE -> TARGET FOLDER", 'COPYLINK') shutil.move(src, targetLink) @@ -248,6 +251,19 @@ def copy_link(src, targetLink, useLink): return True +def replace_links(link): + if not os.path.islink(link): + return + target = link + n = 0 + while os.path.islink(target): + target = os.readlink(target) + n = n + 1 + if n > 1: + logger.info("Changing sym-link: %s to point directly to file: %s" % (link, target), 'COPYLINK') + os.unlink(link) + linktastic.symlink(target, link) + def flatten(outputDestination): logger.info("FLATTEN: Flattening directory: %s" % (outputDestination)) for outputFile in listMediaFiles(outputDestination): @@ -782,7 +798,7 @@ def remove_torrent(clientAgent, inputHash, inputID, inputName): time.sleep(5) except: logger.warning("Failed to delete torrent %s in %s" % (inputName, clientAgent)) - else: + else: resume_torrent(clientAgent, inputHash, inputID, inputName) def find_download(clientAgent, download_id):