Notifications
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
from .main import FileManager
|
||||
|
||||
def start():
|
||||
return FileManager()
|
||||
|
||||
config = []
|
||||
@@ -0,0 +1,103 @@
|
||||
from couchpotato import get_session
|
||||
from couchpotato.api import addApiView
|
||||
from couchpotato.core.event import addEvent
|
||||
from couchpotato.core.helpers.variable import md5, getExt
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
from couchpotato.core.settings.model import FileType, File
|
||||
from couchpotato.environment import Env
|
||||
from flask.helpers import send_from_directory
|
||||
import os.path
|
||||
import urllib2
|
||||
|
||||
log = CPLog(__name__)
|
||||
|
||||
|
||||
class FileManager(Plugin):
|
||||
|
||||
def __init__(self):
|
||||
addEvent('file.add', self.add)
|
||||
addEvent('file.download', self.download)
|
||||
addEvent('file.types', self.getTypes)
|
||||
|
||||
addApiView('file.cache/<path:file>', self.showImage)
|
||||
|
||||
def showImage(self, file = ''):
|
||||
|
||||
cache_dir = Env.get('cache_dir')
|
||||
filename = file.replace(cache_dir[1:] + '/', '')
|
||||
|
||||
return send_from_directory(cache_dir, filename)
|
||||
|
||||
def download(self, url = '', dest = None, overwrite = False):
|
||||
|
||||
try:
|
||||
file = urllib2.urlopen(url)
|
||||
|
||||
if not dest: # to Cache
|
||||
dest = os.path.join(Env.get('cache_dir'), '%s.%s' % (md5(url), getExt(url)))
|
||||
|
||||
if overwrite or not os.path.exists(dest):
|
||||
log.debug('Writing file to: %s' % dest)
|
||||
output = open(dest, 'wb')
|
||||
output.write(file.read())
|
||||
output.close()
|
||||
else:
|
||||
log.debug('File already exists: %s' % dest)
|
||||
|
||||
return dest
|
||||
|
||||
except Exception, e:
|
||||
log.error('Unable to download file "%s": %s' % (url, e))
|
||||
|
||||
return False
|
||||
|
||||
def add(self, path = '', part = 1, type = (), properties = {}):
|
||||
|
||||
db = get_session()
|
||||
|
||||
f = db.query(File).filter_by(path = path).first()
|
||||
if not f:
|
||||
f = File()
|
||||
db.add(f)
|
||||
|
||||
f.path = path
|
||||
f.part = part
|
||||
f.type_id = self.getType(type).id
|
||||
|
||||
db.commit()
|
||||
|
||||
db.expunge(f)
|
||||
return f
|
||||
|
||||
def getType(self, type):
|
||||
|
||||
db = get_session()
|
||||
|
||||
type, identifier = type
|
||||
|
||||
ft = db.query(FileType).filter_by(identifier = identifier).first()
|
||||
if not ft:
|
||||
ft = FileType(
|
||||
type = type,
|
||||
identifier = identifier,
|
||||
name = identifier[0].capitalize() + identifier[1:]
|
||||
)
|
||||
|
||||
db.add(ft)
|
||||
db.commit()
|
||||
|
||||
return ft
|
||||
|
||||
def getTypes(self):
|
||||
|
||||
db = get_session()
|
||||
|
||||
results = db.query(FileType).all()
|
||||
|
||||
types = []
|
||||
for type in results:
|
||||
temp = type.to_dict()
|
||||
types.append(temp)
|
||||
|
||||
return types
|
||||
@@ -1,4 +1,4 @@
|
||||
from couchpotato.core.plugins.file_browser.main import FileBrowser
|
||||
from .main import FileBrowser
|
||||
|
||||
def start():
|
||||
return FileBrowser()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from couchpotato.core.plugins.library.main import LibraryPlugin
|
||||
from .main import LibraryPlugin
|
||||
|
||||
def start():
|
||||
return LibraryPlugin()
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from couchpotato.core.plugins.movie.main import MoviePlugin
|
||||
from .main import MoviePlugin
|
||||
|
||||
def start():
|
||||
return MoviePlugin()
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
from couchpotato import get_session
|
||||
from couchpotato.api import addApiView
|
||||
from couchpotato.core.event import fireEvent
|
||||
from couchpotato.core.event import fireEvent, fireEventAsync
|
||||
from couchpotato.core.helpers.request import getParams, jsonified
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
from couchpotato.core.settings.model import Movie, Release, Profile
|
||||
from couchpotato.core.settings.model import Movie
|
||||
from couchpotato.environment import Env
|
||||
from urllib import urlencode
|
||||
|
||||
@@ -13,30 +13,28 @@ class MoviePlugin(Plugin):
|
||||
def __init__(self):
|
||||
addApiView('movie.search', self.search)
|
||||
addApiView('movie.list', self.list)
|
||||
addApiView('movie.refresh', self.refresh)
|
||||
|
||||
addApiView('movie.add', self.add)
|
||||
addApiView('movie.edit', self.edit)
|
||||
addApiView('movie.delete', self.delete)
|
||||
|
||||
def list(self):
|
||||
|
||||
a = getParams()
|
||||
params = getParams()
|
||||
db = get_session()
|
||||
|
||||
results = get_session().query(Movie).filter(
|
||||
Movie.releases.any(
|
||||
Release.status.has(identifier = 'wanted')
|
||||
)
|
||||
).all()
|
||||
results = db.query(Movie).filter(
|
||||
Movie.status.has(identifier = params.get('status', 'active'))
|
||||
).all()
|
||||
|
||||
movies = []
|
||||
for movie in results:
|
||||
temp = {
|
||||
'id': movie.id,
|
||||
'name': movie.id,
|
||||
'releases': [],
|
||||
}
|
||||
for release in movie.releases:
|
||||
temp['releases'].append({
|
||||
'status': release.status.label,
|
||||
'quality': release.quality.label
|
||||
})
|
||||
temp = movie.to_dict(deep = {
|
||||
'releases': {'status': {}, 'quality': {}},
|
||||
'library': {'titles': {}, 'files':{}},
|
||||
'files': {}
|
||||
})
|
||||
|
||||
movies.append(temp)
|
||||
|
||||
@@ -46,22 +44,41 @@ class MoviePlugin(Plugin):
|
||||
'movies': movies,
|
||||
})
|
||||
|
||||
def refresh(self):
|
||||
|
||||
params = getParams()
|
||||
db = get_session()
|
||||
|
||||
movie = db.query(Movie).filter_by(id = params.get('id')).first()
|
||||
|
||||
# Get current selected title
|
||||
default_title = ''
|
||||
for title in movie.library.titles:
|
||||
if title.default: default_title = title.title
|
||||
|
||||
if movie:
|
||||
#addEvent('library.update.after', )
|
||||
fireEventAsync('library.update', library = movie.library, default_title = default_title)
|
||||
|
||||
return jsonified({
|
||||
'success': True,
|
||||
})
|
||||
|
||||
def search(self):
|
||||
|
||||
a = getParams()
|
||||
cache_key = '%s/%s' % (__name__, urlencode(a))
|
||||
params = getParams()
|
||||
cache_key = '%s/%s' % (__name__, urlencode(params))
|
||||
movies = Env.get('cache').get(cache_key)
|
||||
|
||||
if not movies:
|
||||
results = fireEvent('provider.movie.search', q = a.get('q'))
|
||||
results = fireEvent('provider.movie.search', q = params.get('q'))
|
||||
|
||||
# Combine movie results
|
||||
movies = []
|
||||
for r in results:
|
||||
movies += r
|
||||
|
||||
Env.get('cache').set(cache_key, movies, timeout = 10)
|
||||
|
||||
Env.get('cache').set(cache_key, movies)
|
||||
|
||||
return jsonified({
|
||||
'success': True,
|
||||
@@ -71,24 +88,46 @@ class MoviePlugin(Plugin):
|
||||
|
||||
def add(self):
|
||||
|
||||
a = getParams()
|
||||
params = getParams()
|
||||
db = get_session();
|
||||
|
||||
library = fireEvent('library.add', attrs = a)
|
||||
profile = db.query(Profile).filter_by(identifier = a.get('profile_identifier'))
|
||||
|
||||
m = db.query(Movie).filter_by(library = library).first()
|
||||
library = fireEvent('library.add', single = True, attrs = params)
|
||||
status = fireEvent('status.add', 'active', single = True)
|
||||
|
||||
m = db.query(Movie).filter_by(library_id = library.id).first()
|
||||
if not m:
|
||||
m = Movie(
|
||||
library = library,
|
||||
profile = profile,
|
||||
library_id = library.id,
|
||||
profile_id = params.get('profile_id')
|
||||
)
|
||||
db.add(m)
|
||||
db.commit()
|
||||
|
||||
m.status_id = status.id
|
||||
db.commit()
|
||||
|
||||
return jsonified({
|
||||
'success': True,
|
||||
'added': True,
|
||||
'params': a,
|
||||
'movie': m.to_dict(deep = {
|
||||
'releases': {'status': {}, 'quality': {}},
|
||||
'library': {'titles': {}}
|
||||
})
|
||||
})
|
||||
|
||||
def edit(self):
|
||||
pass
|
||||
|
||||
def delete(self):
|
||||
|
||||
params = getParams()
|
||||
db = get_session()
|
||||
|
||||
status = fireEvent('status.add', 'deleted', single = True)
|
||||
|
||||
movie = db.query(Movie).filter_by(id = params.get('id')).first()
|
||||
movie.status_id = status.id
|
||||
db.commit()
|
||||
|
||||
return jsonified({
|
||||
'success': True,
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from couchpotato.core.plugins.profile.main import ProfilePlugin
|
||||
from .main import ProfilePlugin
|
||||
|
||||
def start():
|
||||
return ProfilePlugin()
|
||||
|
||||
@@ -1,28 +1,90 @@
|
||||
from couchpotato import get_session
|
||||
from couchpotato.api import addApiView
|
||||
from couchpotato.core.event import addEvent
|
||||
from couchpotato.core.helpers.request import jsonified, getParams
|
||||
from couchpotato.core.helpers.request import jsonified, getParams, getParam
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
from couchpotato.core.settings.model import Profile, ProfileType
|
||||
|
||||
log = CPLog(__name__)
|
||||
|
||||
|
||||
class ProfilePlugin(Plugin):
|
||||
|
||||
def __init__(self):
|
||||
addEvent('profile.get', self.get)
|
||||
addEvent('profile.all', self.all)
|
||||
|
||||
addApiView('profile.save', self.save)
|
||||
addApiView('profile.delete', self.delete)
|
||||
|
||||
def get(self, key = ''):
|
||||
def all(self):
|
||||
|
||||
pass
|
||||
db = get_session()
|
||||
profiles = db.query(Profile).all()
|
||||
|
||||
temp = []
|
||||
for profile in profiles:
|
||||
temp.append(profile.to_dict(deep = {'types': {}}))
|
||||
|
||||
return temp
|
||||
|
||||
def save(self):
|
||||
|
||||
a = getParams()
|
||||
params = getParams()
|
||||
|
||||
db = get_session()
|
||||
|
||||
p = db.query(Profile).filter_by(id = params.get('id')).first()
|
||||
if not p:
|
||||
p = Profile()
|
||||
db.add(p)
|
||||
|
||||
p.label = params.get('label')
|
||||
p.order = params.get('order', p.order if p.order else 0)
|
||||
p.core = params.get('core', False)
|
||||
|
||||
#delete old types
|
||||
[db.delete(t) for t in p.types]
|
||||
|
||||
order = 0
|
||||
for type in params.get('types', []):
|
||||
t = ProfileType(
|
||||
order = order,
|
||||
finish = type.get('finish'),
|
||||
wait_for = params.get('wait_for'),
|
||||
quality_id = type.get('quality_id')
|
||||
)
|
||||
p.types.append(t)
|
||||
|
||||
order += 1
|
||||
|
||||
db.commit()
|
||||
|
||||
return jsonified({
|
||||
'success': True,
|
||||
'a': a
|
||||
'profile': p.to_dict(deep = {'types': {}})
|
||||
})
|
||||
|
||||
def delete(self):
|
||||
pass
|
||||
|
||||
id = getParam('id')
|
||||
|
||||
db = get_session()
|
||||
|
||||
success = False
|
||||
message = ''
|
||||
try:
|
||||
p = db.query(Profile).filter_by(id = id).first()
|
||||
|
||||
db.delete(p)
|
||||
db.commit()
|
||||
|
||||
success = True
|
||||
except Exception, e:
|
||||
message = 'Failed deleting Profile: %s' % e
|
||||
log.error(message)
|
||||
|
||||
return jsonified({
|
||||
'success': success,
|
||||
'message': message
|
||||
})
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
from .main import QualityPlugin
|
||||
|
||||
def start():
|
||||
return QualityPlugin()
|
||||
|
||||
config = []
|
||||
@@ -0,0 +1,97 @@
|
||||
from couchpotato import get_session
|
||||
from couchpotato.core.event import addEvent
|
||||
from couchpotato.core.helpers.encoding import toUnicode
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.settings.model import Quality, Profile, ProfileType
|
||||
|
||||
|
||||
log = CPLog(__name__)
|
||||
|
||||
class QualityPlugin:
|
||||
|
||||
qualities = [
|
||||
{'identifier': 'bd50', 'size': (15000, 60000), 'label': 'BR-Disk', 'alternative': ['1080p', 'bd25'], 'allow': [], 'ext':[], 'tags': ['x264', 'h264', 'blu ray']},
|
||||
{'identifier': '1080p', 'size': (5000, 20000), 'label': '1080P', 'alternative': [], 'allow': [], 'ext':['mkv', 'm2ts'], 'tags': ['x264', 'h264', 'bluray']},
|
||||
{'identifier': '720p', 'size': (3500, 10000), 'label': '720P', 'alternative': [], 'allow': [], 'ext':['mkv', 'm2ts'], 'tags': ['x264', 'h264', 'bluray']},
|
||||
{'identifier': 'brrip', 'size': (700, 7000), 'label': 'BR-Rip', 'alternative': ['bdrip'], 'allow': ['720p'], 'ext':['mkv', 'avi']},
|
||||
{'identifier': 'dvdr', 'size': (3000, 10000), 'label': 'DVD-R', 'alternative': [], 'allow': [], 'ext':['iso', 'img'], 'tags': ['pal', 'ntsc']},
|
||||
{'identifier': 'dvdrip', 'size': (600, 2400), 'label': 'DVD-Rip', 'alternative': [], 'allow': [], 'ext':['avi', 'mpg', 'mpeg']},
|
||||
{'identifier': 'scr', 'size': (600, 1600), 'label': 'Screener', 'alternative': ['dvdscr'], 'allow': ['dvdr'], 'ext':['avi', 'mpg', 'mpeg']},
|
||||
{'identifier': 'r5', 'size': (600, 1000), 'label': 'R5', 'alternative': [], 'allow': ['dvdr'], 'ext':['avi', 'mpg', 'mpeg']},
|
||||
{'identifier': 'tc', 'size': (600, 1000), 'label': 'TeleCine', 'alternative': ['telecine'], 'allow': [], 'ext':['avi', 'mpg', 'mpeg']},
|
||||
{'identifier': 'ts', 'size': (600, 1000), 'label': 'TeleSync', 'alternative': ['telesync'], 'allow': [], 'ext':['avi', 'mpg', 'mpeg']},
|
||||
{'identifier': 'cam', 'size': (600, 1000), 'label': 'Cam', 'alternative': [], 'allow': [], 'ext':['avi', 'mpg', 'mpeg']}
|
||||
]
|
||||
pre_releases = ['cam', 'ts', 'tc', 'r5', 'scr']
|
||||
|
||||
def __init__(self):
|
||||
addEvent('quality.all', self.all)
|
||||
addEvent('app.load', self.fill)
|
||||
|
||||
def all(self):
|
||||
|
||||
db = get_session()
|
||||
|
||||
qualities = db.query(Quality).all()
|
||||
|
||||
temp = []
|
||||
for quality in qualities:
|
||||
q = dict(self.getQuality(quality.identifier), **quality.to_dict())
|
||||
temp.append(q)
|
||||
|
||||
return temp
|
||||
|
||||
def getQuality(self, identifier):
|
||||
|
||||
for q in self.qualities:
|
||||
if identifier == q.get('identifier'):
|
||||
return q
|
||||
|
||||
def fill(self):
|
||||
|
||||
db = get_session();
|
||||
|
||||
order = 0
|
||||
for q in self.qualities:
|
||||
|
||||
# Create quality
|
||||
quality = db.query(Quality).filter_by(identifier = q.get('identifier')).first()
|
||||
|
||||
if not quality:
|
||||
log.info('Creating quality: %s' % q.get('label'))
|
||||
quality = Quality()
|
||||
db.add(quality)
|
||||
|
||||
quality.order = order
|
||||
quality.identifier = q.get('identifier')
|
||||
quality.label = q.get('label')
|
||||
quality.size_min, quality.size_max = q.get('size')
|
||||
|
||||
# Create single quality profile
|
||||
profile = db.query(Profile).filter(
|
||||
Profile.core == True
|
||||
).filter(
|
||||
Profile.types.any(quality = quality)
|
||||
).all()
|
||||
|
||||
if not profile:
|
||||
log.info('Creating profile: %s' % q.get('label'))
|
||||
profile = Profile(
|
||||
core = True,
|
||||
label = toUnicode(quality.label),
|
||||
order = order
|
||||
)
|
||||
db.add(profile)
|
||||
|
||||
profile_type = ProfileType(
|
||||
quality = quality,
|
||||
profile = profile,
|
||||
finish = True,
|
||||
order = 0
|
||||
)
|
||||
profile.types.append(profile_type)
|
||||
|
||||
order += 1
|
||||
db.commit()
|
||||
|
||||
return True
|
||||
@@ -0,0 +1,6 @@
|
||||
from .main import StatusPlugin
|
||||
|
||||
def start():
|
||||
return StatusPlugin()
|
||||
|
||||
config = []
|
||||
@@ -0,0 +1,68 @@
|
||||
from couchpotato import get_session
|
||||
from couchpotato.core.event import addEvent
|
||||
from couchpotato.core.helpers.encoding import toUnicode
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.settings.model import Status
|
||||
|
||||
log = CPLog(__name__)
|
||||
|
||||
class StatusPlugin:
|
||||
|
||||
statuses = {
|
||||
'active': 'Active',
|
||||
'done': 'Done',
|
||||
'downloaded': 'Downloaded',
|
||||
'wanted': 'Wanted',
|
||||
'deleted': 'Deleted',
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
addEvent('status.add', self.add)
|
||||
addEvent('status.all', self.all)
|
||||
addEvent('app.load', self.fill)
|
||||
|
||||
def all(self):
|
||||
|
||||
db = get_session()
|
||||
|
||||
statuses = db.query(Status).all()
|
||||
|
||||
temp = []
|
||||
for status in statuses:
|
||||
s = status.to_dict()
|
||||
temp.append(s)
|
||||
|
||||
return temp
|
||||
|
||||
def add(self, identifier):
|
||||
|
||||
db = get_session()
|
||||
|
||||
s = db.query(Status).filter_by(identifier = identifier).first()
|
||||
if not s:
|
||||
s = Status(
|
||||
identifier = identifier,
|
||||
label = identifier.capitalize()
|
||||
)
|
||||
db.add(s)
|
||||
db.commit()
|
||||
|
||||
#db.remove()
|
||||
return s
|
||||
|
||||
def fill(self):
|
||||
|
||||
db = get_session()
|
||||
|
||||
for identifier, label in self.statuses.iteritems():
|
||||
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 = label
|
||||
db.commit()
|
||||
Reference in New Issue
Block a user