imdb check

This commit is contained in:
j 2019-07-23 17:42:56 +02:00
parent 7a539b37b8
commit ec3175d885
2 changed files with 9 additions and 5 deletions

View file

@ -387,7 +387,7 @@ class Item(models.Model):
if self.oxdbId != oxdbId: if self.oxdbId != oxdbId:
q = Item.objects.filter(oxdbId=oxdbId).exclude(id=self.id) q = Item.objects.filter(oxdbId=oxdbId).exclude(id=self.id)
if q.count() != 0: if q.count() != 0:
if len(self.public_id) == 7: if utils.is_imdb_id(self.public_id):
self.oxdbId = None self.oxdbId = None
q[0].merge_with(self, save=False) q[0].merge_with(self, save=False)
else: else:
@ -401,14 +401,14 @@ class Item(models.Model):
q = Item.objects.filter(oxdbId=oxdbId).exclude(id=self.id) q = Item.objects.filter(oxdbId=oxdbId).exclude(id=self.id)
self.oxdbId = oxdbId self.oxdbId = oxdbId
update_poster = True update_poster = True
if len(self.public_id) != 7: if not utils.is_imdb_id(self.public_id):
update_ids = True update_ids = True
# id changed, what about existing item with new id? # id changed, what about existing item with new id?
if settings.USE_IMDB and len(self.public_id) != 7 and self.oxdbId != self.public_id: if settings.USE_IMDB and not utils.is_imdb_id(self.public_id) and self.oxdbId != self.public_id:
self.public_id = self.oxdbId self.public_id = self.oxdbId
# FIXME: move files to new id here # FIXME: move files to new id here
if settings.USE_IMDB and len(self.public_id) == 7: if settings.USE_IMDB and utils.is_imdb_id(self.public_id):
for key in ('title', 'year', 'director', 'season', 'episode', for key in ('title', 'year', 'director', 'season', 'episode',
'seriesTitle', 'episodeTitle'): 'seriesTitle', 'episodeTitle'):
if key in self.data: if key in self.data:
@ -418,7 +418,7 @@ class Item(models.Model):
if settings.USE_IMDB: if settings.USE_IMDB:
defaults = list(filter(lambda k: 'default' in k, settings.CONFIG['itemKeys'])) defaults = list(filter(lambda k: 'default' in k, settings.CONFIG['itemKeys']))
for k in defaults: for k in defaults:
if len(self.public_id) == 7: if utils.is_imdb_id(self.public_id):
if k['id'] in self.data and self.data[k['id']] == k['default']: if k['id'] in self.data and self.data[k['id']] == k['default']:
del self.data[k['id']] del self.data[k['id']]
else: else:

View file

@ -103,3 +103,7 @@ def normalize_dict(encoding, data):
elif isinstance(data, list): elif isinstance(data, list):
return [normalize_dict(encoding, value) for value in data] return [normalize_dict(encoding, value) for value in data]
return data return data
def is_imdb_id(id):
return bool(len(id) >= 7 and str(id).isdigit())