forked from 0x2620/pandora
support vtt subtitles
This commit is contained in:
parent
f8f951c966
commit
6f4a0ba90a
3 changed files with 18 additions and 8 deletions
|
@ -19,7 +19,7 @@ class Command(BaseCommand):
|
||||||
"""
|
"""
|
||||||
import annotations
|
import annotations
|
||||||
"""
|
"""
|
||||||
help = 'import annotations from srt'
|
help = 'import annotations from srt or vtt'
|
||||||
args = 'username item layername filename.srt'
|
args = 'username item layername filename.srt'
|
||||||
option_list = BaseCommand.option_list + (
|
option_list = BaseCommand.option_list + (
|
||||||
)
|
)
|
||||||
|
@ -33,7 +33,10 @@ class Command(BaseCommand):
|
||||||
item = Item.objects.get(public_id=public_id)
|
item = Item.objects.get(public_id=public_id)
|
||||||
layer = filter(lambda l: l['id'] == layer_id, settings.CONFIG['layers'])[0]
|
layer = filter(lambda l: l['id'] == layer_id, settings.CONFIG['layers'])[0]
|
||||||
|
|
||||||
annotations = ox.srt.load(filename)
|
if filename.endswith('.vtt'):
|
||||||
|
annotations = ox.vtt.load(filename)
|
||||||
|
else:
|
||||||
|
annotations = ox.srt.load(filename)
|
||||||
print('importing %d annotations into %s/%s' % (len(annotations), public_id, layer_id))
|
print('importing %d annotations into %s/%s' % (len(annotations), public_id, layer_id))
|
||||||
for i in range(len(annotations)-1):
|
for i in range(len(annotations)-1):
|
||||||
if annotations[i]['out'] == annotations[i+1]['in']:
|
if annotations[i]['out'] == annotations[i+1]['in']:
|
||||||
|
|
|
@ -256,7 +256,7 @@ class File(models.Model):
|
||||||
self.sort_path = utils.sort_string(self.path)
|
self.sort_path = utils.sort_string(self.path)
|
||||||
self.is_audio = self.type == 'audio'
|
self.is_audio = self.type == 'audio'
|
||||||
self.is_video = self.type == 'video'
|
self.is_video = self.type == 'video'
|
||||||
self.is_subtitle = self.path.endswith('.srt')
|
self.is_subtitle = self.path.split('.')[-1] in ('srt', 'vtt')
|
||||||
|
|
||||||
if self.type not in ('audio', 'video'):
|
if self.type not in ('audio', 'video'):
|
||||||
self.duration = None
|
self.duration = None
|
||||||
|
@ -289,7 +289,11 @@ class File(models.Model):
|
||||||
def srt(self, offset=0):
|
def srt(self, offset=0):
|
||||||
srt = []
|
srt = []
|
||||||
subtitles = []
|
subtitles = []
|
||||||
for s in ox.srt.load(self.data.path):
|
if self.data.path.endswith('.vtt'):
|
||||||
|
load = ox.vtt.load
|
||||||
|
else:
|
||||||
|
load = ox.srt.load
|
||||||
|
for s in load(self.data.path):
|
||||||
if s['in'] <= s['out'] and s['value'].strip():
|
if s['in'] <= s['out'] and s['value'].strip():
|
||||||
key = '%s --> %s\n%s' % (s['in'], s['out'], s['value'])
|
key = '%s --> %s\n%s' % (s['in'], s['out'], s['value'])
|
||||||
if key not in subtitles:
|
if key not in subtitles:
|
||||||
|
|
|
@ -103,10 +103,13 @@ def update(request, data):
|
||||||
file__wanted=True)]
|
file__wanted=True)]
|
||||||
|
|
||||||
if filter(lambda l: l['id'] == 'subtitles', settings.CONFIG['layers']):
|
if filter(lambda l: l['id'] == 'subtitles', settings.CONFIG['layers']):
|
||||||
response['data']['file'] = [f.file.oshash
|
qs = files.filter(
|
||||||
for f in files.filter(file__is_subtitle=True,
|
file__is_subtitle=True,
|
||||||
file__available=False,
|
file__available=False
|
||||||
path__endswith='.srt')]
|
).filter(
|
||||||
|
Q(path__endswith='.srt') | Q(path__endswith='.vtt')
|
||||||
|
)
|
||||||
|
response['data']['file'] = [f.file.oshash for f in qs]
|
||||||
else:
|
else:
|
||||||
response['data']['file'] = []
|
response['data']['file'] = []
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
|
|
Loading…
Reference in a new issue