Browse Source

replace multiple separators. fixes #2448

pull/2451/head
Clinton Hall 12 years ago
parent
commit
b771aa303f
  1. 16
      couchpotato/core/plugins/renamer/main.py

16
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) replaced = toUnicode(string)
for x, r in replacements.iteritems(): for x, r in replacements.iteritems():
if x in ['thename', 'namethe']:
continue
if r is not None: if r is not None:
replaced = replaced.replace(u'<%s>' % toUnicode(x), toUnicode(r)) replaced = replaced.replace(u'<%s>' % toUnicode(x), toUnicode(r))
else: else:
#If information is not available, we don't want the tag in the filename #If information is not available, we don't want the tag in the filename
replaced = replaced.replace('<' + x + '>', '') 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) replaced = re.sub(r"[\x00:\*\?\"<>\|]", '', replaced)
sep = self.conf('foldersep') if folder else self.conf('separator') 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): 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): def deleteEmptyFolder(self, folder, show_error = True):
folder = ss(folder) folder = ss(folder)

Loading…
Cancel
Save