From b771aa303fa34a9480d67df572aa77fd04b474f1 Mon Sep 17 00:00:00 2001 From: Clinton Hall Date: Wed, 13 Nov 2013 21:41:29 +1030 Subject: [PATCH 1/2] replace multiple separators. fixes #2448 --- couchpotato/core/plugins/renamer/main.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/couchpotato/core/plugins/renamer/main.py b/couchpotato/core/plugins/renamer/main.py index f2f9f8da..f1e82366 100755 --- a/couchpotato/core/plugins/renamer/main.py +++ b/couchpotato/core/plugins/renamer/main.py @@ -736,19 +736,31 @@ Remove it if you want it to be renamed (again, or at least let it try again) replaced = toUnicode(string) for x, r in replacements.iteritems(): + if x in ['thename', 'namethe']: + continue if r is not None: replaced = replaced.replace(u'<%s>' % toUnicode(x), toUnicode(r)) else: #If information is not available, we don't want the tag in the filename replaced = replaced.replace('<' + x + '>', '') + replaced = self.replaceDoubles(replaced.lstrip('. ')) + for x, r in replacements.iteritems(): + if x in ['thename', 'namethe']: + replaced = replaced.replace(u'<%s>' % toUnicode(x), toUnicode(r)) + else: + continue replaced = re.sub(r"[\x00:\*\?\"<>\|]", '', replaced) sep = self.conf('foldersep') if folder else self.conf('separator') - return self.replaceDoubles(replaced.lstrip('. ')).replace(' ', ' ' if not sep else sep) + return replaced.replace(' ', ' ' if not sep else sep) def replaceDoubles(self, string): - return string.replace(' ', ' ').replace(' .', '.') + replaces = [('\s', ' '), ('\s\.', ' '), ('\.', '.'), ('_', '_'), ('-', '-')] + for r in replaces: + reg, replace_with = r + string = re.sub('%s+' % reg, replace_with, string) + return string def deleteEmptyFolder(self, folder, show_error = True): folder = ss(folder) From c1944c987d7b17772498db7980cadfc7e3f16954 Mon Sep 17 00:00:00 2001 From: Ruud Date: Thu, 14 Nov 2013 22:35:13 +0100 Subject: [PATCH 2/2] Add some more double char replacements --- couchpotato/core/plugins/renamer/main.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/couchpotato/core/plugins/renamer/main.py b/couchpotato/core/plugins/renamer/main.py index 45d46e5a..c544f134 100755 --- a/couchpotato/core/plugins/renamer/main.py +++ b/couchpotato/core/plugins/renamer/main.py @@ -748,18 +748,22 @@ Remove it if you want it to be renamed (again, or at least let it try again) for x, r in replacements.iteritems(): if x in ['thename', 'namethe']: replaced = replaced.replace(u'<%s>' % toUnicode(x), toUnicode(r)) - else: - continue replaced = re.sub(r"[\x00:\*\?\"<>\|]", '', replaced) sep = self.conf('foldersep') if folder else self.conf('separator') return replaced.replace(' ', ' ' if not sep else sep) def replaceDoubles(self, string): - replaces = [('\s', ' '), ('\s\.', ' '), ('\.', '.'), ('_', '_'), ('-', '-')] + + replaces = [ + ('\.+', '.'), ('_+', '_'), ('-+', '-'), ('\s+', ' '), + ('(\s\.)+', '.'), ('(-\.)+', '.'), ('(\s-)+', '-'), + ] + for r in replaces: reg, replace_with = r - string = re.sub('%s+' % reg, replace_with, string) + string = re.sub(reg, replace_with, string) + return string def deleteEmptyFolder(self, folder, show_error = True):