nosql
This commit is contained in:
@@ -1,13 +1,9 @@
|
||||
from couchpotato import get_session
|
||||
from couchpotato import get_db
|
||||
from couchpotato.api import addApiView
|
||||
from couchpotato.core.event import fireEvent
|
||||
from couchpotato.core.helpers.variable import splitString, tryInt
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
from couchpotato.core.settings.model import Media, Library, LibraryTitle, \
|
||||
Release
|
||||
from sqlalchemy.orm import joinedload_all
|
||||
from sqlalchemy.sql.expression import asc, or_
|
||||
import random as rndm
|
||||
import time
|
||||
|
||||
@@ -21,26 +17,21 @@ class Dashboard(Plugin):
|
||||
|
||||
def getSoonView(self, limit_offset = None, random = False, late = False, **kwargs):
|
||||
|
||||
db = get_session()
|
||||
db = get_db()
|
||||
now = time.time()
|
||||
|
||||
# Get profiles first, determine pre or post theater
|
||||
profiles = fireEvent('profile.all', single = True)
|
||||
qualities = fireEvent('quality.all', single = True)
|
||||
pre_releases = fireEvent('quality.pre_releases', single = True)
|
||||
|
||||
id_pre = {}
|
||||
for quality in qualities:
|
||||
id_pre[quality.get('id')] = quality.get('identifier') in pre_releases
|
||||
|
||||
# See what the profile contain and cache it
|
||||
profile_pre = {}
|
||||
for profile in profiles:
|
||||
contains = {}
|
||||
for profile_type in profile.get('types', []):
|
||||
contains['theater' if id_pre.get(profile_type.get('quality_id')) else 'dvd'] = True
|
||||
for q_identifier in profile.get('qualities', []):
|
||||
contains['theater' if q_identifier in pre_releases else 'dvd'] = True
|
||||
|
||||
profile_pre[profile.get('id')] = contains
|
||||
profile_pre[profile.get('_id')] = contains
|
||||
|
||||
# Add limit
|
||||
limit = 12
|
||||
@@ -48,43 +39,32 @@ class Dashboard(Plugin):
|
||||
splt = splitString(limit_offset) if isinstance(limit_offset, (str, unicode)) else limit_offset
|
||||
limit = tryInt(splt[0])
|
||||
|
||||
# Get all active movies
|
||||
q = db.query(Media) \
|
||||
.join(Library) \
|
||||
.outerjoin(Media.releases) \
|
||||
.filter(Media.status_id == active_status.get('id')) \
|
||||
.with_entities(Media.id, Media.profile_id, Library.info, Library.year) \
|
||||
.group_by(Media.id) \
|
||||
.filter(or_(Release.id == None, Release.status_id == ignored_status.get('id')))
|
||||
# Get all active medias
|
||||
active_ids = [x['_id'] for x in db.get_many('media_status', 'active')]
|
||||
|
||||
if not random:
|
||||
q = q.join(LibraryTitle) \
|
||||
.filter(LibraryTitle.default == True) \
|
||||
.order_by(asc(LibraryTitle.simple_title))
|
||||
medias = []
|
||||
if len(active_ids) > 0:
|
||||
|
||||
active = q.all()
|
||||
movies = []
|
||||
# Order by title or randomize
|
||||
if not random:
|
||||
orders_ids = db.all('media_title')
|
||||
active_ids = [x['_id'] for x in orders_ids if x['_id'] in active_ids]
|
||||
else:
|
||||
rndm.shuffle(active_ids)
|
||||
|
||||
if len(active) > 0:
|
||||
for media_id in active_ids:
|
||||
media = db.get('id', media_id)
|
||||
|
||||
# Do the shuffle
|
||||
if random:
|
||||
rndm.shuffle(active)
|
||||
|
||||
movie_ids = []
|
||||
for movie in active:
|
||||
movie_id, profile_id, info, year = movie
|
||||
|
||||
pp = profile_pre.get(profile_id)
|
||||
pp = profile_pre.get(media['profile_id'])
|
||||
if not pp: continue
|
||||
|
||||
eta = info.get('release_date', {}) or {}
|
||||
eta = media['info'].get('release_date', {}) or {}
|
||||
coming_soon = False
|
||||
|
||||
# Theater quality
|
||||
if pp.get('theater') and fireEvent('movie.searcher.could_be_released', True, eta, year, single = True):
|
||||
if pp.get('theater') and fireEvent('movie.searcher.could_be_released', True, eta, media['info']['year'], single = True):
|
||||
coming_soon = True
|
||||
elif pp.get('dvd') and fireEvent('movie.searcher.could_be_released', False, eta, year, single = True):
|
||||
elif pp.get('dvd') and fireEvent('movie.searcher.could_be_released', False, eta, media['info']['year'], single = True):
|
||||
coming_soon = True
|
||||
|
||||
if coming_soon:
|
||||
@@ -92,37 +72,15 @@ class Dashboard(Plugin):
|
||||
# Don't list older movies
|
||||
if ((not late and (not eta.get('dvd') and not eta.get('theater') or eta.get('dvd') and eta.get('dvd') > (now - 2419200))) or
|
||||
(late and (eta.get('dvd', 0) > 0 or eta.get('theater')) and eta.get('dvd') < (now - 2419200))):
|
||||
movie_ids.append(movie_id)
|
||||
medias.append(media)
|
||||
|
||||
if len(movie_ids) >= limit:
|
||||
if len(medias) >= limit:
|
||||
break
|
||||
|
||||
if len(movie_ids) > 0:
|
||||
|
||||
# Get all movie information
|
||||
movies_raw = db.query(Media) \
|
||||
.options(joinedload_all('library.titles')) \
|
||||
.options(joinedload_all('library.files')) \
|
||||
.options(joinedload_all('files')) \
|
||||
.filter(Media.id.in_(movie_ids)) \
|
||||
.all()
|
||||
|
||||
# Create dict by movie id
|
||||
movie_dict = {}
|
||||
for movie in movies_raw:
|
||||
movie_dict[movie.id] = movie
|
||||
|
||||
for movie_id in movie_ids:
|
||||
movies.append(movie_dict[movie_id].to_dict({
|
||||
'library': {'titles': {}, 'files': {}},
|
||||
'files': {},
|
||||
}))
|
||||
|
||||
pass #db.close()
|
||||
return {
|
||||
'success': True,
|
||||
'empty': len(movies) == 0,
|
||||
'movies': movies,
|
||||
'empty': len(medias) == 0,
|
||||
'movies': medias,
|
||||
}
|
||||
|
||||
getLateView = getSoonView
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
var File = new Class({
|
||||
|
||||
initialize: function(type, file){
|
||||
var self = this;
|
||||
|
||||
if(!file){
|
||||
self.empty = true;
|
||||
self.el = new Element('div.empty_file.'+type);
|
||||
return
|
||||
}
|
||||
|
||||
self.data = file;
|
||||
self.type = File.Type.get(file.type_id);
|
||||
|
||||
self['create'+(self.type.type).capitalize()]()
|
||||
|
||||
},
|
||||
|
||||
createImage: function(){
|
||||
var self = this;
|
||||
|
||||
var file_name = self.data.path.replace(/^.*[\\\/]/, '');
|
||||
|
||||
self.el = new Element('div', {
|
||||
'class': 'type_image ' + self.type.identifier,
|
||||
'styles': {
|
||||
'background-image': 'url('+Api.createUrl('file.cache') + file_name+')'
|
||||
}
|
||||
}).adopt(
|
||||
new Element('img', {
|
||||
'src': Api.createUrl('file.cache') + file_name
|
||||
})
|
||||
)
|
||||
},
|
||||
|
||||
toElement: function(){
|
||||
return this.el;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
var FileSelect = new Class({
|
||||
|
||||
multiple: function(type, files, single){
|
||||
|
||||
var results = files.filter(function(file){
|
||||
return file.type_id == File.Type.get(type).id;
|
||||
});
|
||||
|
||||
if(single)
|
||||
return new File(type, results.pop());
|
||||
|
||||
return results;
|
||||
|
||||
},
|
||||
|
||||
single: function(type, files){
|
||||
return this.multiple(type, files, true);
|
||||
}
|
||||
|
||||
});
|
||||
window.File.Select = new FileSelect();
|
||||
|
||||
var FileTypeBase = new Class({
|
||||
|
||||
setup: function(types){
|
||||
var self = this;
|
||||
|
||||
self.typesById = {};
|
||||
self.typesByKey = {};
|
||||
Object.each(types, function(type){
|
||||
self.typesByKey[type.identifier] = type;
|
||||
self.typesById[type.id] = type;
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
get: function(identifier){
|
||||
if(typeOf(identifier) == 'number')
|
||||
return this.typesById[identifier]
|
||||
else
|
||||
return this.typesByKey[identifier]
|
||||
}
|
||||
|
||||
});
|
||||
window.File.Type = new FileTypeBase();
|
||||
@@ -124,7 +124,7 @@ class Manage(Plugin):
|
||||
fireEvent('media.delete', media_id = done_movie['id'], delete_from = 'all')
|
||||
else:
|
||||
|
||||
releases = fireEvent('release.for_movie', id = done_movie.get('id'), single = True)
|
||||
releases = fireEvent('release.for_movie', id = done_movie.get('_id'), single = True)
|
||||
|
||||
for release in releases:
|
||||
if len(release.get('files', [])) > 0:
|
||||
|
||||
@@ -56,8 +56,7 @@ class ProfilePlugin(Plugin):
|
||||
|
||||
for media in medias:
|
||||
if media.get('profile_id') not in profile_ids:
|
||||
default_profile = self.default()
|
||||
media['profile_id'] = default_profile.get('id')
|
||||
media['profile_id'] = profile_ids[0].get('_id')
|
||||
db.update(media)
|
||||
except:
|
||||
log.error('Failed: %s', traceback.format_exc())
|
||||
|
||||
@@ -54,10 +54,20 @@ var Profile = new Class({
|
||||
)
|
||||
);
|
||||
|
||||
self.makeSortable()
|
||||
self.makeSortable();
|
||||
|
||||
// Combine qualities and properties into types
|
||||
data.types = [];
|
||||
data.qualities.each(function(quality, nr){
|
||||
data.types.include({
|
||||
'quality_identifier': quality,
|
||||
'finish': data.finish[nr] || false,
|
||||
'wait_for': data.wait_for[nr] || 0
|
||||
})
|
||||
});
|
||||
|
||||
if(data.types)
|
||||
Object.each(data.types, self.addType.bind(self))
|
||||
data.types.each(self.addType.bind(self));
|
||||
else
|
||||
self.delete_button.hide();
|
||||
|
||||
@@ -111,8 +121,9 @@ var Profile = new Class({
|
||||
Array.each(self.type_container.getElements('.type'), function(type){
|
||||
if(!type.hasClass('deleted') && type.getElement('select').get('value') > 0)
|
||||
data.types.include({
|
||||
'quality_id': type.getElement('select').get('value'),
|
||||
'finish': +type.getElement('input[type=checkbox]').checked
|
||||
'quality_identifier': type.getElement('select').get('value'),
|
||||
'finish': +type.getElement('input[type=checkbox]').checked,
|
||||
'wait_for': 0
|
||||
});
|
||||
})
|
||||
|
||||
@@ -145,7 +156,7 @@ var Profile = new Class({
|
||||
var self = this;
|
||||
|
||||
return self.types.filter(function(type){
|
||||
return type.get('quality_id')
|
||||
return type.get('quality_identifier')
|
||||
});
|
||||
|
||||
},
|
||||
@@ -264,7 +275,7 @@ Profile.Type = new Class({
|
||||
new Element('span.handle')
|
||||
);
|
||||
|
||||
self.el[self.data.quality_id > 0 ? 'removeClass' : 'addClass']('is_empty');
|
||||
self.el[self.data.quality_identifier ? 'removeClass' : 'addClass']('is_empty');
|
||||
|
||||
self.finish_class = new Form.Check(self.finish);
|
||||
|
||||
@@ -287,11 +298,11 @@ Profile.Type = new Class({
|
||||
Object.each(Quality.qualities, function(q){
|
||||
new Element('option', {
|
||||
'text': q.label,
|
||||
'value': q.id
|
||||
'value': q.identifier
|
||||
}).inject(self.qualities)
|
||||
});
|
||||
|
||||
self.qualities.set('value', self.data.quality_id);
|
||||
self.qualities.set('value', self.data.quality_identifier);
|
||||
|
||||
return self.qualities;
|
||||
|
||||
@@ -301,8 +312,9 @@ Profile.Type = new Class({
|
||||
var self = this;
|
||||
|
||||
return {
|
||||
'quality_id': self.qualities.get('value'),
|
||||
'finish': +self.finish.checked
|
||||
'quality_identifier': self.qualities.get('value'),
|
||||
'finish': +self.finish.checked,
|
||||
'wait_for': 0
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ var QualityBase = new Class({
|
||||
|
||||
getProfile: function(id){
|
||||
return this.profiles.filter(function(profile){
|
||||
return profile.data.id == id
|
||||
return profile.data._id == id
|
||||
}).pick()
|
||||
},
|
||||
|
||||
@@ -28,9 +28,9 @@ var QualityBase = new Class({
|
||||
});
|
||||
},
|
||||
|
||||
getQuality: function(id){
|
||||
getQuality: function(identifier){
|
||||
return this.qualities.filter(function(q){
|
||||
return q.id == id;
|
||||
return q.identifier == identifier;
|
||||
}).pick();
|
||||
},
|
||||
|
||||
|
||||
@@ -19,13 +19,13 @@ class ReleaseIndex(TreeBasedIndex):
|
||||
for release in db.get_many('release', media_id, with_doc = True):
|
||||
yield release['doc']
|
||||
|
||||
def run_with_status(self, db, status = []):
|
||||
def run_with_status(self, db, status = [], with_doc = True):
|
||||
|
||||
status = list(status if isinstance(status, (list, tuple)) else [status])
|
||||
|
||||
for s in status:
|
||||
for ms in db.get_many('release_status', s, with_doc = True):
|
||||
yield ms['doc']
|
||||
for ms in db.get_many('release_status', s, with_doc = with_doc):
|
||||
yield ms['doc'] if with_doc else ms
|
||||
|
||||
|
||||
class ReleaseStatusIndex(TreeBasedIndex):
|
||||
@@ -39,7 +39,7 @@ class ReleaseStatusIndex(TreeBasedIndex):
|
||||
|
||||
def make_key_value(self, data):
|
||||
if data.get('_t') == 'release' and data.get('status'):
|
||||
return md5(data.get('status')).hexdigest(), None
|
||||
return md5(data.get('status')).hexdigest(), {'media_id': data.get('media_id')}
|
||||
|
||||
|
||||
class ReleaseIDIndex(TreeBasedIndex):
|
||||
@@ -53,4 +53,4 @@ class ReleaseIDIndex(TreeBasedIndex):
|
||||
|
||||
def make_key_value(self, data):
|
||||
if data.get('_t') == 'release' and data.get('identifier'):
|
||||
return md5(data.get('identifier')).hexdigest(), None
|
||||
return md5(data.get('identifier')).hexdigest(), {'media_id': data.get('media_id')}
|
||||
|
||||
@@ -461,7 +461,7 @@ class Renamer(Plugin):
|
||||
self.tagRelease(group = group, tag = 'exists')
|
||||
|
||||
# Notify on rename fail
|
||||
download_message = 'Renaming of %s (%s) cancelled, exists in %s already.' % (movie.library.titles[0].title, group['meta_data']['quality']['label'], release.quality.label)
|
||||
download_message = 'Renaming of %s (%s) cancelled, exists in %s already.' % (getTitle(movie), group['meta_data']['quality']['label'], release.quality.label)
|
||||
fireEvent('movie.renaming.canceled', message = download_message, data = group)
|
||||
remove_leftovers = False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user