switch
This commit is contained in:
parent
79dbeabafc
commit
1e81dc4fa1
1 changed files with 61 additions and 60 deletions
|
@ -1540,73 +1540,74 @@ class Item(models.Model):
|
||||||
existing = self.annotations.filter(layer=layer).exclude(value='')
|
existing = self.annotations.filter(layer=layer).exclude(value='')
|
||||||
# only import on 0xdb for now or if forced manually
|
# only import on 0xdb for now or if forced manually
|
||||||
# since this will remove all existing subtitles
|
# since this will remove all existing subtitles
|
||||||
if not (settings.USE_IMDB or existing.count() == 0) or not force:
|
if force or not existing.count() or settings.USE_IMDB:
|
||||||
self.add_empty_clips()
|
with transaction.commit_on_success():
|
||||||
return False
|
Annotation.objects.filter(layer=layer, item=self).delete()
|
||||||
with transaction.commit_on_success():
|
AnnotationSequence.reset(self)
|
||||||
Annotation.objects.filter(layer=layer, item=self).delete()
|
offset = 0
|
||||||
AnnotationSequence.reset(self)
|
language = ''
|
||||||
offset = 0
|
subtitles = self.files.filter(selected=True, is_subtitle=True, available=True)
|
||||||
language = ''
|
languages = [f.language for f in subtitles]
|
||||||
subtitles = self.files.filter(selected=True, is_subtitle=True, available=True)
|
if languages:
|
||||||
languages = [f.language for f in subtitles]
|
if 'en' in languages:
|
||||||
if languages:
|
language = 'en'
|
||||||
if 'en' in languages:
|
elif '' in languages:
|
||||||
language = 'en'
|
language = ''
|
||||||
elif '' in languages:
|
else:
|
||||||
language = ''
|
language = languages[0]
|
||||||
else:
|
|
||||||
language = languages[0]
|
|
||||||
|
|
||||||
#loop over all videos
|
#loop over all videos
|
||||||
for f in self.files.filter(Q(is_audio=True)|Q(is_video=True)) \
|
for f in self.files.filter(Q(is_audio=True)|Q(is_video=True)) \
|
||||||
.filter(selected=True).order_by('sort_path'):
|
.filter(selected=True).order_by('sort_path'):
|
||||||
subtitles_added = False
|
subtitles_added = False
|
||||||
prefix = os.path.splitext(f.path)[0]
|
prefix = os.path.splitext(f.path)[0]
|
||||||
if f.instances.all().count() > 0:
|
if f.instances.all().count() > 0:
|
||||||
user = f.instances.all()[0].volume.user
|
user = f.instances.all()[0].volume.user
|
||||||
else:
|
else:
|
||||||
#FIXME: allow annotations from no user instead?
|
#FIXME: allow annotations from no user instead?
|
||||||
user = User.objects.all().order_by('id')[0]
|
user = User.objects.all().order_by('id')[0]
|
||||||
#if there is a subtitle with the same prefix, import
|
#if there is a subtitle with the same prefix, import
|
||||||
q = subtitles.filter(path__startswith=prefix,
|
q = subtitles.filter(path__startswith=prefix,
|
||||||
language=language)
|
language=language)
|
||||||
if q.count() == 1:
|
if q.count() == 1:
|
||||||
s = q[0]
|
s = q[0]
|
||||||
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.json['duration'] and data['out'] > self.json['duration']:
|
||||||
data['out'] = self.json['duration']
|
data['out'] = self.json['duration']
|
||||||
if data['in'] < self.json['duration']:
|
if data['in'] < self.json['duration']:
|
||||||
|
annotation = Annotation(
|
||||||
|
item=self,
|
||||||
|
layer=layer,
|
||||||
|
start=float('%0.03f'%data['in']),
|
||||||
|
end=float('%0.03f'%data['out']),
|
||||||
|
value=value,
|
||||||
|
user=user
|
||||||
|
)
|
||||||
|
annotation.save()
|
||||||
|
#otherwise add empty 5 seconds annotation every minute
|
||||||
|
if not subtitles_added:
|
||||||
|
start = offset and int (offset / 60) * 60 + 60 or 0
|
||||||
|
for i in range(start,
|
||||||
|
int(offset + f.duration) - 5,
|
||||||
|
60):
|
||||||
annotation = Annotation(
|
annotation = Annotation(
|
||||||
item=self,
|
item=self,
|
||||||
layer=layer,
|
layer=layer,
|
||||||
start=float('%0.03f'%data['in']),
|
start=i,
|
||||||
end=float('%0.03f'%data['out']),
|
end=i + 5,
|
||||||
value=value,
|
value='',
|
||||||
user=user
|
user=user
|
||||||
)
|
)
|
||||||
annotation.save()
|
annotation.save()
|
||||||
#otherwise add empty 5 seconds annotation every minute
|
offset += f.duration
|
||||||
if not subtitles_added:
|
#remove left over clips without annotations
|
||||||
start = offset and int (offset / 60) * 60 + 60 or 0
|
Clip.objects.filter(item=self, annotations__id=None).delete()
|
||||||
for i in range(start,
|
return True
|
||||||
int(offset + f.duration) - 5,
|
else:
|
||||||
60):
|
self.add_empty_clips()
|
||||||
annotation = Annotation(
|
return False
|
||||||
item=self,
|
|
||||||
layer=layer,
|
|
||||||
start=i,
|
|
||||||
end=i + 5,
|
|
||||||
value='',
|
|
||||||
user=user
|
|
||||||
)
|
|
||||||
annotation.save()
|
|
||||||
offset += f.duration
|
|
||||||
#remove left over clips without annotations
|
|
||||||
Clip.objects.filter(item=self, annotations__id=None).delete()
|
|
||||||
return True
|
|
||||||
|
|
||||||
def srt(self, layer, language=None):
|
def srt(self, layer, language=None):
|
||||||
def format_value(value):
|
def format_value(value):
|
||||||
|
|
Loading…
Reference in a new issue