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.
52 lines
1.5 KiB
52 lines
1.5 KiB
from couchpotato import get_session
|
|
from couchpotato.core.event import addEvent, fireEventAsync, fireEvent
|
|
from couchpotato.core.helpers.variable import mergeDicts
|
|
from couchpotato.core.plugins.base import Plugin
|
|
from couchpotato.core.settings.model import Media
|
|
|
|
|
|
class MediaBase(Plugin):
|
|
|
|
_type = None
|
|
|
|
default_dict = {
|
|
'profile': {'types': {'quality': {}}},
|
|
'releases': {'status': {}, 'quality': {}, 'files':{}, 'info': {}},
|
|
'library': {'titles': {}, 'files':{}},
|
|
'files': {},
|
|
'status': {},
|
|
'category': {},
|
|
}
|
|
|
|
search_dict = mergeDicts(default_dict, {
|
|
'library': {
|
|
'related_libraries': {},
|
|
'root_library': {}
|
|
},
|
|
})
|
|
|
|
def initType(self):
|
|
addEvent('media.types', self.getType)
|
|
|
|
def getType(self):
|
|
return self._type
|
|
|
|
def createOnComplete(self, id):
|
|
|
|
def onComplete():
|
|
db = get_session()
|
|
media = db.query(Media).filter_by(id = id).first()
|
|
fireEventAsync('%s.searcher.single' % media.type, media.to_dict(self.search_dict), on_complete = self.createNotifyFront(id))
|
|
db.expire_all()
|
|
|
|
return onComplete
|
|
|
|
def createNotifyFront(self, media_id):
|
|
|
|
def notifyFront():
|
|
db = get_session()
|
|
media = db.query(Media).filter_by(id = media_id).first()
|
|
fireEvent('notify.frontend', type = '%s.update' % media.type, data = media.to_dict(self.default_dict))
|
|
db.expire_all()
|
|
|
|
return notifyFront
|
|
|