forked from 0x2620/pandora
rename item.json -> item.cache
This commit is contained in:
parent
1bac062a50
commit
bd0732b8d5
7 changed files with 50 additions and 28 deletions
|
@ -368,7 +368,7 @@ class Annotation(models.Model):
|
||||||
if key in self._clip_keys:
|
if key in self._clip_keys:
|
||||||
j[key] = getattr(self.clip, key)
|
j[key] = getattr(self.clip, key)
|
||||||
elif key not in self.annotation_keys:
|
elif key not in self.annotation_keys:
|
||||||
value = self.item.get(key) or self.item.json.get(key)
|
value = self.item.get(key) or self.item.cache.get(key)
|
||||||
if not value and hasattr(self.item.sort, key):
|
if not value and hasattr(self.item.sort, key):
|
||||||
value = getattr(self.item.sort, key)
|
value = getattr(self.item.sort, key)
|
||||||
if value != None:
|
if value != None:
|
||||||
|
|
|
@ -131,7 +131,7 @@ class MetaClip(object):
|
||||||
if key == 'streams':
|
if key == 'streams':
|
||||||
value = [s.file.oshash for s in self.item.streams()]
|
value = [s.file.oshash for s in self.item.streams()]
|
||||||
else:
|
else:
|
||||||
value = self.item.get(key) or self.item.json.get(key)
|
value = self.item.get(key) or self.item.cache.get(key)
|
||||||
if not value and hasattr(self.item.sort, key):
|
if not value and hasattr(self.item.sort, key):
|
||||||
value = getattr(self.item.sort, key)
|
value = getattr(self.item.sort, key)
|
||||||
if value is not None:
|
if value is not None:
|
||||||
|
@ -148,10 +148,10 @@ class MetaClip(object):
|
||||||
qs = self.annotations.all()
|
qs = self.annotations.all()
|
||||||
if qs.count():
|
if qs.count():
|
||||||
data['annotation'] = qs[0].public_id
|
data['annotation'] = qs[0].public_id
|
||||||
data['parts'] = self.item.json['parts']
|
data['parts'] = self.item.cache['parts']
|
||||||
data['durations'] = self.item.json['durations']
|
data['durations'] = self.item.cache['durations']
|
||||||
for key in ('title', 'director', 'year', 'videoRatio'):
|
for key in ('title', 'director', 'year', 'videoRatio'):
|
||||||
value = self.item.json.get(key)
|
value = self.item.cache.get(key)
|
||||||
if value:
|
if value:
|
||||||
data[key] = value
|
data[key] = value
|
||||||
data['duration'] = data['out'] - data['in']
|
data['duration'] = data['out'] - data['in']
|
||||||
|
|
|
@ -493,16 +493,16 @@ class Clip(models.Model):
|
||||||
data['item'] = self.item.public_id
|
data['item'] = self.item.public_id
|
||||||
data['in'] = self.annotation.start
|
data['in'] = self.annotation.start
|
||||||
data['out'] = self.annotation.end
|
data['out'] = self.annotation.end
|
||||||
data['parts'] = self.annotation.item.json['parts']
|
data['parts'] = self.annotation.item.cache['parts']
|
||||||
data['durations'] = self.annotation.item.json['durations']
|
data['durations'] = self.annotation.item.cache['durations']
|
||||||
else:
|
else:
|
||||||
data['item'] = self.item.public_id
|
data['item'] = self.item.public_id
|
||||||
data['in'] = self.start
|
data['in'] = self.start
|
||||||
data['out'] = self.end
|
data['out'] = self.end
|
||||||
data['parts'] = self.item.json['parts']
|
data['parts'] = self.item.cache['parts']
|
||||||
data['durations'] = self.item.json['durations']
|
data['durations'] = self.item.cache['durations']
|
||||||
for key in ('title', 'director', 'year', 'videoRatio'):
|
for key in ('title', 'director', 'year', 'videoRatio'):
|
||||||
value = self.item.json.get(key)
|
value = self.item.cache.get(key)
|
||||||
if value:
|
if value:
|
||||||
data[key] = value
|
data[key] = value
|
||||||
data['duration'] = data['out'] - data['in']
|
data['duration'] = data['out'] - data['in']
|
||||||
|
|
22
pandora/item/migrations/0004_json_cache.py
Normal file
22
pandora/item/migrations/0004_json_cache.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.13 on 2018-06-19 20:24
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import django.core.serializers.json
|
||||||
|
from django.db import migrations, models
|
||||||
|
import oxdjango.fields
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('item', '0003_jsonfield'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='item',
|
||||||
|
old_name='json',
|
||||||
|
new_name='cache',
|
||||||
|
),
|
||||||
|
]
|
|
@ -177,7 +177,7 @@ class Item(models.Model):
|
||||||
oxdbId = models.CharField(max_length=42, unique=True, blank=True, null=True)
|
oxdbId = models.CharField(max_length=42, unique=True, blank=True, null=True)
|
||||||
external_data = JSONField(default=dict, editable=False)
|
external_data = JSONField(default=dict, editable=False)
|
||||||
data = JSONField(default=dict, editable=False)
|
data = JSONField(default=dict, editable=False)
|
||||||
json = JSONField(default=dict, editable=False)
|
cache = JSONField(default=dict, editable=False)
|
||||||
poster = models.ImageField(default=None, blank=True, upload_to=get_poster_path)
|
poster = models.ImageField(default=None, blank=True, upload_to=get_poster_path)
|
||||||
poster_source = models.TextField(blank=True)
|
poster_source = models.TextField(blank=True)
|
||||||
poster_height = models.IntegerField(default=0)
|
poster_height = models.IntegerField(default=0)
|
||||||
|
@ -425,8 +425,8 @@ class Item(models.Model):
|
||||||
self.poster_width = 80
|
self.poster_width = 80
|
||||||
self.update_sort()
|
self.update_sort()
|
||||||
self.update_languages()
|
self.update_languages()
|
||||||
self.json = self.get_json()
|
self.cache = self.get_json()
|
||||||
self.json['modified'] = datetime.now()
|
self.cache['modified'] = datetime.now()
|
||||||
super(Item, self).save(*args, **kwargs)
|
super(Item, self).save(*args, **kwargs)
|
||||||
self.update_find()
|
self.update_find()
|
||||||
self.update_sort()
|
self.update_sort()
|
||||||
|
@ -1360,7 +1360,7 @@ class Item(models.Model):
|
||||||
if offset:
|
if offset:
|
||||||
self.data['volume'] /= offset
|
self.data['volume'] /= offset
|
||||||
# extract.timeline_strip(self, self.data['cuts'], stream.info, self.timeline_prefix[:-8])
|
# extract.timeline_strip(self, self.data['cuts'], stream.info, self.timeline_prefix[:-8])
|
||||||
self.json = self.get_json()
|
self.cache = self.get_json()
|
||||||
self.update_sort()
|
self.update_sort()
|
||||||
self.select_frame()
|
self.select_frame()
|
||||||
self.make_poster()
|
self.make_poster()
|
||||||
|
@ -1383,9 +1383,9 @@ class Item(models.Model):
|
||||||
self.poster_height = self.poster.height
|
self.poster_height = self.poster.height
|
||||||
self.poster_width = self.poster.width
|
self.poster_width = self.poster.width
|
||||||
self.clear_poster_cache(self.poster.path)
|
self.clear_poster_cache(self.poster.path)
|
||||||
if self.json.get('posterRatio') != self.poster_width / self.poster_height:
|
if self.cache.get('posterRatio') != self.poster_width / self.poster_height:
|
||||||
self.json = self.get_json()
|
self.cache = self.get_json()
|
||||||
Item.objects.filter(id=self.id).update(json=self.json,
|
Item.objects.filter(id=self.id).update(cache=self.cache,
|
||||||
poster_width=self.poster_width,
|
poster_width=self.poster_width,
|
||||||
poster_height=self.poster_height)
|
poster_height=self.poster_height)
|
||||||
|
|
||||||
|
@ -1467,7 +1467,7 @@ class Item(models.Model):
|
||||||
timeline = audio_timeline
|
timeline = audio_timeline
|
||||||
|
|
||||||
cmd = [settings.ITEM_POSTER, '-d', '-', '-p', poster]
|
cmd = [settings.ITEM_POSTER, '-d', '-', '-p', poster]
|
||||||
data = self.json.copy()
|
data = self.cache.copy()
|
||||||
if frame:
|
if frame:
|
||||||
data['frame'] = frame
|
data['frame'] = frame
|
||||||
if os.path.exists(timeline):
|
if os.path.exists(timeline):
|
||||||
|
@ -1495,8 +1495,8 @@ class Item(models.Model):
|
||||||
})
|
})
|
||||||
offset += f.duration
|
offset += f.duration
|
||||||
else:
|
else:
|
||||||
if 'videoRatio' in self.json and self.sort.duration and self.streams():
|
if 'videoRatio' in self.cache and self.sort.duration and self.streams():
|
||||||
width, height = self.json['resolution']
|
width, height = self.cache['resolution']
|
||||||
if width and height:
|
if width and height:
|
||||||
pos = self.sort.duration / 2
|
pos = self.sort.duration / 2
|
||||||
for p in [pos/2, pos, pos+pos/2]:
|
for p in [pos/2, pos, pos+pos/2]:
|
||||||
|
@ -1636,9 +1636,9 @@ class Item(models.Model):
|
||||||
for data in s.srt(offset):
|
for data in s.srt(offset):
|
||||||
subtitles_added = True
|
subtitles_added = True
|
||||||
value = data['value'].replace('\n', '<br>\n').replace('<br><br>\n', '<br>\n')
|
value = data['value'].replace('\n', '<br>\n').replace('<br><br>\n', '<br>\n')
|
||||||
if data['in'] < self.json['duration'] and data['out'] > self.json['duration']:
|
if data['in'] < self.cache['duration'] and data['out'] > self.cache['duration']:
|
||||||
data['out'] = self.json['duration']
|
data['out'] = self.cache['duration']
|
||||||
if data['in'] < self.json['duration']:
|
if data['in'] < self.cache['duration']:
|
||||||
new.append((float('%0.03f' % data['in']), float('%0.03f' % data['out']), value))
|
new.append((float('%0.03f' % data['in']), float('%0.03f' % data['out']), value))
|
||||||
# otherwise add empty 5 seconds annotation every minute
|
# otherwise add empty 5 seconds annotation every minute
|
||||||
if not subtitles_added:
|
if not subtitles_added:
|
||||||
|
|
|
@ -175,11 +175,11 @@ def only_p_sums(request, query, m):
|
||||||
if p == 'accessed':
|
if p == 'accessed':
|
||||||
r[p] = m.sort.accessed or ''
|
r[p] = m.sort.accessed or ''
|
||||||
elif p == 'editable':
|
elif p == 'editable':
|
||||||
r[p] = is_editable(request, m.json)
|
r[p] = is_editable(request, m.cache)
|
||||||
elif p in item_sort_keys:
|
elif p in item_sort_keys:
|
||||||
r[p] = getattr(m.sort, p)
|
r[p] = getattr(m.sort, p)
|
||||||
else:
|
else:
|
||||||
r[p] = m.json.get(p)
|
r[p] = m.cache.get(p)
|
||||||
if 'clip_qs' in query:
|
if 'clip_qs' in query:
|
||||||
r['clips'] = get_clips(query, query['clip_qs'].filter(item=m))
|
r['clips'] = get_clips(query, query['clip_qs'].filter(item=m))
|
||||||
return r
|
return r
|
||||||
|
@ -212,7 +212,7 @@ def get_items(request, query):
|
||||||
qs = qs.select_related()
|
qs = qs.select_related()
|
||||||
items = [only_p_sums(request, query, m) for m in qs]
|
items = [only_p_sums(request, query, m) for m in qs]
|
||||||
else:
|
else:
|
||||||
items = [only_p(request, query, m['json']) for m in qs.values('json')]
|
items = [only_p(request, query, m['cache']) for m in qs.values('cache')]
|
||||||
return items
|
return items
|
||||||
|
|
||||||
def get_stats(request, query):
|
def get_stats(request, query):
|
||||||
|
@ -1040,7 +1040,7 @@ def video(request, id, resolution, format, index=None, track=None):
|
||||||
if not r:
|
if not r:
|
||||||
return HttpResponseForbidden()
|
return HttpResponseForbidden()
|
||||||
path = video.name
|
path = video.name
|
||||||
duration = sum(item.json['durations'])
|
duration = sum(item.cache['durations'])
|
||||||
|
|
||||||
content_type = mimetypes.guess_type(path)[0]
|
content_type = mimetypes.guess_type(path)[0]
|
||||||
if len(t) == 2 and t[1] > t[0] and duration >= t[1]:
|
if len(t) == 2 and t[1] > t[0] and duration >= t[1]:
|
||||||
|
|
|
@ -55,5 +55,5 @@ class Sequence(models.Model):
|
||||||
if keys:
|
if keys:
|
||||||
for key in keys:
|
for key in keys:
|
||||||
if key not in j:
|
if key not in j:
|
||||||
j[key] = self.sort.item.json.get(key)
|
j[key] = self.sort.item.cache.get(key)
|
||||||
return j
|
return j
|
||||||
|
|
Loading…
Reference in a new issue