diff --git a/couchpotato/core/helpers/variable.py b/couchpotato/core/helpers/variable.py index 775765e9..4eb004d4 100644 --- a/couchpotato/core/helpers/variable.py +++ b/couchpotato/core/helpers/variable.py @@ -286,3 +286,14 @@ def dictIsSubset(a, b): def isSubFolder(sub_folder, base_folder): # Returns True if sub_folder is the same as or inside base_folder return base_folder and sub_folder and ss(os.path.normpath(base_folder).rstrip(os.path.sep) + os.path.sep) in ss(os.path.normpath(sub_folder).rstrip(os.path.sep) + os.path.sep) + +# From SABNZBD +re_password = [re.compile(r'([^/\\]+)[/\\](.+)'), re.compile(r'(.+){{([^{}]+)}}$'), re.compile(r'(.+)\s+password\s*=\s*(.+)$', re.I)] +def scanForPassword(name): + m = None + for reg in re_password: + m = reg.search(name) + if m: break + + if m: + return m.group(1).strip('. '), m.group(2).strip() diff --git a/couchpotato/core/plugins/base.py b/couchpotato/core/plugins/base.py index bd397eb0..008fc8f4 100644 --- a/couchpotato/core/plugins/base.py +++ b/couchpotato/core/plugins/base.py @@ -2,7 +2,7 @@ from couchpotato import get_db from couchpotato.core.event import fireEvent, addEvent from couchpotato.core.helpers.encoding import ss, toSafeString, \ toUnicode, sp -from couchpotato.core.helpers.variable import getExt, md5, isLocalIP +from couchpotato.core.helpers.variable import getExt, md5, isLocalIP, scanForPassword, tryInt from couchpotato.core.logger import CPLog from couchpotato.environment import Env import requests @@ -301,8 +301,17 @@ class Plugin(object): return value def createNzbName(self, data, media): + release_name = data.get('name') tag = self.cpTag(media) - return '%s%s' % (toSafeString(toUnicode(data.get('name'))[:127 - len(tag)]), tag) + + # Check if password is filename + name_password = scanForPassword(data.get('name')) + if name_password: + release_name, password = name_password + tag += '{{%s}}' % password + + max_length = 127 - len(tag) # Some filesystems don't support 128+ long filenames + return '%s%s' % (toSafeString(toUnicode(release_name)[:max_length]), tag) def createFileName(self, data, filedata, media): name = sp(os.path.join(self.createNzbName(data, media))) @@ -316,6 +325,42 @@ class Plugin(object): return '' + def checkFilesChanged(self, files, unchanged_for = 60): + now = time.time() + + for cur_file in files: + + # File got removed while checking + if not os.path.isfile(cur_file): + file_too_new = now + break + + # File has changed in last 60 seconds + file_time = self.self.getFileTimes(cur_file) + for t in file_time: + if t > now - unchanged_for: + file_too_new = tryInt(time.time() - t) + break + + if file_too_new: + break + + if file_too_new: + try: + time_string = time.ctime(file_time[0]) + except: + try: + time_string = time.ctime(file_time[1]) + except: + time_string = 'unknown' + + return file_too_new, time_string + + return False, None + + def getFileTimes(self, file_path): + return [os.path.getmtime(file_path), os.path.getctime(file_path) if os.name != 'posix' else 0] + def isDisabled(self): return not self.isEnabled() diff --git a/couchpotato/core/plugins/renamer/main.py b/couchpotato/core/plugins/renamer/main.py index a88af2cf..22e1d6ac 100755 --- a/couchpotato/core/plugins/renamer/main.py +++ b/couchpotato/core/plugins/renamer/main.py @@ -1119,29 +1119,9 @@ Remove it if you want it to be renamed (again, or at least let it try again) # Check if archive is fresh and maybe still copying/moving/downloading, ignore files newer than 1 minute if check_file_date: - file_too_new = False - for cur_file in archive['files']: - if not os.path.isfile(cur_file): - file_too_new = time.time() - break - file_time = [os.path.getmtime(cur_file), os.path.getctime(cur_file)] - for t in file_time: - if t > time.time() - 60: - file_too_new = tryInt(time.time() - t) - break - - if file_too_new: - break - - if file_too_new: - try: - time_string = time.ctime(file_time[0]) - except: - try: - time_string = time.ctime(file_time[1]) - except: - time_string = 'unknown' + files_too_new, time_string = self.checkFilesChanged(archive['files']) + if files_too_new: log.info('Archive seems to be still copying/moving/downloading or just copied/moved/downloaded (created on %s), ignoring for now: %s', (time_string, os.path.basename(archive['file']))) continue diff --git a/couchpotato/core/plugins/scanner/main.py b/couchpotato/core/plugins/scanner/main.py index e7f9b69d..3ed50798 100644 --- a/couchpotato/core/plugins/scanner/main.py +++ b/couchpotato/core/plugins/scanner/main.py @@ -290,41 +290,21 @@ class Scanner(Plugin): break # Check if movie is fresh and maybe still unpacking, ignore files newer than 1 minute - file_too_new = False - for cur_file in group['unsorted_files']: - if not os.path.isfile(cur_file): - file_too_new = time.time() - break - file_time = [os.path.getmtime(cur_file), os.path.getctime(cur_file)] - for t in file_time: - if t > time.time() - 60: - file_too_new = tryInt(time.time() - t) - break + if check_file_date: + files_too_new, time_string = self.checkFilesChanged(group['unsorted_files']) + if files_too_new: + log.info('Files seem to be still unpacking or just unpacked (created on %s), ignoring for now: %s', (time_string, identifier)) - if file_too_new: - break + # Delete the unsorted list + del group['unsorted_files'] - if check_file_date and file_too_new: - try: - time_string = time.ctime(file_time[0]) - except: - try: - time_string = time.ctime(file_time[1]) - except: - time_string = 'unknown' - - log.info('Files seem to be still unpacking or just unpacked (created on %s), ignoring for now: %s', (time_string, identifier)) - - # Delete the unsorted list - del group['unsorted_files'] - - continue + continue # Only process movies newer than x if newer_than and newer_than > 0: has_new_files = False for cur_file in group['unsorted_files']: - file_time = [os.path.getmtime(cur_file), os.path.getctime(cur_file)] + file_time = self.getFileTimes(cur_file) if file_time[0] > newer_than or file_time[1] > newer_than: has_new_files = True break diff --git a/couchpotato/core/providers/nzb/nzbclub/main.py b/couchpotato/core/providers/nzb/nzbclub/main.py index 75f99ed6..44121a60 100644 --- a/couchpotato/core/providers/nzb/nzbclub/main.py +++ b/couchpotato/core/providers/nzb/nzbclub/main.py @@ -22,8 +22,11 @@ class NZBClub(NZBProvider, RSS): q = '"%s %s"' % (title, movie['info']['year']) - params = tryUrlencode({ + q_param = tryUrlencode({ 'q': q, + }) + + params = tryUrlencode({ 'ig': 1, 'rpp': 200, 'st': 5, @@ -31,7 +34,7 @@ class NZBClub(NZBProvider, RSS): 'ns': 1, }) - nzbs = self.getRSSData(self.urls['search'] % params) + nzbs = self.getRSSData(self.urls['search'] % ('%s&%s' % (q_param, params))) for nzb in nzbs: