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