More nosql
This commit is contained in:
@@ -10,10 +10,10 @@ class Automation(Plugin):
|
||||
|
||||
def __init__(self):
|
||||
|
||||
addEvent('app.load2', self.setCrons)
|
||||
addEvent('app.load', self.setCrons)
|
||||
|
||||
if not Env.get('dev'):
|
||||
addEvent('app.load2', self.addMovies)
|
||||
addEvent('app.load', self.addMovies)
|
||||
|
||||
addEvent('setting.save.automation.hour.after', self.setCrons)
|
||||
|
||||
|
||||
@@ -291,7 +291,7 @@ class Plugin(object):
|
||||
|
||||
def cpTag(self, media):
|
||||
if Env.setting('enabled', 'renamer'):
|
||||
return '.cp(' + media['library'].get('identifier') + ')' if media['library'].get('identifier') else ''
|
||||
return '.cp(' + media.get('identifier') + ')' if media.get('identifier') else ''
|
||||
|
||||
return ''
|
||||
|
||||
|
||||
@@ -5,12 +5,12 @@ from CodernityDB.tree_index import TreeBasedIndex
|
||||
class CategoryIndex(TreeBasedIndex):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs['key_format'] = '16s'
|
||||
kwargs['key_format'] = '32s'
|
||||
super(CategoryIndex, self).__init__(*args, **kwargs)
|
||||
|
||||
def make_key(self, key):
|
||||
return md5(key).digest()
|
||||
return md5(key).hexdigest()
|
||||
|
||||
def make_key_value(self, data):
|
||||
if data.get('type') == 'category':
|
||||
return md5(data['media_id']).digest(), None
|
||||
if data.get('_t') == 'category':
|
||||
return md5(data['media_id']).hexdigest(), None
|
||||
|
||||
@@ -10,7 +10,7 @@ log = CPLog(__name__)
|
||||
class Custom(Plugin):
|
||||
|
||||
def __init__(self):
|
||||
addEvent('app.load2', self.createStructure)
|
||||
addEvent('app.load', self.createStructure)
|
||||
|
||||
def createStructure(self):
|
||||
|
||||
|
||||
@@ -49,7 +49,6 @@ class Dashboard(Plugin):
|
||||
limit = tryInt(splt[0])
|
||||
|
||||
# Get all active movies
|
||||
active_status, ignored_status = fireEvent('status.get', ['active', 'ignored'], single = True)
|
||||
q = db.query(Media) \
|
||||
.join(Library) \
|
||||
.outerjoin(Media.releases) \
|
||||
|
||||
@@ -5,8 +5,7 @@ from couchpotato.core.helpers.encoding import toUnicode
|
||||
from couchpotato.core.helpers.variable import md5, getExt
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
from couchpotato.core.plugins.scanner.main import Scanner
|
||||
from couchpotato.core.settings.model import FileType, File
|
||||
from couchpotato.core.settings.model import File
|
||||
from couchpotato.environment import Env
|
||||
from tornado.web import StaticFileHandler
|
||||
import os.path
|
||||
|
||||
@@ -47,7 +47,7 @@ class Manage(Plugin):
|
||||
})
|
||||
|
||||
if not Env.get('dev') and self.conf('startup_scan'):
|
||||
addEvent('app.load2', self.updateLibraryQuick)
|
||||
addEvent('app.load', self.updateLibraryQuick)
|
||||
|
||||
def getProgress(self, **kwargs):
|
||||
return {
|
||||
@@ -120,7 +120,7 @@ class Manage(Plugin):
|
||||
total_movies, done_movies = fireEvent('media.list', types = 'movie', status = 'done', single = True)
|
||||
|
||||
for done_movie in done_movies:
|
||||
if done_movie['library']['identifier'] not in added_identifiers:
|
||||
if done_movie['identifier'] not in added_identifiers:
|
||||
fireEvent('media.delete', media_id = done_movie['id'], delete_from = 'all')
|
||||
else:
|
||||
|
||||
@@ -184,13 +184,13 @@ class Manage(Plugin):
|
||||
'to_go': total_found,
|
||||
})
|
||||
|
||||
if group['library'] and group['library'].get('identifier'):
|
||||
identifier = group['library'].get('identifier')
|
||||
if group['media'] and group['media'].get('identifier'):
|
||||
identifier = group['media'].get('identifier')
|
||||
added_identifiers.append(identifier)
|
||||
|
||||
# Add it to release and update the info
|
||||
fireEvent('release.add', group = group)
|
||||
fireEvent('library.update.movie', identifier = identifier, on_complete = self.createAfterUpdate(folder, identifier))
|
||||
fireEvent('movie.update_info', identifier = identifier, on_complete = self.createAfterUpdate(folder, identifier))
|
||||
else:
|
||||
self.updateProgress(folder)
|
||||
|
||||
@@ -207,7 +207,7 @@ class Manage(Plugin):
|
||||
total = self.in_progress[folder]['total']
|
||||
movie_dict = fireEvent('media.get', identifier, single = True)
|
||||
|
||||
fireEvent('notify.frontend', type = 'movie.added', data = movie_dict, message = None if total > 5 else 'Added "%s" to manage.' % getTitle(movie_dict['library']))
|
||||
fireEvent('notify.frontend', type = 'movie.added', data = movie_dict, message = None if total > 5 else 'Added "%s" to manage.' % getTitle(movie_dict))
|
||||
|
||||
return afterUpdate
|
||||
|
||||
@@ -237,7 +237,7 @@ class Manage(Plugin):
|
||||
|
||||
if groups:
|
||||
for group in groups.values():
|
||||
if group['library'] and group['library'].get('identifier'):
|
||||
if group.get('info'):
|
||||
fireEvent('release.add', group = group)
|
||||
|
||||
def getDiskSpace(self):
|
||||
|
||||
@@ -12,6 +12,6 @@ class NameIndex(TreeBasedIndex):
|
||||
return key
|
||||
|
||||
def make_key_value(self, data):
|
||||
if data.get('type') == 'media' and data.get('title') is not None:
|
||||
if data.get('_t') == 'media' and data.get('title') is not None:
|
||||
return data.get('title'), None
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ import time
|
||||
from couchpotato import CPLog, get_db
|
||||
from couchpotato.core.event import addEvent
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
from .index import ReleaseIndex, NameIndex
|
||||
|
||||
log = CPLog(__name__)
|
||||
|
||||
@@ -13,7 +12,7 @@ class NoSQL(Plugin):
|
||||
|
||||
def __init__(self):
|
||||
|
||||
pass #addEvent('app.load2', self.test)
|
||||
pass #addEvent('app.load', self.test)
|
||||
|
||||
def test(self):
|
||||
|
||||
@@ -31,7 +30,8 @@ class NoSQL(Plugin):
|
||||
|
||||
for id in range(10):
|
||||
media = db.insert({
|
||||
'type': 'media',
|
||||
'_t': 'media',
|
||||
'type': 'movie',
|
||||
'tmdb': id,
|
||||
'imdb': 'tt%s' % id,
|
||||
'last_edit': 0,
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
from CodernityDB.hash_index import HashIndex
|
||||
from hashlib import md5
|
||||
from CodernityDB.tree_index import TreeBasedIndex
|
||||
|
||||
|
||||
class ProfileIndex(HashIndex):
|
||||
class ProfileIndex(TreeBasedIndex):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs['key_format'] = '16s'
|
||||
kwargs['key_format'] = 'i'
|
||||
super(ProfileIndex, self).__init__(*args, **kwargs)
|
||||
|
||||
def make_key(self, key):
|
||||
return md5(key).digest()
|
||||
return key
|
||||
|
||||
def make_key_value(self, data):
|
||||
if data.get('type') == 'profile' and data.get('identifier'):
|
||||
return md5(data.get('identifier')).digest(), None
|
||||
if data.get('_t') == 'profile':
|
||||
return data.get('order', 99), None
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import traceback
|
||||
from couchpotato import get_session, get_db
|
||||
from couchpotato.api import addApiView
|
||||
from couchpotato.core.event import addEvent, fireEvent
|
||||
from couchpotato.core.event import addEvent
|
||||
from couchpotato.core.helpers.encoding import toUnicode
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
from .index import ProfileIndex
|
||||
from couchpotato.core.settings.model import Profile, ProfileType, Media
|
||||
from sqlalchemy.orm import joinedload_all
|
||||
from couchpotato.core.settings.model import Profile, ProfileType
|
||||
|
||||
log = CPLog(__name__)
|
||||
|
||||
@@ -34,7 +33,7 @@ class ProfilePlugin(Plugin):
|
||||
addEvent('database.setup', self.databaseSetup)
|
||||
|
||||
addEvent('app.initialize', self.fill, priority = 90)
|
||||
addEvent('app.load2', self.forceDefaults)
|
||||
addEvent('app.load', self.forceDefaults)
|
||||
|
||||
def databaseSetup(self):
|
||||
|
||||
@@ -46,7 +45,6 @@ class ProfilePlugin(Plugin):
|
||||
log.debug('Index already exists')
|
||||
db.edit_index(ProfileIndex(db.path, 'profile'))
|
||||
|
||||
|
||||
def forceDefaults(self):
|
||||
|
||||
# Get all active movies without profile
|
||||
@@ -57,7 +55,7 @@ class ProfilePlugin(Plugin):
|
||||
profile_ids = [x.get('_id') for x in self.all()]
|
||||
|
||||
for media in medias:
|
||||
if media['profile_id'] not in profile_ids:
|
||||
if media.get('profile_id') not in profile_ids:
|
||||
default_profile = self.default()
|
||||
media['profile_id'] = default_profile.get('id')
|
||||
db.update(media)
|
||||
@@ -76,7 +74,7 @@ class ProfilePlugin(Plugin):
|
||||
db = get_db()
|
||||
profiles = db.all('profile', with_doc = True)
|
||||
|
||||
return list(profiles)
|
||||
return [x['doc'] for x in profiles]
|
||||
|
||||
def save(self, **kwargs):
|
||||
|
||||
@@ -127,7 +125,7 @@ class ProfilePlugin(Plugin):
|
||||
|
||||
def default(self):
|
||||
db = get_db()
|
||||
return db.get_many('profile', limit = 1, with_doc = True)[0]
|
||||
return list(db.all('profile', limit = 1, with_doc = True))[0]['doc']
|
||||
|
||||
def saveOrder(self, **kwargs):
|
||||
|
||||
@@ -213,8 +211,7 @@ class ProfilePlugin(Plugin):
|
||||
log.info('Creating default profile: %s', profile.get('label'))
|
||||
|
||||
pro = {
|
||||
'type': 'profile',
|
||||
'identifier': profile.get('label').lower(),
|
||||
'_t': 'profile',
|
||||
'label': toUnicode(profile.get('label')),
|
||||
'order': order,
|
||||
'qualities': profile.get('qualities'),
|
||||
@@ -229,9 +226,6 @@ class ProfilePlugin(Plugin):
|
||||
db.insert(pro)
|
||||
order += 1
|
||||
|
||||
for x in db.all('profile', with_doc = True):
|
||||
log.info(x)
|
||||
|
||||
return True
|
||||
except:
|
||||
log.error('Failed: %s', traceback.format_exc())
|
||||
|
||||
@@ -324,4 +324,4 @@ Profile.Type = new Class({
|
||||
return this.el;
|
||||
}
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
from CodernityDB.hash_index import HashIndex
|
||||
from hashlib import md5
|
||||
|
||||
|
||||
class QualityIndex(HashIndex):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs['key_format'] = '32s'
|
||||
super(QualityIndex, self).__init__(*args, **kwargs)
|
||||
|
||||
def make_key(self, key):
|
||||
return md5(key).hexdigest()
|
||||
|
||||
def make_key_value(self, data):
|
||||
if data.get('_t') == 'quality' and data.get('identifier'):
|
||||
return md5(data.get('identifier')).hexdigest(), None
|
||||
@@ -1,15 +1,14 @@
|
||||
import traceback
|
||||
from couchpotato import get_session
|
||||
from couchpotato import get_session, get_db
|
||||
from couchpotato.api import addApiView
|
||||
from couchpotato.core.event import addEvent
|
||||
from couchpotato.core.helpers.encoding import toUnicode, ss
|
||||
from couchpotato.core.helpers.variable import mergeDicts, getExt
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
from couchpotato.core.settings.model import Quality, Profile, ProfileType
|
||||
from sqlalchemy.sql.expression import or_
|
||||
from couchpotato.core.plugins.quality.index import QualityIndex
|
||||
from couchpotato.core.settings.model import Quality
|
||||
import re
|
||||
import time
|
||||
|
||||
log = CPLog(__name__)
|
||||
|
||||
@@ -39,6 +38,7 @@ class QualityPlugin(Plugin):
|
||||
addEvent('quality.single', self.single)
|
||||
addEvent('quality.guess', self.guess)
|
||||
addEvent('quality.pre_releases', self.preReleases)
|
||||
addEvent('quality.order', self.getOrder)
|
||||
|
||||
addApiView('quality.size.save', self.saveSize)
|
||||
addApiView('quality.list', self.allView, docs = {
|
||||
@@ -50,9 +50,31 @@ class QualityPlugin(Plugin):
|
||||
})
|
||||
|
||||
addEvent('app.initialize', self.fill, priority = 10)
|
||||
addEvent('database.setup', self.databaseSetup)
|
||||
|
||||
addEvent('app.test', self.doTest)
|
||||
|
||||
self.addOrder()
|
||||
|
||||
def addOrder(self):
|
||||
self.order = []
|
||||
for q in self.qualities:
|
||||
self.order.append(q.get('identifier'))
|
||||
|
||||
def getOrder(self):
|
||||
return self.order
|
||||
|
||||
def databaseSetup(self):
|
||||
|
||||
db = get_db()
|
||||
|
||||
# Quality index
|
||||
try:
|
||||
db.add_index(QualityIndex(db.path, 'quality'))
|
||||
except:
|
||||
log.debug('Index already exists')
|
||||
db.edit_index(QualityIndex(db.path, 'quality'))
|
||||
|
||||
def preReleases(self):
|
||||
return self.pre_releases
|
||||
|
||||
@@ -68,30 +90,29 @@ class QualityPlugin(Plugin):
|
||||
if self.cached_qualities:
|
||||
return self.cached_qualities
|
||||
|
||||
db = get_session()
|
||||
db = get_db()
|
||||
|
||||
qualities = db.query(Quality).all()
|
||||
qualities = db.all('quality', with_doc = True)
|
||||
|
||||
temp = []
|
||||
for quality in qualities:
|
||||
q = mergeDicts(self.getQuality(quality.identifier), quality.to_dict())
|
||||
quality = quality['doc']
|
||||
q = mergeDicts(self.getQuality(quality.get('identifier')), quality)
|
||||
temp.append(q)
|
||||
|
||||
self.cached_qualities = temp
|
||||
|
||||
pass #db.close()
|
||||
return temp
|
||||
|
||||
def single(self, identifier = ''):
|
||||
|
||||
db = get_session()
|
||||
db = get_db()
|
||||
quality_dict = {}
|
||||
|
||||
quality = db.query(Quality).filter(or_(Quality.identifier == identifier, Quality.id == identifier)).first()
|
||||
quality = db.get('quality', identifier, with_doc = True)['doc']
|
||||
if quality:
|
||||
quality_dict = dict(self.getQuality(quality.identifier), **quality.to_dict())
|
||||
quality_dict = mergeDicts(self.getQuality(quality['identifier']), quality)
|
||||
|
||||
pass #db.close()
|
||||
return quality_dict
|
||||
|
||||
def getQuality(self, identifier):
|
||||
@@ -128,60 +149,35 @@ class QualityPlugin(Plugin):
|
||||
def fill(self):
|
||||
|
||||
try:
|
||||
db = get_session()
|
||||
db = get_db()
|
||||
|
||||
order = 0
|
||||
for q in self.qualities:
|
||||
|
||||
# Create quality
|
||||
qual = db.query(Quality).filter_by(identifier = q.get('identifier')).first()
|
||||
db.insert({
|
||||
'_t': 'quality',
|
||||
'order': order,
|
||||
'identifier': q.get('identifier'),
|
||||
'size_min': q.get('size')[0],
|
||||
'size_max': q.get('size')[1]
|
||||
})
|
||||
|
||||
if not qual:
|
||||
log.info('Creating quality: %s', q.get('label'))
|
||||
qual = Quality()
|
||||
qual.order = order
|
||||
qual.identifier = q.get('identifier')
|
||||
qual.label = toUnicode(q.get('label'))
|
||||
qual.size_min, qual.size_max = q.get('size')
|
||||
|
||||
db.add(qual)
|
||||
|
||||
# Create single quality profile
|
||||
prof = db.query(Profile).filter(
|
||||
Profile.core == True
|
||||
).filter(
|
||||
Profile.types.any(quality = qual)
|
||||
).all()
|
||||
|
||||
if not prof:
|
||||
log.info('Creating profile: %s', q.get('label'))
|
||||
prof = Profile(
|
||||
core = True,
|
||||
label = toUnicode(qual.label),
|
||||
order = order
|
||||
)
|
||||
db.add(prof)
|
||||
|
||||
profile_type = ProfileType(
|
||||
quality = qual,
|
||||
profile = prof,
|
||||
finish = True,
|
||||
order = 0
|
||||
)
|
||||
prof.types.append(profile_type)
|
||||
log.info('Creating profile: %s', q.get('label'))
|
||||
db.insert({
|
||||
'_t': 'profile',
|
||||
'order': order + 20, # Make sure it goes behind other profiles
|
||||
'core': True,
|
||||
'qualities': [q.get('identifier')],
|
||||
'label': toUnicode(q.get('label')),
|
||||
'finish': [True],
|
||||
'wait_for': [0],
|
||||
})
|
||||
|
||||
order += 1
|
||||
|
||||
db.commit()
|
||||
|
||||
time.sleep(0.3) # Wait a moment
|
||||
|
||||
return True
|
||||
except:
|
||||
log.error('Failed: %s', traceback.format_exc())
|
||||
db.rollback()
|
||||
finally:
|
||||
pass #db.close()
|
||||
|
||||
return False
|
||||
|
||||
|
||||
@@ -5,15 +5,15 @@ from CodernityDB.tree_index import TreeBasedIndex
|
||||
class ReleaseIndex(TreeBasedIndex):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs['key_format'] = '16s'
|
||||
kwargs['key_format'] = '32s'
|
||||
super(ReleaseIndex, self).__init__(*args, **kwargs)
|
||||
|
||||
def make_key(self, key):
|
||||
return md5(key).digest()
|
||||
return md5(key).hexdigest()
|
||||
|
||||
def make_key_value(self, data):
|
||||
if data.get('type') == 'release' and data.get('media_id'):
|
||||
return md5(data['media_id']).digest(), {'media_id': data.get('media_id')}
|
||||
if data.get('_t') == 'release' and data.get('media_id'):
|
||||
return md5(data['media_id']).hexdigest(), {'media_id': data.get('media_id')}
|
||||
|
||||
def run_for_media(self, db, media_id):
|
||||
for release in db.get_many('release', media_id, with_doc = True):
|
||||
@@ -31,12 +31,26 @@ class ReleaseIndex(TreeBasedIndex):
|
||||
class ReleaseStatusIndex(TreeBasedIndex):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs['key_format'] = '16s'
|
||||
kwargs['key_format'] = '32s'
|
||||
super(ReleaseStatusIndex, self).__init__(*args, **kwargs)
|
||||
|
||||
def make_key(self, key):
|
||||
return md5(key).digest()
|
||||
return md5(key).hexdigest()
|
||||
|
||||
def make_key_value(self, data):
|
||||
if data.get('type') == 'release' and data.get('status'):
|
||||
return md5(data.get('status')).digest(), None
|
||||
if data.get('_t') == 'release' and data.get('status'):
|
||||
return md5(data.get('status')).hexdigest(), None
|
||||
|
||||
|
||||
class ReleaseIDIndex(TreeBasedIndex):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs['key_format'] = '32s'
|
||||
super(ReleaseIDIndex, self).__init__(*args, **kwargs)
|
||||
|
||||
def make_key(self, key):
|
||||
return md5(key).hexdigest()
|
||||
|
||||
def make_key_value(self, data):
|
||||
if data.get('_t') == 'release' and data.get('identifier'):
|
||||
return md5(data.get('identifier')).hexdigest(), None
|
||||
|
||||
@@ -5,7 +5,7 @@ from couchpotato.core.helpers.encoding import ss, toUnicode
|
||||
from couchpotato.core.helpers.variable import getTitle
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
from .index import ReleaseIndex, ReleaseStatusIndex
|
||||
from .index import ReleaseIndex, ReleaseStatusIndex, ReleaseIDIndex
|
||||
from couchpotato.core.plugins.scanner.main import Scanner
|
||||
from couchpotato.core.settings.model import Release as Relea, Media, \
|
||||
ReleaseInfo
|
||||
@@ -61,7 +61,7 @@ class Release(Plugin):
|
||||
addEvent('database.setup', self.databaseSetup)
|
||||
|
||||
# Clean releases that didn't have activity in the last week
|
||||
addEvent('app.load2', self.cleanDone)
|
||||
addEvent('app.load', self.cleanDone)
|
||||
fireEvent('schedule.interval', 'movie.clean_releases', self.cleanDone, hours = 4)
|
||||
|
||||
def databaseSetup(self):
|
||||
@@ -82,6 +82,13 @@ class Release(Plugin):
|
||||
log.debug('Index already exists')
|
||||
db.edit_index(ReleaseStatusIndex(db.path, 'release_status'))
|
||||
|
||||
# Release identifier index
|
||||
try:
|
||||
db.add_index(ReleaseIDIndex(db.path, 'release_identifier'))
|
||||
except:
|
||||
log.debug('Index already exists')
|
||||
db.edit_index(ReleaseIDIndex(db.path, 'release_identifier'))
|
||||
|
||||
def cleanDone(self):
|
||||
log.debug('Removing releases from dashboard')
|
||||
|
||||
@@ -112,7 +119,7 @@ class Release(Plugin):
|
||||
try:
|
||||
db = get_session()
|
||||
|
||||
identifier = '%s.%s.%s' % (group['library']['identifier'], group['meta_data'].get('audio', 'unknown'), group['meta_data']['quality']['identifier'])
|
||||
identifier = '%s.%s.%s' % (group['identifier'], group['meta_data'].get('audio', 'unknown'), group['meta_data']['quality']['identifier'])
|
||||
|
||||
# Add movie
|
||||
media = db.query(Media).filter_by(library_id = group['library'].get('id')).first()
|
||||
@@ -120,7 +127,7 @@ class Release(Plugin):
|
||||
media = Media(
|
||||
library_id = group['library'].get('id'),
|
||||
profile_id = 0,
|
||||
status_id = done_status.get('id')
|
||||
status = 'done'
|
||||
)
|
||||
db.add(media)
|
||||
db.commit()
|
||||
@@ -129,7 +136,7 @@ class Release(Plugin):
|
||||
rel = db.query(Relea).filter(
|
||||
or_(
|
||||
Relea.identifier == identifier,
|
||||
and_(Relea.identifier.startswith(group['library']['identifier']), Relea.status_id == snatched_status.get('id'))
|
||||
and_(Relea.identifier.startswith(group['identifier']), Relea.status == 'snatched')
|
||||
)
|
||||
).first()
|
||||
if not rel:
|
||||
@@ -137,7 +144,7 @@ class Release(Plugin):
|
||||
identifier = identifier,
|
||||
movie = media,
|
||||
quality_id = group['meta_data']['quality'].get('id'),
|
||||
status_id = done_status.get('id')
|
||||
status = 'done'
|
||||
)
|
||||
db.add(rel)
|
||||
db.commit()
|
||||
@@ -246,11 +253,6 @@ class Release(Plugin):
|
||||
# Get matching provider
|
||||
provider = fireEvent('provider.belongs_to', item['url'], provider = item.get('provider'), single = True)
|
||||
|
||||
# Backwards compatibility code
|
||||
if not item.get('protocol'):
|
||||
item['protocol'] = item['type']
|
||||
item['type'] = 'movie'
|
||||
|
||||
if item.get('protocol') != 'torrent_magnet':
|
||||
item['download'] = provider.loginDownload if provider.urls.get('login') else provider.download
|
||||
|
||||
@@ -271,11 +273,6 @@ class Release(Plugin):
|
||||
|
||||
def download(self, data, media, manual = False):
|
||||
|
||||
# Backwards compatibility code
|
||||
if not data.get('protocol'):
|
||||
data['protocol'] = data['type']
|
||||
data['type'] = 'movie'
|
||||
|
||||
# Test to see if any downloaders are enabled for this type
|
||||
downloader_enabled = fireEvent('download.enabled', manual, data, single = True)
|
||||
if not downloader_enabled:
|
||||
@@ -303,8 +300,6 @@ class Release(Plugin):
|
||||
return False
|
||||
log.debug('Downloader result: %s', download_result)
|
||||
|
||||
snatched_status, done_status, downloaded_status, active_status = fireEvent('status.get', ['snatched', 'done', 'downloaded', 'active'], single = True)
|
||||
|
||||
try:
|
||||
db = get_session()
|
||||
rls = db.query(Relea).filter_by(identifier = md5(data['url'])).first()
|
||||
@@ -324,7 +319,7 @@ class Release(Plugin):
|
||||
rls.info.append(rls_info)
|
||||
db.commit()
|
||||
|
||||
log_movie = '%s (%s) in %s' % (getTitle(media['library']), media['library']['year'], rls.quality.label)
|
||||
log_movie = '%s (%s) in %s' % (getTitle(media), media['info']['year'], rls.quality.label)
|
||||
snatch_message = 'Snatched "%s": %s' % (data.get('name'), log_movie)
|
||||
log.info(snatch_message)
|
||||
fireEvent('%s.snatched' % data['type'], message = snatch_message, data = rls.to_dict())
|
||||
@@ -335,7 +330,7 @@ class Release(Plugin):
|
||||
|
||||
# If renamer isn't used, mark media done if finished or release downloaded
|
||||
else:
|
||||
if media['status_id'] == active_status.get('id'):
|
||||
if media['status'] == 'active':
|
||||
finished = next((True for profile_type in media['profile']['types']
|
||||
if profile_type['quality_id'] == rls.quality.id and profile_type['finish']), False)
|
||||
if finished:
|
||||
@@ -346,7 +341,7 @@ class Release(Plugin):
|
||||
|
||||
# Mark media done
|
||||
mdia = db.query(Media).filter_by(id = media['id']).first()
|
||||
mdia.status_id = done_status.get('id')
|
||||
mdia.status = 'done'
|
||||
mdia.last_edit = int(time.time())
|
||||
db.commit()
|
||||
|
||||
@@ -364,15 +359,14 @@ class Release(Plugin):
|
||||
|
||||
return True
|
||||
|
||||
def tryDownloadResult(self, results, media, quality_type, manual = False):
|
||||
ignored_status, failed_status = fireEvent('status.get', ['ignored', 'failed'], single = True)
|
||||
def tryDownloadResult(self, results, media, quality_custom, manual = False):
|
||||
|
||||
for rel in results:
|
||||
if not quality_type.get('finish', False) and quality_type.get('wait_for', 0) > 0 and rel.get('age') <= quality_type.get('wait_for', 0):
|
||||
log.info('Ignored, waiting %s days: %s', (quality_type.get('wait_for'), rel['name']))
|
||||
if not quality_custom.get('finish', False) and quality_custom.get('wait_for', 0) > 0 and rel.get('age') <= quality_custom.get('wait_for', 0):
|
||||
log.info('Ignored, waiting %s days: %s', (quality_custom.get('wait_for'), rel['name']))
|
||||
continue
|
||||
|
||||
if rel['status_id'] in [ignored_status.get('id'), failed_status.get('id')]:
|
||||
if rel['status'] in ['ignored', 'failed']:
|
||||
log.info('Ignored: %s', rel['name'])
|
||||
continue
|
||||
|
||||
@@ -388,12 +382,10 @@ class Release(Plugin):
|
||||
|
||||
return False
|
||||
|
||||
def createFromSearch(self, search_results, media, quality_type):
|
||||
|
||||
available_status = fireEvent('status.get', ['available'], single = True)
|
||||
def createFromSearch(self, search_results, media, quality):
|
||||
|
||||
try:
|
||||
db = get_session()
|
||||
db = get_db()
|
||||
|
||||
found_releases = []
|
||||
|
||||
@@ -402,45 +394,40 @@ class Release(Plugin):
|
||||
rel_identifier = md5(rel['url'])
|
||||
found_releases.append(rel_identifier)
|
||||
|
||||
rls = db.query(Relea).filter_by(identifier = rel_identifier).first()
|
||||
if not rls:
|
||||
rls = Relea(
|
||||
identifier = rel_identifier,
|
||||
movie_id = media.get('id'),
|
||||
#media_id = media.get('id'),
|
||||
quality_id = quality_type.get('quality_id'),
|
||||
status_id = available_status.get('id')
|
||||
)
|
||||
db.add(rls)
|
||||
else:
|
||||
[db.delete(old_info) for old_info in rls.info]
|
||||
rls.last_edit = int(time.time())
|
||||
release = {
|
||||
'_t': 'release',
|
||||
'identifier': rel_identifier,
|
||||
'media_id': media.get('_id'),
|
||||
'quality': quality.get('identifier'),
|
||||
'status': 'available',
|
||||
'last_edit': int(time.time()),
|
||||
'info': {}
|
||||
}
|
||||
|
||||
db.commit()
|
||||
try:
|
||||
rls = db.get('release_identifier', rel_identifier, with_doc = True)['doc']
|
||||
except:
|
||||
rls = db.insert(release)
|
||||
rls.update(release)
|
||||
|
||||
# Update info, but filter out functions
|
||||
for info in rel:
|
||||
try:
|
||||
if not isinstance(rel[info], (str, unicode, int, long, float)):
|
||||
continue
|
||||
|
||||
rls_info = ReleaseInfo(
|
||||
identifier = info,
|
||||
value = toUnicode(rel[info])
|
||||
)
|
||||
rls.info.append(rls_info)
|
||||
rls['info'][info] = toUnicode(rel[info])
|
||||
except InterfaceError:
|
||||
log.debug('Couldn\'t add %s to ReleaseInfo: %s', (info, traceback.format_exc()))
|
||||
|
||||
db.commit()
|
||||
db.update(rls)
|
||||
|
||||
rel['status_id'] = rls.status_id
|
||||
# Update release in search_results
|
||||
rel['status'] = rls.get('status')
|
||||
|
||||
return found_releases
|
||||
except:
|
||||
log.error('Failed: %s', traceback.format_exc())
|
||||
db.rollback()
|
||||
finally:
|
||||
pass #db.close()
|
||||
|
||||
return []
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ class Renamer(Plugin):
|
||||
addEvent('renamer.scan', self.scan)
|
||||
addEvent('renamer.check_snatched', self.checkSnatched)
|
||||
|
||||
addEvent('app.load2', self.scan)
|
||||
addEvent('app.load', self.scan)
|
||||
addEvent('app.load', self.setCrons)
|
||||
|
||||
# Enable / disable interval
|
||||
@@ -222,23 +222,20 @@ class Renamer(Plugin):
|
||||
remove_files = []
|
||||
remove_releases = []
|
||||
|
||||
movie_title = getTitle(group['library'])
|
||||
movie_title = getTitle(group)
|
||||
|
||||
# Add _UNKNOWN_ if no library item is connected
|
||||
if not group['library'] or not movie_title:
|
||||
if not group.get('info') or not movie_title:
|
||||
self.tagRelease(group = group, tag = 'unknown')
|
||||
continue
|
||||
# Rename the files using the library data
|
||||
else:
|
||||
group['library'] = fireEvent('library.update.movie', identifier = group['library']['identifier'], single = True)
|
||||
if not group['library']:
|
||||
group['media'] = fireEvent('movie.update_info', identifier = group['media']['identifier'], single = True)
|
||||
if not group['media']:
|
||||
log.error('Could not rename, no library item to work with: %s', group_identifier)
|
||||
continue
|
||||
|
||||
library = group['library']
|
||||
library_ent = db.query(Library).filter_by(identifier = group['library']['identifier']).first()
|
||||
|
||||
movie_title = getTitle(library)
|
||||
movie_title = getTitle(group['media'])
|
||||
|
||||
# Overwrite destination when set in category
|
||||
destination = to_folder
|
||||
@@ -419,19 +416,19 @@ class Renamer(Plugin):
|
||||
# Add it to the wanted list before we continue
|
||||
if len(library_ent.movies) == 0:
|
||||
profile = db.query(Profile).filter_by(core = True, label = group['meta_data']['quality']['label']).first()
|
||||
fireEvent('movie.add', params = {'identifier': group['library']['identifier'], 'profile_id': profile.id}, search_after = False)
|
||||
fireEvent('movie.add', params = {'identifier': group['identifier'], 'profile_id': profile.id}, search_after = False)
|
||||
db.expire_all()
|
||||
library_ent = db.query(Library).filter_by(identifier = group['library']['identifier']).first()
|
||||
library_ent = db.query(Library).filter_by(identifier = group['identifier']).first()
|
||||
|
||||
for movie in library_ent.movies:
|
||||
|
||||
# Mark movie "done" once it's found the quality with the finish check
|
||||
try:
|
||||
if movie.status_id == active_status.get('id') and movie.profile:
|
||||
if movie.get('status') == 'active' and movie.get('profile_id'):
|
||||
for profile_type in movie.profile.types:
|
||||
if profile_type.quality_id == group['meta_data']['quality']['id'] and profile_type.finish:
|
||||
movie.status_id = done_status.get('id')
|
||||
movie.last_edit = int(time.time())
|
||||
movie['status'] = 'done'
|
||||
movie['last_edit'] = int(time.time())
|
||||
db.commit()
|
||||
except Exception as e:
|
||||
log.error('Failed marking movie finished: %s %s', (e, traceback.format_exc()))
|
||||
@@ -441,7 +438,7 @@ class Renamer(Plugin):
|
||||
for release in movie.releases:
|
||||
|
||||
# When a release already exists
|
||||
if release.status_id is done_status.get('id'):
|
||||
if release.get('status') == 'done':
|
||||
|
||||
# This is where CP removes older, lesser quality releases
|
||||
if release.quality.order > group['meta_data']['quality']['order']:
|
||||
@@ -470,7 +467,7 @@ class Renamer(Plugin):
|
||||
|
||||
break
|
||||
|
||||
elif release.status_id in [snatched_status.get('id'), seeding_status.get('id')]:
|
||||
elif release.get('status') in ['snatched', 'seeding']:
|
||||
if release_download and release_download.get('rls_id'):
|
||||
if release_download['rls_id'] == release.id:
|
||||
if release_download['status'] == 'completed':
|
||||
@@ -917,7 +914,7 @@ Remove it if you want it to be renamed (again, or at least let it try again)
|
||||
found_release = True
|
||||
break
|
||||
else:
|
||||
if release_download['name'] == nzbname or rel['info']['name'] in release_download['name'] or getImdb(release_download['name']) == movie_dict['library']['identifier']:
|
||||
if release_download['name'] == nzbname or rel['info']['name'] in release_download['name'] or getImdb(release_download['name']) == movie_dict['identifier']:
|
||||
log.debug('Found release by release name or imdb ID: %s', release_download['name'])
|
||||
found_release = True
|
||||
break
|
||||
@@ -951,7 +948,7 @@ Remove it if you want it to be renamed (again, or at least let it try again)
|
||||
|
||||
elif release_download['status'] == 'seeding':
|
||||
#If linking setting is enabled, process release
|
||||
if self.conf('file_action') != 'move' and not rel.status_id == 'seeding' and self.statusInfoComplete(release_download):
|
||||
if self.conf('file_action') != 'move' and not rel.get('status') == 'seeding' and self.statusInfoComplete(release_download):
|
||||
log.info('Download of %s completed! It is now being processed while leaving the original files alone for seeding. Current ratio: %s.', (release_download['name'], release_download['seed_ratio']))
|
||||
|
||||
# Remove the downloading tag
|
||||
|
||||
@@ -5,7 +5,7 @@ from couchpotato.core.helpers.variable import getExt, getImdb, tryInt, \
|
||||
splitString
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.plugins.base import Plugin
|
||||
from couchpotato.core.settings.model import File, Media
|
||||
from couchpotato.core.settings.model import File
|
||||
from enzyme.exceptions import NoParserError, ParseError
|
||||
from guessit import guess_movie_info
|
||||
from subliminal.videos import Video
|
||||
@@ -417,13 +417,11 @@ class Scanner(Plugin):
|
||||
del group['unsorted_files']
|
||||
|
||||
# Determine movie
|
||||
group['library'] = self.determineMovie(group, release_download = release_download)
|
||||
if not group['library']:
|
||||
log.error('Unable to determine movie: %s', group['identifiers'])
|
||||
group['media'] = self.determineMedia(group, release_download = release_download)
|
||||
if not group['media']:
|
||||
log.error('Unable to determine media: %s', group['identifiers'])
|
||||
else:
|
||||
movie = db.query(Media).filter_by(library_id = group['library']['id']).first()
|
||||
group['movie_id'] = None if not movie else movie.id
|
||||
db.expire_all()
|
||||
group['identifier'] = group['media']['identifier']
|
||||
|
||||
processed_movies[identifier] = group
|
||||
|
||||
@@ -554,7 +552,7 @@ class Scanner(Plugin):
|
||||
|
||||
return detected_languages
|
||||
|
||||
def determineMovie(self, group, release_download = None):
|
||||
def determineMedia(self, group, release_download = None):
|
||||
|
||||
# Get imdb id from downloader
|
||||
imdb_id = release_download and release_download.get('imdb_id')
|
||||
|
||||
@@ -24,11 +24,11 @@ class Score(Plugin):
|
||||
try: preferred_words = removeDuplicate(preferred_words + splitString(movie['category']['preferred'].lower()))
|
||||
except: pass
|
||||
|
||||
score = nameScore(toUnicode(nzb['name']), movie['library']['year'], preferred_words)
|
||||
score = nameScore(toUnicode(nzb['name']), movie['info']['year'], preferred_words)
|
||||
|
||||
for movie_title in movie['library']['titles']:
|
||||
score += nameRatioScore(toUnicode(nzb['name']), toUnicode(movie_title['title']))
|
||||
score += namePositionScore(toUnicode(nzb['name']), toUnicode(movie_title['title']))
|
||||
for movie_title in movie['info']['titles']:
|
||||
score += nameRatioScore(toUnicode(nzb['name']), toUnicode(movie_title))
|
||||
score += namePositionScore(toUnicode(nzb['name']), toUnicode(movie_title))
|
||||
|
||||
score += sizeScore(nzb['size'])
|
||||
|
||||
@@ -44,7 +44,7 @@ class Score(Plugin):
|
||||
score += providerScore(nzb['provider'])
|
||||
|
||||
# Duplicates in name
|
||||
score += duplicateScore(nzb['name'], getTitle(movie['library']))
|
||||
score += duplicateScore(nzb['name'], getTitle(movie))
|
||||
|
||||
# Merge global and category
|
||||
ignored_words = splitString(Env.setting('ignored_words', section = 'searcher').lower())
|
||||
@@ -52,7 +52,7 @@ class Score(Plugin):
|
||||
except: pass
|
||||
|
||||
# Partial ignored words
|
||||
score += partialIgnoredScore(nzb['name'], getTitle(movie['library']), ignored_words)
|
||||
score += partialIgnoredScore(nzb['name'], getTitle(movie), ignored_words)
|
||||
|
||||
# Ignore single downloads from multipart
|
||||
score += halfMultipartScore(nzb['name'])
|
||||
|
||||
@@ -25,14 +25,13 @@ class Subtitle(Plugin):
|
||||
db = get_session()
|
||||
|
||||
library = db.query(Library).all()
|
||||
done_status = fireEvent('status.get', 'done', single = True)
|
||||
|
||||
for movie in library.movies:
|
||||
|
||||
for release in movie.releases:
|
||||
|
||||
# get releases and their movie files
|
||||
if release.status_id is done_status.get('id'):
|
||||
if release.get('status') == 'done':
|
||||
|
||||
files = []
|
||||
for file in release.files.filter(FileType.status.has(identifier = 'movie')).all():
|
||||
|
||||
@@ -18,7 +18,7 @@ class Trailer(Plugin):
|
||||
|
||||
trailers = fireEvent('trailer.search', group = group, merge = True)
|
||||
if not trailers or trailers == []:
|
||||
log.info('No trailers found for: %s', getTitle(group['library']))
|
||||
log.info('No trailers found for: %s', getTitle(group))
|
||||
return False
|
||||
|
||||
for trailer in trailers.get(self.conf('quality'), []):
|
||||
|
||||
Reference in New Issue
Block a user