forked from 0x2620/pandora
update paths on item edit, enable editable fields in editFile, part is a string now
This commit is contained in:
parent
6916792f95
commit
3de99bb4b6
4 changed files with 21 additions and 27 deletions
|
@ -39,7 +39,7 @@ class File(models.Model):
|
|||
#editable
|
||||
extension = models.CharField(default="", max_length=255, null=True)
|
||||
language = models.CharField(default="", max_length=8, null=True)
|
||||
part = models.IntegerField(null=True)
|
||||
part = models.CharField(default="", max_length=255, null=True)
|
||||
part_title = models.CharField(default="", max_length=255, null=True)
|
||||
version = models.CharField(default="", max_length=255, null=True)
|
||||
|
||||
|
@ -167,6 +167,8 @@ class File(models.Model):
|
|||
if self.path:
|
||||
self.path = self.normalize_path()
|
||||
self.sort_path = utils.sort_string(self.path)
|
||||
data = ox.movie.parse_path(self.path)
|
||||
self.type = data['type'] or 'unknown'
|
||||
self.is_audio = self.type == 'audio'
|
||||
self.is_video = self.type == 'video'
|
||||
self.is_subtitle = self.path.endswith('.srt')
|
||||
|
@ -245,7 +247,11 @@ class File(models.Model):
|
|||
'framerate': self.framerate,
|
||||
'id': self.oshash,
|
||||
'instances': [i.json() for i in self.instances.all()],
|
||||
'extension': self.extension,
|
||||
'language': self.language,
|
||||
'part': self.part,
|
||||
'partTitle': self.part_title,
|
||||
'version': self.version,
|
||||
'path': self.path,
|
||||
'resolution': resolution,
|
||||
'samplerate': self.samplerate,
|
||||
|
@ -262,22 +268,6 @@ class File(models.Model):
|
|||
del data[k]
|
||||
return data
|
||||
|
||||
def get_part(self):
|
||||
if self.type not in ('audio', 'video'):
|
||||
name = os.path.splitext(self.path)[0]
|
||||
if self.language:
|
||||
name = name[-(len(self.language)+1)]
|
||||
qs = self.item.files.filter(Q(is_video=True)|Q(is_audio=True),
|
||||
selected=True, path__startswith=name)
|
||||
if qs.count()>0:
|
||||
return qs[0].get_part()
|
||||
if self.selected:
|
||||
files = list(self.item.files.filter(type=self.type, language=self.language,
|
||||
selected=self.selected).order_by('sort_path'))
|
||||
if self in files:
|
||||
return files.index(self) + 1
|
||||
return None
|
||||
|
||||
def all_paths(self):
|
||||
return [self.path] + [i.path for i in self.instances.all()]
|
||||
|
||||
|
|
|
@ -402,10 +402,11 @@ def editFile(request):
|
|||
#FIXME: is this to slow to run sync?
|
||||
f.item.update_selected()
|
||||
f.item.update_wanted()
|
||||
for key in ('part', 'language'):
|
||||
for key in ('extension', 'language', 'part', 'partTitle', 'version'):
|
||||
if key in data:
|
||||
setattr(f, key, data[key])
|
||||
f.auto = False
|
||||
setattr(f,
|
||||
re.sub('([A-Z])', lambda m: '_%s' % m.groups()[0].lower(), key),
|
||||
data[key])
|
||||
update = True
|
||||
if update:
|
||||
f.save()
|
||||
|
|
|
@ -368,9 +368,9 @@ class Item(models.Model):
|
|||
public_id = a.public_id.split('/')[1]
|
||||
a.public_id = "%s/%s" % (self.itemId, public_id)
|
||||
a.save()
|
||||
tasks.update_file_paths.delay(self.itemId)
|
||||
if update_poster:
|
||||
return tasks.update_poster.delay(self.itemId)
|
||||
|
||||
return None
|
||||
|
||||
def delete_files(self):
|
||||
|
@ -952,10 +952,6 @@ class Item(models.Model):
|
|||
if s.filter(selected=False).count() > 0:
|
||||
s.update(selected=True, wanted=False)
|
||||
update = True
|
||||
for f in s:
|
||||
if f.get_part() != f.part:
|
||||
f.save()
|
||||
update = True
|
||||
if update:
|
||||
self.rendered = False
|
||||
self.update_timeline()
|
||||
|
@ -1152,7 +1148,7 @@ class Item(models.Model):
|
|||
def poster_frames(self):
|
||||
frames = []
|
||||
offset = 0
|
||||
for f in self.files.filter(selected=True, is_video=True).order_by('part'):
|
||||
for f in self.files.filter(selected=True, is_video=True).order_by('sort_path'):
|
||||
for ff in f.frames.all().order_by('position'):
|
||||
frames.append({
|
||||
'position': offset + ff.position,
|
||||
|
@ -1225,7 +1221,7 @@ class Item(models.Model):
|
|||
|
||||
#loop over all videos
|
||||
for f in self.files.filter(Q(is_audio=True)|Q(is_video=True)) \
|
||||
.filter(selected=True).order_by('part'):
|
||||
.filter(selected=True).order_by('sort_path'):
|
||||
subtitles_added = False
|
||||
prefix = os.path.splitext(f.path)[0]
|
||||
if f.instances.all().count() > 0:
|
||||
|
|
|
@ -56,6 +56,13 @@ def update_poster(itemId):
|
|||
icon=item.icon.name
|
||||
)
|
||||
|
||||
@task(ignore_results=True, queue='default')
|
||||
def update_file_paths(itemId):
|
||||
item = models.Item.objects.get(itemId=itemId)
|
||||
for f in item.files.all():
|
||||
if f.normalize_path() != f.path:
|
||||
f.save()
|
||||
|
||||
@task(ignore_results=True, queue='default')
|
||||
def update_external(itemId):
|
||||
item = models.Item.objects.get(itemId=itemId)
|
||||
|
|
Loading…
Reference in a new issue