Merge pull request #2607 from mano3m/develop_no_ren

Mark release as downloaded if renamer is disabled.
This commit is contained in:
Joel Kåberg
2013-12-19 10:30:12 -08:00
+37 -27
View File
@@ -211,7 +211,12 @@ class Release(Plugin):
db = get_session() db = get_session()
rel = db.query(Relea).filter_by(id = id).first() rel = db.query(Relea).filter_by(id = id).first()
if rel: if not rel:
log.error('Couldn\'t find release with id: %s', id)
return {
'success': False
}
item = {} item = {}
for info in rel.info: for info in rel.info:
item[info.identifier] = info.value item[info.identifier] = info.value
@@ -221,6 +226,7 @@ class Release(Plugin):
# Get matching provider # Get matching provider
provider = fireEvent('provider.belongs_to', item['url'], provider = item.get('provider'), single = True) provider = fireEvent('provider.belongs_to', item['url'], provider = item.get('provider'), single = True)
# Backwards compatibility code
if not item.get('protocol'): if not item.get('protocol'):
item['protocol'] = item['type'] item['protocol'] = item['type']
item['type'] = 'movie' item['type'] = 'movie'
@@ -243,41 +249,43 @@ class Release(Plugin):
return { return {
'success': success 'success': success
} }
else:
log.error('Couldn\'t find release with id: %s', id)
return {
'success': False
}
def download(self, data, media, manual = False): def download(self, data, media, manual = False):
# Backwards compatibility code
if not data.get('protocol'): if not data.get('protocol'):
data['protocol'] = data['type'] data['protocol'] = data['type']
data['type'] = 'movie' data['type'] = 'movie'
# Test to see if any downloaders are enabled for this type # Test to see if any downloaders are enabled for this type
downloader_enabled = fireEvent('download.enabled', manual, data, single = True) downloader_enabled = fireEvent('download.enabled', manual, data, single = True)
if not downloader_enabled:
log.info('Tried to download, but none of the "%s" downloaders are enabled or gave an error', (data.get('protocol')))
return False
if downloader_enabled: # Download NZB or torrent file
snatched_status, done_status, active_status = fireEvent('status.get', ['snatched', 'done', 'active'], single = True)
# Download release to temp
filedata = None filedata = None
if data.get('download') and (ismethod(data.get('download')) or isfunction(data.get('download'))): if data.get('download') and (ismethod(data.get('download')) or isfunction(data.get('download'))):
filedata = data.get('download')(url = data.get('url'), nzb_id = data.get('id')) filedata = data.get('download')(url = data.get('url'), nzb_id = data.get('id'))
if filedata == 'try_next': if filedata == 'try_next':
return filedata return filedata
# Send NZB or torrent file to downloader
download_result = fireEvent('download', data = data, media = media, manual = manual, filedata = filedata, single = True) download_result = fireEvent('download', data = data, media = media, manual = manual, filedata = filedata, single = True)
if not download_result:
log.info('Tried to download, but the "%s" downloader gave an error', (data.get('protocol')))
return False
log.debug('Downloader result: %s', download_result) log.debug('Downloader result: %s', download_result)
if download_result: snatched_status, done_status, downloaded_status, active_status = fireEvent('status.get', ['snatched', 'done', 'downloaded', 'active'], single = True)
try: try:
# Mark release as snatched
db = get_session() db = get_session()
rls = db.query(Relea).filter_by(identifier = md5(data['url'])).first() rls = db.query(Relea).filter_by(identifier = md5(data['url'])).first()
if rls: if not rls:
log.error('No release found to store download information in')
return False
renamer_enabled = Env.setting('enabled', 'renamer') renamer_enabled = Env.setting('enabled', 'renamer')
# Save download-id info if returned # Save download-id info if returned
@@ -295,12 +303,16 @@ class Release(Plugin):
log.info(snatch_message) log.info(snatch_message)
fireEvent('%s.snatched' % data['type'], message = snatch_message, data = rls.to_dict()) fireEvent('%s.snatched' % data['type'], message = snatch_message, data = rls.to_dict())
# If renamer isn't used, mark media done # Mark release as snatched
if not renamer_enabled: if renamer_enabled:
try: self.updateStatus(rls.id, status = snatched_status)
# If renamer isn't used, mark media done if finished or release downloaded
else:
if media['status_id'] == active_status.get('id'): if media['status_id'] == active_status.get('id'):
for profile_type in media['profile']['types']: finished = next((True for profile_type in media['profile']['types'] if \
if profile_type['quality_id'] == rls.quality.id and profile_type['finish']: profile_type['quality_id'] == rls.quality.id and profile_type['finish']), False)
if finished:
log.info('Renamer disabled, marking media as finished: %s', log_movie) log.info('Renamer disabled, marking media as finished: %s', log_movie)
# Mark release done # Mark release done
@@ -311,20 +323,18 @@ class Release(Plugin):
mdia.status_id = done_status.get('id') mdia.status_id = done_status.get('id')
mdia.last_edit = int(time.time()) mdia.last_edit = int(time.time())
db.commit() db.commit()
except:
log.error('Failed marking media finished, renamer disabled: %s', traceback.format_exc())
else:
self.updateStatus(rls.id, status = snatched_status)
except:
log.error('Failed marking media finished: %s', traceback.format_exc())
return True return True
log.info('Tried to download, but none of the "%s" downloaders are enabled or gave an error', (data.get('protocol'))) # Assume release downloaded
self.updateStatus(rls.id, status = downloaded_status)
except:
log.error('Failed storing download status: %s', traceback.format_exc())
return False return False
return True
def tryDownloadResult(self, results, media, quality_type, manual = False): def tryDownloadResult(self, results, media, quality_type, manual = False):
ignored_status, failed_status = fireEvent('status.get', ['ignored', 'failed'], single = True) ignored_status, failed_status = fireEvent('status.get', ['ignored', 'failed'], single = True)