22 changed files with 377 additions and 128 deletions
@ -0,0 +1,35 @@ |
|||||
|
from .main import Manage |
||||
|
|
||||
|
def start(): |
||||
|
return Manage() |
||||
|
|
||||
|
config = [{ |
||||
|
'name': 'manage', |
||||
|
'groups': [ |
||||
|
{ |
||||
|
'tab': 'renamer', |
||||
|
'label': 'movie library manager', |
||||
|
'description': 'Add multiple movie folders.', |
||||
|
'wizard': True, |
||||
|
'options': [ |
||||
|
{ |
||||
|
'name': 'enabled', |
||||
|
'default': False, |
||||
|
'type': 'enabler', |
||||
|
}, |
||||
|
{ |
||||
|
'name': 'library', |
||||
|
'type': 'directories', |
||||
|
'description': 'Folder where the movies should be moved to.', |
||||
|
}, |
||||
|
{ |
||||
|
'label': 'Cleanup After', |
||||
|
'name': 'cleanup', |
||||
|
'type': 'bool', |
||||
|
'description': 'Remove movie from db if it can\'t be found after re-scan.', |
||||
|
'default': True, |
||||
|
}, |
||||
|
], |
||||
|
}, |
||||
|
], |
||||
|
}] |
@ -0,0 +1,65 @@ |
|||||
|
from couchpotato import get_session |
||||
|
from couchpotato.api import addApiView |
||||
|
from couchpotato.core.event import fireEvent, addEvent, fireEventAsync |
||||
|
from couchpotato.core.helpers.request import jsonified, getParams |
||||
|
from couchpotato.core.logger import CPLog |
||||
|
from couchpotato.core.plugins.base import Plugin |
||||
|
from couchpotato.core.settings.model import File |
||||
|
from couchpotato.environment import Env |
||||
|
import time |
||||
|
|
||||
|
|
||||
|
log = CPLog(__name__) |
||||
|
|
||||
|
class Manage(Plugin): |
||||
|
|
||||
|
last_update = 0 |
||||
|
|
||||
|
def __init__(self): |
||||
|
|
||||
|
fireEvent('scheduler.interval', identifier = 'manage.update_library', handle = self.updateLibrary, hours = 2) |
||||
|
|
||||
|
addEvent('manage.update', self.updateLibrary) |
||||
|
addApiView('manage.update', self.updateLibraryView) |
||||
|
|
||||
|
if not Env.setting('development'): |
||||
|
addEvent('app.load', self.updateLibrary) |
||||
|
|
||||
|
def updateLibraryView(self): |
||||
|
|
||||
|
params = getParams() |
||||
|
|
||||
|
fireEventAsync('manage.update', full = params.get('full', True)) |
||||
|
|
||||
|
return jsonified({ |
||||
|
'success': True |
||||
|
}) |
||||
|
|
||||
|
|
||||
|
def updateLibrary(self, full = False): |
||||
|
|
||||
|
if self.isDisabled() or (self.last_update > time.time() - 20): |
||||
|
return |
||||
|
|
||||
|
directories = self.directories() |
||||
|
|
||||
|
log.info('Updating manage library: %s' % directories) |
||||
|
|
||||
|
for directory in directories: |
||||
|
fireEvent('scanner.folder', folder = directory) |
||||
|
|
||||
|
# If cleanup option is enabled, remove offline files from database |
||||
|
if self.conf('cleanup'): |
||||
|
db = get_session() |
||||
|
files_in_path = db.query(File).filter(File.path.like(directory + '%%')).filter_by(available = 0).all() |
||||
|
[db.delete(x) for x in files_in_path] |
||||
|
db.commit() |
||||
|
db.remove() |
||||
|
|
||||
|
self.last_update = time.time() |
||||
|
|
||||
|
def directories(self): |
||||
|
try: |
||||
|
return self.conf('library', default = '').split('::') |
||||
|
except: |
||||
|
return [] |
After Width: | Height: | Size: 840 B |
Loading…
Reference in new issue