Merge branch 'refs/heads/develop'

This commit is contained in:
Ruud
2013-09-18 23:06:29 +02:00
2 changed files with 32 additions and 17 deletions
+18 -5
View File
@@ -819,6 +819,13 @@ class Scanner(Plugin):
return None
def findYear(self, text):
# Search year inside () or [] first
matches = re.search('(\(|\[)(?P<year>19[0-9]{2}|20[0-9]{2})(\]|\))', text)
if matches:
return matches.group('year')
# Search normal
matches = re.search('(?P<year>19[0-9]{2}|20[0-9]{2})', text)
if matches:
return matches.group('year')
@@ -831,11 +838,11 @@ class Scanner(Plugin):
guess = {}
if file_name:
try:
guess = guess_movie_info(toUnicode(file_name))
if guess.get('title') and guess.get('year'):
guessit = guess_movie_info(toUnicode(file_name))
if guessit.get('title') and guessit.get('year'):
guess = {
'name': guess.get('title'),
'year': guess.get('year'),
'name': guessit.get('title'),
'year': guessit.get('year'),
}
except:
log.debug('Could not detect via guessit "%s": %s', (file_name, traceback.format_exc()))
@@ -843,7 +850,13 @@ class Scanner(Plugin):
# Backup to simple
cleaned = ' '.join(re.split('\W+', simplifyString(release_name)))
cleaned = re.sub(self.clean, ' ', cleaned)
year = self.findYear(cleaned)
for year_str in [file_name, cleaned]:
if not year_str: continue
year = self.findYear(year_str)
if year:
break
cp_guess = {}
if year: # Split name on year
+14 -12
View File
@@ -84,18 +84,6 @@ def runCouchPotato(options, base_path, args, data_dir = None, log_dir = None, En
# Backup before start and cleanup old databases
new_backup = toUnicode(os.path.join(data_dir, 'db_backup', str(int(time.time()))))
# Create path and copy
if not os.path.isdir(new_backup): os.makedirs(new_backup)
src_files = [options.config_file, db_path, db_path + '-shm', db_path + '-wal']
for src_file in src_files:
if os.path.isfile(src_file):
dst_file = toUnicode(os.path.join(new_backup, os.path.basename(src_file)))
shutil.copyfile(src_file, dst_file)
# Try and copy stats seperately
try: shutil.copystat(src_file, dst_file)
except: pass
# Remove older backups, keep backups 3 days or at least 3
backups = []
for directory in os.listdir(os.path.dirname(new_backup)):
@@ -103,6 +91,20 @@ def runCouchPotato(options, base_path, args, data_dir = None, log_dir = None, En
if os.path.isdir(backup):
backups.append(backup)
latest_backup = tryInt(os.path.basename(sorted(backups)[-1])) if len(backups) > 0 else 0
if latest_backup < time.time() - 3600:
# Create path and copy
if not os.path.isdir(new_backup): os.makedirs(new_backup)
src_files = [options.config_file, db_path, db_path + '-shm', db_path + '-wal']
for src_file in src_files:
if os.path.isfile(src_file):
dst_file = toUnicode(os.path.join(new_backup, os.path.basename(src_file)))
shutil.copyfile(src_file, dst_file)
# Try and copy stats seperately
try: shutil.copystat(src_file, dst_file)
except: pass
total_backups = len(backups)
for backup in backups:
if total_backups > 3: