diff --git a/couchpotato/core/plugins/renamer/__init__.py b/couchpotato/core/plugins/renamer/__init__.py index f4ea8a75..f90828bc 100644 --- a/couchpotato/core/plugins/renamer/__init__.py +++ b/couchpotato/core/plugins/renamer/__init__.py @@ -118,7 +118,7 @@ config = [{ 'default': 'move', 'type': 'dropdown', 'values': [('Move', 'move'), ('Copy', 'copy'), ('Hard link', 'hardlink'), ('Sym link', 'symlink')], - 'description': 'Define which kind of file operation you want to use. Before you start using hard links or sym links, read about thire possible drawbacks.', + 'description': 'Define which kind of file operation you want to use. Before you start using hard links or sym links, PLEASE read about their possible drawbacks.', 'advanced': True, }, { diff --git a/couchpotato/core/plugins/renamer/main.py b/couchpotato/core/plugins/renamer/main.py index 0dbda0da..26aa9dea 100644 --- a/couchpotato/core/plugins/renamer/main.py +++ b/couchpotato/core/plugins/renamer/main.py @@ -10,8 +10,8 @@ from couchpotato.core.plugins.base import Plugin from couchpotato.core.settings.model import Library, File, Profile, Release, \ ReleaseInfo from couchpotato.environment import Env -import linktastic.linktastic as linktastic import errno +import linktastic.linktastic as linktastic import os import re import shutil @@ -140,7 +140,8 @@ class Renamer(Plugin): else: log.error('Download ID %s from downloader %s not found in releases', (download_id, downloader)) - groups = fireEvent('scanner.scan', folder = folder if folder else self.conf('from'), files = movie_files, download_info = download_info, single = True) + groups = fireEvent('scanner.scan', folder = folder if folder else self.conf('from'), + files = movie_files, download_info = download_info, return_ignored = False, single = True) destination = self.conf('to') folder_name = self.conf('folder_name') @@ -450,6 +451,9 @@ class Renamer(Plugin): log.error('Failed moving the file "%s" : %s', (os.path.basename(src), traceback.format_exc())) self.tagDir(group, 'failed_rename') + if self.conf('file_action') != 'move': + self.tagDir(group, 'renamed already') + # Remove matching releases for release in remove_releases: log.debug('Removing release %s', release.identifier) @@ -495,31 +499,23 @@ class Renamer(Plugin): return rename_files + # This adds a file to ignore / tag a release so it is ignored later def tagDir(self, group, tag): - rename_files = {} + ignore_file = None + for movie_file in sorted(list(group['files']['movie'])): + ignore_file = '%s.ignore' % os.path.splitext(movie_file)[0] + break - if group['dirname']: - rename_files[group['parentdir']] = group['parentdir'].replace(group['dirname'], '_%s_%s' % (tag.upper(), group['dirname'])) - else: # Add it to filename - for file_type in group['files']: - for rename_me in group['files'][file_type]: - filename = os.path.basename(rename_me) - rename_files[rename_me] = rename_me.replace(filename, '_%s_%s' % (tag.upper(), filename)) + text = """This file is from CouchPotato +It has marked this release as "%s" +This file hides the release from the renamer +Remove it if you want it to be renamed (again, or at least let it try again) +""" % tag - for src in rename_files: - if rename_files[src]: - dst = rename_files[src] - log.info('Renaming "%s" to "%s"', (src, dst)) + if ignore_file: + self.createFile(ignore_file, text) - # Create dir - self.makeDir(os.path.dirname(dst)) - - try: - self.moveFile(src, dst) - except: - log.error('Failed moving the file "%s" : %s', (os.path.basename(src), traceback.format_exc())) - raise def moveFile(self, old, dest): dest = ss(dest) diff --git a/couchpotato/core/plugins/scanner/main.py b/couchpotato/core/plugins/scanner/main.py index e7a94598..79fe0018 100644 --- a/couchpotato/core/plugins/scanner/main.py +++ b/couchpotato/core/plugins/scanner/main.py @@ -101,7 +101,7 @@ class Scanner(Plugin): addEvent('scanner.name_year', self.getReleaseNameYear) addEvent('scanner.partnumber', self.getPartNumber) - def scan(self, folder = None, files = None, download_info = None, simple = False, newer_than = 0, on_found = None): + def scan(self, folder = None, files = None, download_info = None, simple = False, newer_than = 0, return_ignored = True, on_found = None): folder = ss(os.path.normpath(folder)) @@ -177,17 +177,25 @@ class Scanner(Plugin): # Group files minus extension + ignored_identifiers = [] for identifier, group in movie_files.iteritems(): if identifier not in group['identifiers'] and len(identifier) > 0: group['identifiers'].append(identifier) log.debug('Grouping files: %s', identifier) + has_ignored = 0 for file_path in group['unsorted_files']: - wo_ext = file_path[:-(len(getExt(file_path)) + 1)] + ext = getExt(file_path) + wo_ext = file_path[:-(len(ext) + 1)] found_files = set([i for i in leftovers if wo_ext in i]) group['unsorted_files'].extend(found_files) leftovers = leftovers - found_files + has_ignored += 1 if ext == 'ignore' else 0 + + if has_ignored > 0: + ignored_identifiers.append(identifier) + # Break if CP wants to shut down if self.shuttingDown(): break @@ -327,15 +335,17 @@ class Scanner(Plugin): except: break + if return_ignored is False and identifier in ignored_identifiers: + log.debug('Ignore file found, ignoring release: %s' % identifier) + continue + # Group extra (and easy) files first - # images = self.getImages(group['unsorted_files']) group['files'] = { 'movie_extra': self.getMovieExtras(group['unsorted_files']), 'subtitle': self.getSubtitles(group['unsorted_files']), 'subtitle_extra': self.getSubtitlesExtras(group['unsorted_files']), 'nfo': self.getNfo(group['unsorted_files']), 'trailer': self.getTrailers(group['unsorted_files']), - #'backdrop': images['backdrop'], 'leftover': set(group['unsorted_files']), }