You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
3.7 KiB

import traceback
14 years ago
from couchpotato import get_session
14 years ago
from couchpotato.api import addApiView
14 years ago
from couchpotato.core.event import addEvent
14 years ago
from couchpotato.core.helpers.encoding import toUnicode
from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin
14 years ago
from couchpotato.core.settings.model import Status
log = CPLog(__name__)
class StatusPlugin(Plugin):
14 years ago
statuses = {
'needs_update': 'Needs update',
14 years ago
'active': 'Active',
'done': 'Done',
'downloaded': 'Downloaded',
'wanted': 'Wanted',
'snatched': 'Snatched',
'failed': 'Failed',
14 years ago
'deleted': 'Deleted',
'ignored': 'Ignored',
'available': 'Available',
12 years ago
'suggest': 'Suggest',
Seeding support Design intent: - Option to turn seeding support on or off - After torrent downloading is complete the seeding phase starts, seeding parameters can be set per torrent provide (0 disables them) - When the seeding phase starts the checkSnatched function renames all files if (sym)linking/copying is used. The movie is set to done (!), the release to seeding status. - Note that Direct symlink functionality is removed as the original file needs to end up in the movies store and not the downloader store (if the downloader cleans up his files, the original is deleted and the symlinks are useless) - checkSnatched waits until downloader sets the download to completed (met the seeding parameters) - When completed, checkSnatched intiates the renamer if move is used, or if linking is used asks the downloader to remove the torrent and clean-up it's files and sets the release to downloaded - Updated some of the .ignore file behavior to allow the downloader to remove its files Known items/issues: - only implemented for uTorrent and Transmission - text in downloader settings is too long and messes up the layout... To do (after this PR): - implement for other torrent downloaders - complete download removal for NZBs (remove from history in sabNZBd) - failed download management for torrents (no seeders, takes too long, etc.) - unrar support Updates: - Added transmission support - Simplified uTorrent - Added checkSnatched to renamer to make sure the poller is always first - Updated default values and removed advanced option tag for providers - Updated the tagger to allow removing of ignore tags and tagging when the group is not known - Added tagging of downloading torrents - fixed subtitles being leftover after seeding
12 years ago
'seeding': 'Seeding',
'missing': 'Missing',
14 years ago
}
status_cached = {}
14 years ago
def __init__(self):
addEvent('status.get', self.get)
14 years ago
addEvent('status.get_by_id', self.getById)
14 years ago
addEvent('status.all', self.all)
addEvent('app.initialize', self.fill)
11 years ago
addEvent('app.load', self.all) # Cache all statuses
14 years ago
addApiView('status.list', self.list, docs = {
'desc': 'Check for available update',
'return': {'type': 'object', 'example': """{
'success': True,
'list': array, statuses
}"""}
})
14 years ago
def list(self, **kwargs):
14 years ago
return {
14 years ago
'success': True,
'list': self.all()
}
14 years ago
14 years ago
def getById(self, id):
db = get_session()
status = db.query(Status).filter_by(id = id).first()
status_dict = status.to_dict()
11 years ago
db.close()
return status_dict
14 years ago
14 years ago
def all(self):
db = get_session()
statuses = db.query(Status).all()
temp = []
for status in statuses:
s = status.to_dict()
temp.append(s)
# Update cache
self.status_cached[status.identifier] = s
11 years ago
db.close()
14 years ago
return temp
def get(self, identifiers):
14 years ago
12 years ago
if not isinstance(identifiers, list):
identifiers = [identifiers]
try:
db = get_session()
return_list = []
14 years ago
for identifier in identifiers:
14 years ago
if self.status_cached.get(identifier):
return_list.append(self.status_cached.get(identifier))
continue
s = db.query(Status).filter_by(identifier = identifier).first()
if not s:
s = Status(
identifier = identifier,
label = toUnicode(identifier.capitalize())
)
db.add(s)
db.commit()
status_dict = s.to_dict()
self.status_cached[identifier] = status_dict
return_list.append(status_dict)
return return_list if len(identifiers) > 1 else return_list[0]
except:
log.error('Failed: %s', traceback.format_exc())
db.rollback()
finally:
db.close()
14 years ago
def fill(self):
try:
db = get_session()
14 years ago
for identifier, label in self.statuses.items():
s = db.query(Status).filter_by(identifier = identifier).first()
if not s:
log.info('Creating status: %s', label)
s = Status(
identifier = identifier,
label = toUnicode(label)
)
db.add(s)
s.label = toUnicode(label)
db.commit()
except:
log.error('Failed: %s', traceback.format_exc())
db.rollback()
finally:
db.close()