Notifications

This commit is contained in:
Ruud
2011-04-09 20:18:51 +02:00
parent 288aa8c0a1
commit 85fc1c01ee
67 changed files with 3270 additions and 400 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
from couchpotato.core.plugins.library.main import LibraryPlugin
from .main import LibraryPlugin
def start():
return LibraryPlugin()
+57 -8
View File
@@ -1,32 +1,81 @@
from couchpotato import get_session
from couchpotato.core.event import addEvent
from couchpotato.core.event import addEvent, fireEventAsync, fireEvent
from couchpotato.core.logger import CPLog
from couchpotato.core.plugins.base import Plugin
from couchpotato.core.settings.model import Library
from couchpotato.core.settings.model import Library, LibraryTitle
log = CPLog(__name__)
class LibraryPlugin(Plugin):
def __init__(self):
addEvent('library.add', self.add)
addEvent('library.update', self.update)
def add(self, attrs = {}):
db = get_session();
db = get_session()
l = db.query(Library).filter_by(identifier = attrs.get('identifier')).first()
if not l:
l = Library(
name = attrs.get('name'),
year = attrs.get('year'),
identifier = attrs.get('identifier'),
description = attrs.get('description')
plot = attrs.get('plot'),
tagline = attrs.get('tagline')
)
title = LibraryTitle(
title = attrs.get('title')
)
l.titles.append(title)
db.add(l)
db.commit()
# Update library info
fireEventAsync('library.update', library = l, default_title = attrs.get('title', ''))
#db.remove()
return l
def update(self, item):
def update(self, library, default_title = ''):
pass
db = get_session()
library = db.query(Library).filter_by(identifier = library.identifier).first()
info = fireEvent('provider.movie.info', merge = True, identifier = library.identifier)
# Main info
library.plot = info.get('plot', '')
library.tagline = info.get('tagline', '')
library.year = info.get('year', 0)
# Titles
[db.delete(title) for title in library.titles]
titles = info.get('titles')
log.debug('Adding titles: %s' % titles)
for title in titles:
t = LibraryTitle(
title = title,
default = title.lower() == default_title.lower()
)
library.titles.append(t)
db.commit()
# Files
images = info.get('images')
for type in images:
for image in images[type]:
file_path = fireEvent('file.download', url = image, single = True)
file = fireEvent('file.add', path = file_path, type = ('image', type[:-1]), single = True)
try:
library.files.append(file)
db.commit()
except:
log.debug('File already attached to library')
fireEvent('library.update.after')