3 changed files with 86 additions and 1 deletions
@ -1,13 +1,44 @@ |
|||||
from couchpotato.core.event import addEvent |
from couchpotato import get_session |
||||
|
from couchpotato.core.event import addEvent, fireEventAsync, fireEvent |
||||
from couchpotato.core.plugins.base import Plugin |
from couchpotato.core.plugins.base import Plugin |
||||
|
from couchpotato.core.settings.model import Media |
||||
|
|
||||
|
|
||||
class MediaBase(Plugin): |
class MediaBase(Plugin): |
||||
|
|
||||
_type = None |
_type = None |
||||
|
|
||||
|
default_dict = { |
||||
|
'profile': {'types': {'quality': {}}}, |
||||
|
'releases': {'status': {}, 'quality': {}, 'files':{}, 'info': {}}, |
||||
|
'library': {'titles': {}, 'files':{}}, |
||||
|
'files': {}, |
||||
|
'status': {}, |
||||
|
'category': {}, |
||||
|
} |
||||
|
|
||||
def initType(self): |
def initType(self): |
||||
addEvent('media.types', self.getType) |
addEvent('media.types', self.getType) |
||||
|
|
||||
def getType(self): |
def getType(self): |
||||
return self._type |
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.default_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.%s' % (media.type, media.id), data = media.to_dict(self.default_dict)) |
||||
|
db.expire_all() |
||||
|
|
||||
|
return notifyFront |
||||
|
@ -0,0 +1,6 @@ |
|||||
|
from .main import Media |
||||
|
|
||||
|
def start(): |
||||
|
return Media() |
||||
|
|
||||
|
config = [] |
@ -0,0 +1,48 @@ |
|||||
|
from couchpotato import get_session |
||||
|
from couchpotato.api import addApiView |
||||
|
from couchpotato.core.event import fireEvent, fireEventAsync, addEvent |
||||
|
from couchpotato.core.helpers.variable import splitString |
||||
|
from couchpotato.core.logger import CPLog |
||||
|
from couchpotato.core.media import MediaBase |
||||
|
|
||||
|
log = CPLog(__name__) |
||||
|
|
||||
|
|
||||
|
class Media(MediaBase): |
||||
|
|
||||
|
def __init__(self): |
||||
|
|
||||
|
addApiView('media.refresh', self.refresh, docs = { |
||||
|
'desc': 'Refresh a any media type by ID', |
||||
|
'params': { |
||||
|
'id': {'desc': 'Movie, Show, Season or Episode ID(s) you want to refresh.', 'type': 'int (comma separated)'}, |
||||
|
} |
||||
|
}) |
||||
|
|
||||
|
addEvent('app.load', self.addSingleRefresh) |
||||
|
|
||||
|
def refresh(self, id = '', **kwargs): |
||||
|
db = get_session() |
||||
|
|
||||
|
for x in splitString(id): |
||||
|
media = db.query(Media).filter_by(id = x).first() |
||||
|
|
||||
|
if media: |
||||
|
# Get current selected title |
||||
|
default_title = '' |
||||
|
for title in media.library.titles: |
||||
|
if title.default: default_title = title.title |
||||
|
|
||||
|
fireEvent('notify.frontend', type = '%s.busy.%s' % (media.type, x), data = True) |
||||
|
fireEventAsync('library.update.%s' % media.type, identifier = media.library.identifier, default_title = default_title, force = True, on_complete = self.createOnComplete(x)) |
||||
|
|
||||
|
db.expire_all() |
||||
|
|
||||
|
return { |
||||
|
'success': True, |
||||
|
} |
||||
|
|
||||
|
def addSingleRefresh(self): |
||||
|
|
||||
|
for media_type in fireEvent('media.types', merge = True): |
||||
|
addApiView('%s.refresh' % media_type, self.refresh) |
Loading…
Reference in new issue