matches. load subtitle annotations into database
This commit is contained in:
parent
6406a6506c
commit
76fcb1b61e
4 changed files with 32 additions and 18 deletions
|
@ -43,7 +43,7 @@ class File(models.Model):
|
||||||
episode = models.IntegerField(default=-1)
|
episode = models.IntegerField(default=-1)
|
||||||
|
|
||||||
size = models.BigIntegerField(default=0)
|
size = models.BigIntegerField(default=0)
|
||||||
duration = models.BigIntegerField(null=True)
|
duration = models.FloatField(null=True)
|
||||||
|
|
||||||
info = fields.DictField(default={})
|
info = fields.DictField(default={})
|
||||||
|
|
||||||
|
@ -143,8 +143,8 @@ class File(models.Model):
|
||||||
if not self.is_audio and not self.is_video and self.name.endswith('.srt'):
|
if not self.is_audio and not self.is_video and self.name.endswith('.srt'):
|
||||||
self.is_subtitle = True
|
self.is_subtitle = True
|
||||||
|
|
||||||
self.part = self.get_part()
|
|
||||||
self.type = self.get_type()
|
self.type = self.get_type()
|
||||||
|
self.part = self.get_part()
|
||||||
|
|
||||||
if self.type not in ('audio', 'video'):
|
if self.type not in ('audio', 'video'):
|
||||||
self.duration = None
|
self.duration = None
|
||||||
|
@ -166,7 +166,7 @@ class File(models.Model):
|
||||||
return self.data.read()
|
return self.data.read()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def srt(self):
|
def srt(self, offset=0):
|
||||||
|
|
||||||
def _detectEncoding(fp):
|
def _detectEncoding(fp):
|
||||||
bomDict={ # bytepattern : name
|
bomDict={ # bytepattern : name
|
||||||
|
@ -203,7 +203,7 @@ class File(models.Model):
|
||||||
return encoding
|
return encoding
|
||||||
|
|
||||||
def parseTime(t):
|
def parseTime(t):
|
||||||
return ox.time2ms(t.replace(',', '.')) / 1000
|
return offset + ox.time2ms(t.replace(',', '.')) / 1000
|
||||||
|
|
||||||
srt = []
|
srt = []
|
||||||
|
|
||||||
|
|
|
@ -89,15 +89,3 @@ def update_files(user, volume, files):
|
||||||
#FIXME: can this have any bad consequences? i.e. on the selction of used item files.
|
#FIXME: can this have any bad consequences? i.e. on the selction of used item files.
|
||||||
models.Instance.objects.filter(volume=volume).exclude(file__oshash__in=all_files).delete()
|
models.Instance.objects.filter(volume=volume).exclude(file__oshash__in=all_files).delete()
|
||||||
|
|
||||||
def import_subtitles(id):
|
|
||||||
f = models.File.objects.get(pk=id)
|
|
||||||
layer = models.Layer.objects.get(name='subtitles')
|
|
||||||
for data in f.srt():
|
|
||||||
annotation = models.Annotation(
|
|
||||||
item=f.item,
|
|
||||||
layer=layer,
|
|
||||||
start=data['in'],
|
|
||||||
end=data['out'],
|
|
||||||
value=data['value']
|
|
||||||
)
|
|
||||||
annotation.save()
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from celery.decorators import task, periodic_task
|
from celery.decorators import task, periodic_task
|
||||||
|
from django.db.models import Q
|
||||||
|
|
||||||
import models
|
import models
|
||||||
|
|
||||||
|
@ -34,3 +35,24 @@ def update_streams(itemId):
|
||||||
if item.files.filter(is_main=True, is_video=True, available=False).count() == 0:
|
if item.files.filter(is_main=True, is_video=True, available=False).count() == 0:
|
||||||
item.update_streams()
|
item.update_streams()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def load_subtitles(itemId):
|
||||||
|
item = models.Item.objects.get(itemId=itemId)
|
||||||
|
layer = models.Layer.objects.get(name='subtitles')
|
||||||
|
models.Annotation.objects.filter(layer=layer,item=item).delete()
|
||||||
|
offset = 0
|
||||||
|
for f in item.files.filter(is_main=True, is_subtitle=True, available=True).order_by('part'):
|
||||||
|
user = f.instances.all()[0].volume.user
|
||||||
|
for data in f.srt(offset):
|
||||||
|
annotation = models.Annotation(
|
||||||
|
item=f.item,
|
||||||
|
layer=layer,
|
||||||
|
start=data['in'],
|
||||||
|
end=data['out'],
|
||||||
|
value=data['value'],
|
||||||
|
user=user
|
||||||
|
)
|
||||||
|
annotation.save()
|
||||||
|
duration = item.files.filter(Q(is_audio=True)|Q(is_video=True)) \
|
||||||
|
.filter(is_main=True, available=True, part=f.part)[0].duration
|
||||||
|
offset += duration
|
||||||
|
|
|
@ -6,8 +6,10 @@ from django.db import models
|
||||||
import ox
|
import ox
|
||||||
from ox.django import fields
|
from ox.django import fields
|
||||||
from django.contrib.auth.models import User, Group
|
from django.contrib.auth.models import User, Group
|
||||||
|
from django.db.models import Q
|
||||||
|
|
||||||
import managers
|
import managers
|
||||||
|
from annotation.models import Annotation
|
||||||
|
|
||||||
class Place(models.Model):
|
class Place(models.Model):
|
||||||
'''
|
'''
|
||||||
|
@ -69,8 +71,10 @@ class Place(models.Model):
|
||||||
return j
|
return j
|
||||||
|
|
||||||
def update_matches(self):
|
def update_matches(self):
|
||||||
import random
|
q = Q(value__icontains=self.name)
|
||||||
self.matches = random.randInt(0, 100)
|
for name in self.alternativeNames:
|
||||||
|
q = q|Q(value__icontains=name)
|
||||||
|
self.matches = Annotation.objects.filter(q).count()
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
|
|
Loading…
Reference in a new issue