Check release type by info
This commit is contained in:
1 parent
58ad5c3938
commit
384a355a53
2 files changed
+20
-25
No files matched your search
@@ -39,13 +39,6 @@ class Downloader(Provider):
|
|||||||
addEvent('download.enabled_types', self.getEnabledDownloadType)
|
addEvent('download.enabled_types', self.getEnabledDownloadType)
|
||||||
addEvent('download.status', self._getAllDownloadStatus)
|
addEvent('download.status', self._getAllDownloadStatus)
|
||||||
addEvent('download.remove_failed', self._removeFailed)
|
addEvent('download.remove_failed', self._removeFailed)
|
||||||
addEvent('download.downloader_type', self.getDownloaderType)
|
|
||||||
|
|
||||||
def getDownloaderType(self, downloader):
|
|
||||||
if self.getName() == downloader:
|
|
||||||
return self.type
|
|
||||||
|
|
||||||
return []
|
|
||||||
|
|
||||||
def getEnabledDownloadType(self):
|
def getEnabledDownloadType(self):
|
||||||
for download_type in self.type:
|
for download_type in self.type:
|
||||||
|
|||||||
@@ -70,15 +70,14 @@ class Renamer(Plugin):
|
|||||||
|
|
||||||
fireEventAsync('renamer.scan',
|
fireEventAsync('renamer.scan',
|
||||||
movie_folder = movie_folder,
|
movie_folder = movie_folder,
|
||||||
downloader = downloader,
|
download_info = {'id': download_id, 'downloader': downloader} if download_id else None
|
||||||
download_id = download_id
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return jsonified({
|
return jsonified({
|
||||||
'success': True
|
'success': True
|
||||||
})
|
})
|
||||||
|
|
||||||
def scan(self, movie_folder = None, downloader = None, download_id = None):
|
def scan(self, movie_folder = None, download_info = None):
|
||||||
|
|
||||||
if self.isDisabled():
|
if self.isDisabled():
|
||||||
return
|
return
|
||||||
@@ -118,8 +117,8 @@ class Renamer(Plugin):
|
|||||||
|
|
||||||
db = get_session()
|
db = get_session()
|
||||||
|
|
||||||
# Get the download info stored in the downloaded release
|
# Extend the download info with info stored in the downloaded release
|
||||||
download_info = self.getDownloadInfo(download_id = download_id, downloader = downloader)
|
download_info = self.extendDownloadInfo(download_info)
|
||||||
|
|
||||||
groups = fireEvent('scanner.scan', folder = folder if folder else self.conf('from'),
|
groups = fireEvent('scanner.scan', folder = folder if folder else self.conf('from'),
|
||||||
files = files, download_info = download_info, return_ignored = False, single = True)
|
files = files, download_info = download_info, return_ignored = False, single = True)
|
||||||
@@ -377,7 +376,7 @@ class Renamer(Plugin):
|
|||||||
|
|
||||||
# Remove leftover files
|
# Remove leftover files
|
||||||
if self.conf('cleanup') and not self.conf('move_leftover') and remove_leftovers and \
|
if self.conf('cleanup') and not self.conf('move_leftover') and remove_leftovers and \
|
||||||
not (self.conf('file_action') != 'move' and download_info and download_info.get('is_torrent')):
|
not (self.conf('file_action') != 'move' and self.downloadIsTorrent(download_info)):
|
||||||
log.debug('Removing leftover files')
|
log.debug('Removing leftover files')
|
||||||
for current_file in group['files']['leftover']:
|
for current_file in group['files']['leftover']:
|
||||||
remove_files.append(current_file)
|
remove_files.append(current_file)
|
||||||
@@ -427,13 +426,13 @@ class Renamer(Plugin):
|
|||||||
self.makeDir(os.path.dirname(dst))
|
self.makeDir(os.path.dirname(dst))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.moveFile(src, dst, forcemove = not (download_info and download_info.get('is_torrent')))
|
self.moveFile(src, dst, forcemove = not self.downloadIsTorrent(download_info))
|
||||||
group['renamed_files'].append(dst)
|
group['renamed_files'].append(dst)
|
||||||
except:
|
except:
|
||||||
log.error('Failed moving the file "%s" : %s', (os.path.basename(src), traceback.format_exc()))
|
log.error('Failed moving the file "%s" : %s', (os.path.basename(src), traceback.format_exc()))
|
||||||
self.tagDir(group, 'failed_rename')
|
self.tagDir(group, 'failed_rename')
|
||||||
|
|
||||||
if self.conf('file_action') != 'move' and download_info and download_info.get('is_torrent'):
|
if self.conf('file_action') != 'move' and self.downloadIsTorrent(download_info):
|
||||||
self.tagDir(group, 'renamed already')
|
self.tagDir(group, 'renamed already')
|
||||||
|
|
||||||
# Remove matching releases
|
# Remove matching releases
|
||||||
@@ -657,7 +656,7 @@ Remove it if you want it to be renamed (again, or at least let it try again)
|
|||||||
elif item['status'] == 'completed':
|
elif item['status'] == 'completed':
|
||||||
log.info('Download of %s completed!', item['name'])
|
log.info('Download of %s completed!', item['name'])
|
||||||
if item['id'] and item['downloader'] and item['folder']:
|
if item['id'] and item['downloader'] and item['folder']:
|
||||||
fireEvent('renamer.scan', movie_folder = item['folder'], downloader = item['downloader'], download_id = item['id'])
|
fireEventAsync('renamer.scan', movie_folder = item['folder'], download_info = item)
|
||||||
else:
|
else:
|
||||||
scan_required = True
|
scan_required = True
|
||||||
|
|
||||||
@@ -677,17 +676,16 @@ Remove it if you want it to be renamed (again, or at least let it try again)
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def getDownloadInfo(self, download_id, downloader):
|
def extendDownloadInfo(self, download_info):
|
||||||
|
|
||||||
rls = None
|
rls = None
|
||||||
download_info = None
|
|
||||||
|
|
||||||
if download_id and downloader:
|
if download_info and download_info.get('id') and download_info.get('downloader'):
|
||||||
|
|
||||||
db = get_session()
|
db = get_session()
|
||||||
|
|
||||||
rlsnfo_dwnlds = db.query(ReleaseInfo).filter_by(identifier = 'download_downloader', value = downloader).all()
|
rlsnfo_dwnlds = db.query(ReleaseInfo).filter_by(identifier = 'download_downloader', value = download_info.get('downloader')).all()
|
||||||
rlsnfo_ids = db.query(ReleaseInfo).filter_by(identifier = 'download_id', value = download_id).all()
|
rlsnfo_ids = db.query(ReleaseInfo).filter_by(identifier = 'download_id', value = download_info.get('id')).all()
|
||||||
|
|
||||||
for rlsnfo_dwnld in rlsnfo_dwnlds:
|
for rlsnfo_dwnld in rlsnfo_dwnlds:
|
||||||
for rlsnfo_id in rlsnfo_ids:
|
for rlsnfo_id in rlsnfo_ids:
|
||||||
@@ -697,14 +695,18 @@ Remove it if you want it to be renamed (again, or at least let it try again)
|
|||||||
if rls: break
|
if rls: break
|
||||||
|
|
||||||
if not rls:
|
if not rls:
|
||||||
log.error('Download ID %s from downloader %s not found in releases', (download_id, downloader))
|
log.error('Download ID %s from downloader %s not found in releases', (download_info.get('id'), download_info.get('downloader')))
|
||||||
|
|
||||||
if rls:
|
if rls:
|
||||||
download_info = {
|
|
||||||
|
rls_dict = rls.to_dict({'info':{}})
|
||||||
|
download_info.update({
|
||||||
'imdb_id': rls.movie.library.identifier,
|
'imdb_id': rls.movie.library.identifier,
|
||||||
'quality': rls.quality.identifier,
|
'quality': rls.quality.identifier,
|
||||||
'is_torrent': any(downloader_type in fireEvent('download.downloader_type', downloader = downloader) for downloader_type in ['torrent', 'torrent_magnet'])
|
'type': rls_dict.get('info', {}).get('type')
|
||||||
}
|
})
|
||||||
|
|
||||||
return download_info
|
return download_info
|
||||||
|
|
||||||
|
def downloadIsTorrent(self, download_info):
|
||||||
|
return download_info and download_info.get('type') in ['torrent', 'torrent_magnet']
|
||||||
Reference in new issue
Block a user