Merge branch 'develop4' of https://github.com/mano3m/CouchPotatoServer into mano3m-develop4

This commit is contained in:
Ruud
2012-08-05 16:41:35 +02:00
7 changed files with 210 additions and 17 deletions
@@ -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 -1
View File
@@ -30,7 +30,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):
@@ -39,6 +39,22 @@ config = [{
'type': 'dropdown',
'values': [('usenet & torrents', 'both'), ('usenet', 'nzb'), ('torrents', 'torrent')],
},
{
'advanced': True,
'name': 'run_every',
'label': 'Run every',
'default': 1,
'type': 'int',
'unit': 'min(s)',
'description': 'Detect movie status every X minutes. Will start the renamer if movie is <strong>completed</strong> or handle <strong>failed</strong> download if these options are enabled',
},
{
'name': 'failed download',
'default': True,
'type': 'bool',
'advanced': True,
'description': 'Try the next best release for a movie after a download failed.',
},
],
}, {
'tab': 'searcher',
+81
View File
@@ -25,9 +25,12 @@ class Searcher(Plugin):
addEvent('searcher.single', self.single)
addEvent('searcher.correct_movie', self.correctMovie)
addEvent('searcher.download', self.download)
addEvent('searcher.checksnatched', self.checksnatched)
# Schedule cronjob
fireEvent('schedule.cron', 'searcher.all', self.all_movies, day = self.conf('cron_day'), hour = self.conf('cron_hour'), minute = self.conf('cron_minute'))
fireEvent('schedule.interval', 'searcher.checksnatched', self.checksnatched, minutes = self.conf('run_every'))
def all_movies(self):
@@ -439,3 +442,81 @@ class Searcher(Plugin):
return False
def checksnatched(self):
snatched_status = fireEvent('status.get', 'snatched', single = True)
ignored_status = fireEvent('status.get', 'ignored', single = True)
db = get_session()
rels = db.query(Release).filter_by(status_id = snatched_status.get('id'))
log.info('Checking status snatched releases...')
scanrequired = False
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
movie = rel.movie.to_dict({
'profile': {'types': {'quality': {}}},
'releases': {'status': {}, 'quality': {}},
'library': {'titles': {}, 'files':{}},
'files': {}
})
# check status
downloadstatus = fireEvent('getdownloadstatus', data = item, movie = movie)
if not downloadstatus: # Downloader not compatible with download status
log.debug('Download status functionality is not implemented for active downloaders.')
scanrequired = True
else:
log.debug('Download status: %s' , downloadstatus[0])
if downloadstatus[0] == 'Failed':
# 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
if self.conf('failed download', default = True):
#update movie to reflect release status update
movie = 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', movie)
else:
log.info('Download of %s failed.', item['name'])
elif downloadstatus[0] == 'Completed':
log.info('Download of %s completed!', item['name'])
scanrequired = True
elif downloadstatus[0] == 'Not found':
log.info('%s not found in downloaders', item['name'])
rel.status_id = ignored_status.get('id')
db.commit()
# Note that Queued, Downloading, Paused, Repair and Unpackimg are also available as status for SabNZBd
if scanrequired:
fireEvent('renamer.scan')
return