mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-14 10:36:52 -07:00
add custom group replacements to exceptions.
This commit is contained in:
parent
6e3c21c1af
commit
795e5f3849
3 changed files with 42 additions and 11 deletions
|
@ -354,3 +354,9 @@
|
|||
# enter the full path to a text file containing passwords to be used for extraction attempts.
|
||||
# In the passwords file, every password should be on a new line
|
||||
PassWordFile =
|
||||
|
||||
[Custom]
|
||||
# enter a list (comma separated) of Group Tags you want removed from filenames to help with subtitle matching.
|
||||
# e.g remove_group = [rarbag],-NZBgeek
|
||||
# be careful if your "group" is a common "real" word. Please report if you have any group replacments that would fall in this category.
|
||||
remove_group =
|
||||
|
|
|
@ -173,6 +173,7 @@ HWACCEL = False
|
|||
|
||||
PASSWORDSFILE = None
|
||||
DOWNLOADINFO = None
|
||||
GROUPS = None
|
||||
|
||||
USER_SCRIPT_MEDIAEXTENSIONS = None
|
||||
USER_SCRIPT = None
|
||||
|
@ -191,7 +192,7 @@ def initialize(section=None):
|
|||
SABNZB_NO_OF_ARGUMENTS, SABNZB_0717_NO_OF_ARGUMENTS, CATEGORIES, TORRENT_CLIENTAGENT, USELINK, OUTPUTDIRECTORY, \
|
||||
NOFLATTEN, UTORRENTPWD, UTORRENTUSR, UTORRENTWEBUI, DELUGEHOST, DELUGEPORT, DELUGEUSR, DELUGEPWD, \
|
||||
TRANSMISSIONHOST, TRANSMISSIONPORT, TRANSMISSIONPWD, TRANSMISSIONUSR, COMPRESSEDCONTAINER, MEDIACONTAINER, \
|
||||
METACONTAINER, SECTIONS, ALL_FORKS, TEST_FILE, GENERALOPTS, LOG_GIT, \
|
||||
METACONTAINER, SECTIONS, ALL_FORKS, TEST_FILE, GENERALOPTS, LOG_GIT, GROUPS, \
|
||||
__INITIALIZED__, AUTO_UPDATE, APP_FILENAME, USER_DELAY, APP_NAME, TRANSCODE, DEFAULTS, GIT_PATH, GIT_USER, \
|
||||
GIT_BRANCH, GIT_REPO, SYS_ENCODING, NZB_CLIENTAGENT, SABNZBDHOST, SABNZBDPORT, SABNZBDAPIKEY, \
|
||||
DUPLICATE, IGNOREEXTENSIONS, VEXTENSION, OUTPUTVIDEOPATH, PROCESSOUTPUT, VCODEC, VCODEC_ALLOW, VPRESET, \
|
||||
|
@ -310,6 +311,9 @@ def initialize(section=None):
|
|||
SABNZBDPORT = int(CFG["Nzb"]["sabnzbd_port"])
|
||||
SABNZBDAPIKEY = CFG["Nzb"]["sabnzbd_apikey"]
|
||||
NZB_DEFAULTDIR = CFG["Nzb"]["default_downloadDirectory"]
|
||||
GROUPS = CFG["Custom"]["remove_group"]
|
||||
if isinstance(GROUPS, str): GROUPS = GROUPS.split(',')
|
||||
if GROUPS == ['']: GROUPS = None
|
||||
|
||||
TORRENT_CLIENTAGENT = CFG["Torrent"]["clientAgent"] # utorrent | deluge | transmission | rtorrent | other
|
||||
USELINK = CFG["Torrent"]["useLink"] # no | hard | sym
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import os
|
||||
import re
|
||||
import nzbtomedia
|
||||
from nzbtomedia import logger
|
||||
from nzbtomedia.nzbToMediaUtil import listMediaFiles
|
||||
|
||||
|
@ -20,6 +21,7 @@ char_replace = [[r"(\w)1\.(\w)",r"\1i\2"]
|
|||
def process_all_exceptions(name, dirname):
|
||||
rename_script(dirname)
|
||||
for filename in listMediaFiles(dirname):
|
||||
newfilename = None
|
||||
parentDir = os.path.dirname(filename)
|
||||
head, fileExtension = os.path.splitext(os.path.basename(filename))
|
||||
if reverse_pattern.search(head) is not None:
|
||||
|
@ -27,8 +29,33 @@ def process_all_exceptions(name, dirname):
|
|||
elif garbage_name.search(head) is not None:
|
||||
exception = replace_filename
|
||||
else:
|
||||
continue
|
||||
exception(filename, parentDir, name)
|
||||
exception = None
|
||||
newfilename = filename
|
||||
if not newfilename:
|
||||
newfilename = exception(filename, parentDir, name)
|
||||
if nzbtomedia.GROUPS:
|
||||
newfilename = strip_groups(newfilename)
|
||||
if newfilename != filename:
|
||||
rename_file(filename, newfilename)
|
||||
|
||||
def strip_groups(filename):
|
||||
if not nzbtomedia.GROUPS:
|
||||
return filename
|
||||
head, fileExtension = os.path.splitext(os.path.basename(filename))
|
||||
newname = head.replace(' ', '.')
|
||||
for group in nzbtomedia.GROUPS:
|
||||
newname = newname.replace(group, '')
|
||||
newname = newname.replace('[]', '')
|
||||
newfile = newname + fileExtension
|
||||
newfilePath = os.path.join(dirname, newfile)
|
||||
return newfilePath
|
||||
|
||||
def rename_file(filename, newfilePath):
|
||||
logger.debug("Replacing file name %s with download name %s" % (head, newname), "EXCEPTION")
|
||||
try:
|
||||
os.rename(filename, newfilePath)
|
||||
except Exception,e:
|
||||
logger.error("Unable to rename file due to: %s" % (str(e)), "EXCEPTION")
|
||||
|
||||
def replace_filename(filename, dirname, name):
|
||||
head, fileExtension = os.path.splitext(os.path.basename(filename))
|
||||
|
@ -43,10 +70,7 @@ def replace_filename(filename, dirname, name):
|
|||
return
|
||||
newfile = newname + fileExtension
|
||||
newfilePath = os.path.join(dirname, newfile)
|
||||
try:
|
||||
os.rename(filename, newfilePath)
|
||||
except Exception,e:
|
||||
logger.error("Unable to rename file due to: %s" % (str(e)), "EXCEPTION")
|
||||
return newfilePath
|
||||
|
||||
def reverse_filename(filename, dirname, name):
|
||||
head, fileExtension = os.path.splitext(os.path.basename(filename))
|
||||
|
@ -70,10 +94,7 @@ def reverse_filename(filename, dirname, name):
|
|||
logger.debug("Reversing filename %s to %s" % (head, newname), "EXCEPTION")
|
||||
newfile = newname + fileExtension
|
||||
newfilePath = os.path.join(dirname, newfile)
|
||||
try:
|
||||
os.rename(filename, newfilePath)
|
||||
except Exception,e:
|
||||
logger.error("Unable to rename file due to: %s" % (str(e)), "EXCEPTION")
|
||||
return newfilePath
|
||||
|
||||
def rename_script(dirname):
|
||||
rename_file = ""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue