Searcher and renamer fixes
This commit is contained in:
1 parent
800b5ce3d6
commit
dc4b4676f6
9 files changed
+115
-63
No files matched your search
@@ -1,5 +1,5 @@
|
||||
from couchpotato import get_session
|
||||
from couchpotato.core.event import addEvent, fireEvent
|
||||
from couchpotato.core.event import addEvent, fireEvent, fireEventAsync
|
||||
from couchpotato.core.helpers.encoding import toUnicode
|
||||
from couchpotato.core.helpers.variable import getExt
|
||||
from couchpotato.core.logger import CPLog
|
||||
@@ -40,7 +40,7 @@ class Renamer(Plugin):
|
||||
group = groups[group_identifier]
|
||||
rename_files = {}
|
||||
|
||||
# Add _UNKNOWN_ if no library is connected
|
||||
# Add _UNKNOWN_ if no library item is connected
|
||||
if not group['library']:
|
||||
if group['dirname']:
|
||||
rename_files[group['parentdir']] = group['parentdir'].replace(group['dirname'], '_UNKNOWN_%s' % group['dirname'])
|
||||
@@ -53,6 +53,10 @@ class Renamer(Plugin):
|
||||
# Rename the files using the library data
|
||||
else:
|
||||
group['library'] = fireEvent('library.update', identifier = group['library']['identifier'], single = True)
|
||||
if not group['library']:
|
||||
log.error('Could not rename, no library item to work with: %s' % group_identifier)
|
||||
continue
|
||||
|
||||
library = group['library']
|
||||
|
||||
# Find subtitle for renaming
|
||||
@@ -85,12 +89,9 @@ class Renamer(Plugin):
|
||||
|
||||
for file_type in group['files']:
|
||||
|
||||
# Move DVD files (no renaming)
|
||||
if group['is_dvd'] and file_type is 'movie':
|
||||
continue
|
||||
|
||||
# Move nfo depending on settings
|
||||
if file_type is 'nfo' and not self.conf('rename_nfo'):
|
||||
log.debug('Skipping, renaming of %s disabled' % file_type)
|
||||
continue
|
||||
|
||||
# Subtitle extra
|
||||
@@ -98,7 +99,7 @@ class Renamer(Plugin):
|
||||
continue
|
||||
|
||||
# Move other files
|
||||
multiple = len(group['files']['movie']) > 1
|
||||
multiple = len(group['files']['movie']) > 1 and not group['is_dvd']
|
||||
cd = 1 if multiple else 0
|
||||
|
||||
for file in sorted(list(group['files'][file_type])):
|
||||
@@ -123,7 +124,7 @@ class Renamer(Plugin):
|
||||
if file_type is 'trailer':
|
||||
final_file_name = self.doReplace(trailer_name, replacements)
|
||||
elif file_type is 'nfo':
|
||||
final_file_name = self.doReplace(nfo_name, replacements) + '-orig'
|
||||
final_file_name = self.doReplace(nfo_name, replacements)
|
||||
elif file_type is 'backdrop':
|
||||
final_file_name = self.doReplace(backdrop_name, replacements)
|
||||
|
||||
@@ -131,8 +132,13 @@ class Renamer(Plugin):
|
||||
if separator:
|
||||
final_file_name = final_file_name.replace(' ', separator)
|
||||
|
||||
# Main file
|
||||
rename_files[file] = os.path.join(destination, final_folder_name, final_file_name)
|
||||
# Move DVD files (no structure renaming)
|
||||
if group['is_dvd'] and file_type is 'movie':
|
||||
structure_dir = file.split(group['dirname'])[-1].lstrip(os.path.sep)
|
||||
rename_files[file] = os.path.join(destination, final_folder_name, structure_dir)
|
||||
# Do rename others
|
||||
else:
|
||||
rename_files[file] = os.path.join(destination, final_folder_name, final_file_name)
|
||||
|
||||
# Check for extra subtitle files
|
||||
if file_type is 'subtitle':
|
||||
@@ -154,17 +160,13 @@ class Renamer(Plugin):
|
||||
if multiple:
|
||||
cd += 1
|
||||
|
||||
# Notify on download
|
||||
download_message = 'Download of %s (%s) successful.' % (group['library']['titles'][0]['title'], replacements['quality'])
|
||||
fireEvent('movie.downloaded', message = download_message, data = group)
|
||||
|
||||
# Before renaming, remove the lower quality files
|
||||
db = get_session()
|
||||
library = db.query(Library).filter_by(identifier = group['library']['identifier']).first()
|
||||
done_status = fireEvent('status.get', 'done', single = True)
|
||||
for movie in library.movies:
|
||||
for release in movie.releases:
|
||||
if release.quality.order < group['meta_data']['quality']['order']:
|
||||
if release.quality.order > group['meta_data']['quality']['order']:
|
||||
log.info('Removing older release for %s, with quality %s' % (movie.library.titles[0].title, release.quality.label))
|
||||
elif release.status_id is done_status.get('id'):
|
||||
if release.quality.order is group['meta_data']['quality']['order']:
|
||||
@@ -200,21 +202,24 @@ class Renamer(Plugin):
|
||||
log.info('Renaming "%s" to "%s"' % (src, dst))
|
||||
|
||||
path = os.path.dirname(dst)
|
||||
try:
|
||||
if not os.path.isdir(path): os.makedirs(path)
|
||||
except:
|
||||
log.error('Failed creating dir %s: %s' % (path, traceback.format_exc()))
|
||||
continue
|
||||
|
||||
# Create dir
|
||||
self.makeDir(path)
|
||||
|
||||
try:
|
||||
shutil.move(src, dst)
|
||||
pass
|
||||
#shutil.move(src, dst)
|
||||
except:
|
||||
log.error('Failed moving the file "%s" : %s' % (os.path.basename(src), traceback.format_exc()))
|
||||
|
||||
#print rename_me, rename_files[rename_me]
|
||||
|
||||
# Search for trailers etc
|
||||
fireEvent('renamer.after', group)
|
||||
fireEventAsync('renamer.after', group)
|
||||
|
||||
# Notify on download
|
||||
download_message = 'Download of %s (%s) successful.' % (group['library']['titles'][0]['title'], replacements['quality'])
|
||||
fireEventAsync('movie.downloaded', message = download_message, data = group)
|
||||
|
||||
# Break if CP wants to shut down
|
||||
if self.shuttingDown():
|
||||
|
||||
Reference in new issue
Block a user