Put the renamer as a function of a download status checker in the searcher class

The changed functionality is as follows:
- the renamer is not on scheduled interval anymore
- the download status checker checks the status of all snatched releases every x minutes
- if a release has downloaded it fires up the renamer (if enabled)
- if it failed, it sets the release to ignored and snatches the next best release

With these additions the renamer wont scan your hd anymore when it is not required, and will retry failed downloads with new releases.

To do:
- the only downloader implemented is SabNZBd, for the others it defaults to the old behavior when releases are snatched (I think!?)
- a button to scan manually: Items added to the renamer folder are only picked up after a download completed
This commit is contained in:
mano3m committed 2012-08-02 18:59:04 +02:00
1 parent 100b563e10
commit 4223ed4b5a
7 files changed
+172 -108

No files matched your search

@@ -86,15 +86,6 @@ config = [{
'label': 'Separator',
'description': 'Replace all the spaces with a character. Example: ".", "-" (without quotes). Leave empty to use spaces.',
},
{
'advanced': True,
'name': 'run_every',
'label': 'Run every',
'default': 1,
'type': 'int',
'unit': 'min(s)',
'description': 'Search for new movies inside the folder every X minutes.',
},
],
}, {
'tab': 'renamer',
+1 -56
View File
@@ -29,7 +29,7 @@ class Renamer(Plugin):
addEvent('renamer.scan', self.scan)
addEvent('app.load', self.scan)
fireEvent('schedule.interval', 'renamer.scan', self.scan, minutes = self.conf('run_every'))
#fireEvent('schedule.interval', 'renamer.scan', self.scan, minutes = self.conf('run_every'))
def scanView(self):
@@ -48,8 +48,6 @@ class Renamer(Plugin):
log.info('Renamer is disabled to avoid infinite looping of the same error.')
return
self.checkSnatchedStatusses()
# Check to see if the "to" folder is inside the "from" folder.
if not os.path.isdir(self.conf('from')) or not os.path.isdir(self.conf('to')):
log.debug('"To" and "From" have to exist.')
@@ -474,57 +472,4 @@ class Renamer(Plugin):
except:
log.error('Couldn\'t remove empty directory %s: %s', (folder, traceback.format_exc()))
def checkSnatchedStatusses(self):
snatched_status = fireEvent('status.get', 'snatched', single = True)
ignored_status = fireEvent('status.get', 'ignored', single = True)
db = get_session()
rels = db.query(Relea).filter_by(status_id = snatched_status.get('id'))
for rel in rels:
# Get current selected title
default_title = ''
for title in rel.movie.library.titles:
if title.default: default_title = title.title
log.debug('Checking snatched movie: %s' , default_title)
item = {}
for info in rel.info:
item[info.identifier] = info.value
log.debug('Checking status snatched release: %s' , item.get('name'))
mov = rel.movie.to_dict({
'profile': {'types': {'quality': {}}},
'releases': {'status': {}, 'quality': {}},
'library': {'titles': {}, 'files':{}},
'files': {}
})
# check status
downloadfailed = fireEvent('getdownloadfailed', data = item, movie = mov)
if downloadfailed:
# if failed set status to ignored
rel.status_id = ignored_status.get('id')
db.commit()
# search/download again
# if downloaded manually: # this is currently not stored...
# log.info('Download of %s failed...', item['name'])
# return
#update movie to reflect release status update
mov = rel.movie.to_dict({
'profile': {'types': {'quality': {}}},
'releases': {'status': {}, 'quality': {}},
'library': {'titles': {}, 'files':{}},
'files': {}
})
log.info('Download of %s failed, trying next release...', item['name'])
fireEvent('searcher.single', mov)
return