forked from 0x2620/pandora
cleanup poster update
This commit is contained in:
parent
4daf115dad
commit
c413d3526b
1 changed files with 25 additions and 27 deletions
|
@ -118,8 +118,9 @@ def get_item(info, user=None, async=False):
|
||||||
item = existing_item
|
item = existing_item
|
||||||
except Item.DoesNotExist:
|
except Item.DoesNotExist:
|
||||||
item.oxdbId = item.oxdb_id()
|
item.oxdbId = item.oxdb_id()
|
||||||
item.save()
|
p = item.save()
|
||||||
tasks.update_poster.delay(item.itemId)
|
if not p:
|
||||||
|
tasks.update_poster.delay(item.itemId)
|
||||||
else:
|
else:
|
||||||
qs = Item.objects.filter(find__key='title', find__value=info['title'])
|
qs = Item.objects.filter(find__key='title', find__value=info['title'])
|
||||||
if qs.count() == 1:
|
if qs.count() == 1:
|
||||||
|
@ -128,8 +129,9 @@ def get_item(info, user=None, async=False):
|
||||||
item = Item()
|
item = Item()
|
||||||
item.data = item_data
|
item.data = item_data
|
||||||
item.user = user
|
item.user = user
|
||||||
item.save()
|
p = item.save()
|
||||||
tasks.update_poster.delay(item.itemId)
|
if not p:
|
||||||
|
tasks.update_poster.delay(item.itemId)
|
||||||
return item
|
return item
|
||||||
|
|
||||||
class Item(models.Model):
|
class Item(models.Model):
|
||||||
|
@ -265,8 +267,11 @@ class Item(models.Model):
|
||||||
response = external_data('getData', {'id': self.itemId})
|
response = external_data('getData', {'id': self.itemId})
|
||||||
if response['status']['code'] == 200:
|
if response['status']['code'] == 200:
|
||||||
self.external_data = response['data']
|
self.external_data = response['data']
|
||||||
self.make_poster(True)
|
p = self.save()
|
||||||
self.save()
|
if p:
|
||||||
|
p.wait()
|
||||||
|
else:
|
||||||
|
self.make_poster(True)
|
||||||
|
|
||||||
def expand_connections(self):
|
def expand_connections(self):
|
||||||
c = self.get('connections')
|
c = self.get('connections')
|
||||||
|
@ -1058,19 +1063,6 @@ class Item(models.Model):
|
||||||
tasks.load_subtitles.delay(self.itemId)
|
tasks.load_subtitles.delay(self.itemId)
|
||||||
get_sequences.delay(self.itemId)
|
get_sequences.delay(self.itemId)
|
||||||
|
|
||||||
def delete_poster(self):
|
|
||||||
if self.poster:
|
|
||||||
path = self.poster.path
|
|
||||||
try:
|
|
||||||
self.poster.delete()
|
|
||||||
except:
|
|
||||||
self.poster.name = None
|
|
||||||
else:
|
|
||||||
poster= self.path('poster.jpg')
|
|
||||||
path = os.path.abspath(os.path.join(settings.MEDIA_ROOT, poster))
|
|
||||||
for f in glob(path.replace('.jpg', '*.jpg')):
|
|
||||||
os.unlink(f)
|
|
||||||
|
|
||||||
def save_poster(self, data):
|
def save_poster(self, data):
|
||||||
self.poster.name = self.path('poster.jpg')
|
self.poster.name = self.path('poster.jpg')
|
||||||
poster = self.poster.path
|
poster = self.poster.path
|
||||||
|
@ -1101,7 +1093,6 @@ class Item(models.Model):
|
||||||
def make_poster(self, force=False):
|
def make_poster(self, force=False):
|
||||||
ox.makedirs(os.path.join(settings.MEDIA_ROOT,self.path()))
|
ox.makedirs(os.path.join(settings.MEDIA_ROOT,self.path()))
|
||||||
if not self.poster or force:
|
if not self.poster or force:
|
||||||
self.delete_poster()
|
|
||||||
poster = self.make_siteposter()
|
poster = self.make_siteposter()
|
||||||
url = self.prefered_poster_url()
|
url = self.prefered_poster_url()
|
||||||
if url:
|
if url:
|
||||||
|
@ -1112,6 +1103,13 @@ class Item(models.Model):
|
||||||
data = f.read()
|
data = f.read()
|
||||||
if data:
|
if data:
|
||||||
self.save_poster(data)
|
self.save_poster(data)
|
||||||
|
poster = self.poster.path
|
||||||
|
for f in glob(poster.replace('.jpg', '*.jpg')):
|
||||||
|
if f != poster:
|
||||||
|
try:
|
||||||
|
os.unlink(f)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
def make_siteposter(self):
|
def make_siteposter(self):
|
||||||
poster = self.path('siteposter.jpg')
|
poster = self.path('siteposter.jpg')
|
||||||
|
@ -1194,13 +1192,13 @@ class Item(models.Model):
|
||||||
p = subprocess.Popen(cmd)
|
p = subprocess.Popen(cmd)
|
||||||
p.wait()
|
p.wait()
|
||||||
#remove cached versions
|
#remove cached versions
|
||||||
icons = os.path.abspath(os.path.join(settings.MEDIA_ROOT, icon))
|
icon = os.path.abspath(os.path.join(settings.MEDIA_ROOT, icon))
|
||||||
icons = glob(icons.replace('.jpg', '*.jpg'))
|
for f in glob(icon.replace('.jpg', '*.jpg')):
|
||||||
for f in filter(lambda p: not p.endswith('/icon.jpg'), icons):
|
if f != icon:
|
||||||
try:
|
try:
|
||||||
os.unlink(f)
|
os.unlink(f)
|
||||||
except:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
return icon
|
return icon
|
||||||
|
|
||||||
def load_subtitles(self):
|
def load_subtitles(self):
|
||||||
|
|
Loading…
Reference in a new issue