Merge branch 'refs/heads/develop' into tv
This commit is contained in:
@@ -42,17 +42,21 @@ class Database(object):
|
||||
db = self.getDB()
|
||||
|
||||
# Category index
|
||||
index_instance = klass(db.path, index_name)
|
||||
try:
|
||||
db.add_index(klass(db.path, index_name))
|
||||
db.add_index(index_instance)
|
||||
db.reindex_index(index_name)
|
||||
except:
|
||||
previous_version = db.indexes_names[index_name]._version
|
||||
previous = db.indexes_names[index_name]
|
||||
previous_version = previous._version
|
||||
current_version = klass._version
|
||||
|
||||
# Only edit index if versions are different
|
||||
if previous_version < current_version:
|
||||
log.debug('Index "%s" already exists, updating and reindexing', index_name)
|
||||
db.edit_index(klass(db.path, index_name), reindex = True)
|
||||
db.destroy_index(previous)
|
||||
db.add_index(index_instance)
|
||||
db.reindex_index(index_name)
|
||||
|
||||
def deleteDocument(self, **kwargs):
|
||||
|
||||
@@ -155,7 +159,15 @@ class Database(object):
|
||||
for ml in migrate_list:
|
||||
migrate_data[ml] = {}
|
||||
rows = migrate_list[ml]
|
||||
c.execute('SELECT %s FROM `%s`' % ('`' + '`,`'.join(rows) + '`', ml))
|
||||
|
||||
try:
|
||||
c.execute('SELECT %s FROM `%s`' % ('`' + '`,`'.join(rows) + '`', ml))
|
||||
except:
|
||||
# ignore faulty destination_id database
|
||||
if ml == 'category':
|
||||
migrate_data[ml] = {}
|
||||
else:
|
||||
raise
|
||||
|
||||
for p in c.fetchall():
|
||||
columns = {}
|
||||
|
||||
@@ -1,30 +1,48 @@
|
||||
from string import ascii_letters
|
||||
from hashlib import md5
|
||||
|
||||
from CodernityDB.hash_index import HashIndex
|
||||
from CodernityDB.tree_index import MultiTreeBasedIndex, TreeBasedIndex
|
||||
from couchpotato.core.helpers.encoding import toUnicode, simplifyString
|
||||
|
||||
|
||||
class MediaIMDBIndex(HashIndex):
|
||||
_version = 1
|
||||
class MediaIndex(MultiTreeBasedIndex):
|
||||
_version = 2
|
||||
|
||||
custom_header = """from CodernityDB.tree_index import MultiTreeBasedIndex"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs['key_format'] = 'I'
|
||||
super(MediaIMDBIndex, self).__init__(*args, **kwargs)
|
||||
kwargs['key_format'] = '32s'
|
||||
super(MediaIndex, self).__init__(*args, **kwargs)
|
||||
|
||||
def make_key(self, key):
|
||||
return int(key.strip('t'))
|
||||
return md5(key).hexdigest()
|
||||
|
||||
def make_key_value(self, data):
|
||||
if data.get('_t') == 'media' and data.get('identifier'):
|
||||
return int(data['identifier'].strip('t')), None
|
||||
if data.get('_t') == 'media' and (data.get('identifier') or data.get('identifiers')):
|
||||
|
||||
identifiers = data.get('identifiers', {})
|
||||
if data.get('identifier') and 'imdb' not in identifiers:
|
||||
identifiers['imdb'] = data.get('identifier')
|
||||
|
||||
ids = []
|
||||
for x in identifiers:
|
||||
ids.append(md5('%s-%s' % (x, data['identifiers'][x])).hexdigest())
|
||||
|
||||
return ids, None
|
||||
|
||||
def run_to_dict(self, db, media_id, dict_dept = None):
|
||||
if not dict_dept: dict_dept = {}
|
||||
|
||||
return db.get('id', media_id)
|
||||
|
||||
def run_identifiers(self, db, identifiers, with_doc = False):
|
||||
for x in identifiers:
|
||||
try:
|
||||
media = db.get('media', '%s-%s' % (x, identifiers[x]), with_doc = with_doc)
|
||||
return media
|
||||
except:
|
||||
pass
|
||||
|
||||
def run_with_status(self, db, status = [], with_doc = True):
|
||||
|
||||
status = list(status if isinstance(status, (list, tuple)) else [status])
|
||||
|
||||
@@ -8,18 +8,16 @@ from couchpotato.core.helpers.encoding import toUnicode
|
||||
from couchpotato.core.helpers.variable import splitString, getImdb, getTitle
|
||||
from couchpotato.core.logger import CPLog
|
||||
from couchpotato.core.media import MediaBase
|
||||
from .index import MediaIMDBIndex, MediaStatusIndex, MediaTypeIndex, TitleSearchIndex, TitleIndex, StartsWithIndex
|
||||
from .index import MediaIndex, MediaStatusIndex, MediaTypeIndex, TitleSearchIndex, TitleIndex, StartsWithIndex
|
||||
|
||||
|
||||
log = CPLog(__name__)
|
||||
|
||||
autoload = 'MediaPlugin'
|
||||
|
||||
|
||||
class MediaPlugin(MediaBase):
|
||||
|
||||
_database = {
|
||||
'media': MediaIMDBIndex,
|
||||
'media': MediaIndex,
|
||||
'media_search_title': TitleSearchIndex,
|
||||
'media_status': MediaStatusIndex,
|
||||
'media_by_type': MediaTypeIndex,
|
||||
@@ -127,7 +125,7 @@ class MediaPlugin(MediaBase):
|
||||
imdb_id = getImdb(str(media_id))
|
||||
|
||||
if imdb_id:
|
||||
m = db.get('media', imdb_id, with_doc = True)['doc']
|
||||
m = db.get('media', 'imdb-%s' % imdb_id, with_doc = True)['doc']
|
||||
else:
|
||||
m = db.get('id', media_id)
|
||||
|
||||
|
||||
@@ -101,7 +101,9 @@ class MovieBase(MovieTypeBase):
|
||||
'_t': 'media',
|
||||
'type': 'movie',
|
||||
'title': def_title,
|
||||
'identifier': params.get('identifier'),
|
||||
'identifiers': {
|
||||
'imdb': params.get('identifier')
|
||||
},
|
||||
'status': status if status else 'active',
|
||||
'profile_id': params.get('profile_id', default_profile.get('_id')),
|
||||
'category_id': cat_id if cat_id is not None and len(cat_id) > 0 and cat_id != '-1' else None,
|
||||
@@ -116,7 +118,7 @@ class MovieBase(MovieTypeBase):
|
||||
|
||||
new = False
|
||||
try:
|
||||
m = db.get('media', params.get('identifier'), with_doc = True)['doc']
|
||||
m = db.get('media', 'imdb-%s' % params.get('identifier'), with_doc = True)['doc']
|
||||
except:
|
||||
new = True
|
||||
m = db.insert(media)
|
||||
@@ -262,7 +264,7 @@ class MovieBase(MovieTypeBase):
|
||||
if media_id:
|
||||
media = db.get('id', media_id)
|
||||
else:
|
||||
media = db.get('media', identifier, with_doc = True)['doc']
|
||||
media = db.get('media', 'imdb-%s' % identifier, with_doc = True)['doc']
|
||||
|
||||
info = fireEvent('movie.info', merge = True, extended = extended, identifier = media.get('identifier'))
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ class MovieResultModifier(Plugin):
|
||||
|
||||
media = None
|
||||
try:
|
||||
media = db.get('media', imdb, with_doc = True)['doc']
|
||||
media = db.get('media', 'imdb-%s' % imdb, with_doc = True)['doc']
|
||||
except RecordNotFound:
|
||||
pass
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ class Release(Plugin):
|
||||
|
||||
# Add movie if it doesn't exist
|
||||
try:
|
||||
media = db.get('media', group['identifier'], with_doc = True)['doc']
|
||||
media = db.get('media', 'imdb-%s' % group['identifier'], with_doc = True)['doc']
|
||||
except:
|
||||
media = fireEvent('movie.add', params = {
|
||||
'identifier': group['identifier'],
|
||||
|
||||
Reference in New Issue
Block a user