forked from 0x2620/pandora
matches, subtitles, parts
This commit is contained in:
parent
c01bb87c13
commit
c2981681c1
5 changed files with 42 additions and 14 deletions
|
@ -7,6 +7,7 @@ import re
|
|||
import time
|
||||
|
||||
from django.db import models
|
||||
from django.db.models import Q
|
||||
from django.contrib.auth.models import User
|
||||
from django.conf import settings
|
||||
from django.db.models.signals import pre_delete
|
||||
|
@ -138,10 +139,12 @@ class File(models.Model):
|
|||
else:
|
||||
self.is_video = os.path.splitext(self.name)[-1] in ('.avi', '.mkv', '.dv', '.ogv', '.mpeg', '.mov')
|
||||
self.is_audio = os.path.splitext(self.name)[-1] in ('.mp3', '.wav', '.ogg', '.flac')
|
||||
self.is_subtitle= os.path.splitext(self.name)[-1] in ('.srt', '.sub', '.idx')
|
||||
self.is_subtitle = os.path.splitext(self.name)[-1] in ('.srt', )
|
||||
|
||||
if not self.is_audio and not self.is_video and self.name.endswith('.srt'):
|
||||
self.is_subtitle = True
|
||||
else:
|
||||
self.is_subtitle = False
|
||||
|
||||
self.type = self.get_type()
|
||||
self.language = self.get_language()
|
||||
|
@ -282,6 +285,15 @@ class File(models.Model):
|
|||
return data
|
||||
|
||||
def get_part(self):
|
||||
#FIXME: this breaks for sub/idx/srt
|
||||
if os.path.splitext(self.name)[-1] in ('.sub', '.idx', '.srt'):
|
||||
name = os.path.splitext(self.name)[0]
|
||||
if self.language:
|
||||
name = name[-(len(self.language)+1)]
|
||||
qs = self.item.files.filter(Q(is_video=True)|Q(is_audio=True),
|
||||
is_main=True, name__startswith=name)
|
||||
if qs.count()>0:
|
||||
return qs[0].part
|
||||
if not self.is_extra:
|
||||
files = list(self.item.files.filter(type=self.type, language=self.language,
|
||||
is_main=self.is_main).order_by('sort_name'))
|
||||
|
|
|
@ -52,10 +52,12 @@ def parseCondition(condition):
|
|||
'text': 'string',
|
||||
'year': 'string',
|
||||
'length': 'string',
|
||||
'list': 'list'
|
||||
'list': 'list',
|
||||
'layer': 'string'
|
||||
}.get(key_type, key_type)
|
||||
if k == 'list':
|
||||
key_type = 'list'
|
||||
|
||||
if key_type == "string":
|
||||
in_find=True
|
||||
value_key = 'find__value'
|
||||
|
|
|
@ -400,8 +400,8 @@ class Item(models.Model):
|
|||
save('trivia', ' '.join(self.get('trivia', [])))
|
||||
|
||||
#FIXME:
|
||||
qs = Annotation.objects.filter(layer__type='subtitle', item=self).order_by('start')
|
||||
save('dialog', '\n'.join([l.value for l in qs]))
|
||||
qs = Annotation.objects.filter(layer__name='subtitles', item=self).order_by('start')
|
||||
save('subtitles', '\n'.join([l.value for l in qs]))
|
||||
|
||||
def update_sort(self):
|
||||
try:
|
||||
|
|
|
@ -41,7 +41,16 @@ def load_subtitles(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'):
|
||||
language = ''
|
||||
languages = [f.language for f in item.files.filter(is_main=True, is_subtitle=True,
|
||||
available=True)]
|
||||
if languages:
|
||||
if 'en' in languages:
|
||||
language = 'en'
|
||||
else:
|
||||
language = languages[0]
|
||||
for f in item.files.filter(is_main=True, is_subtitle=True,
|
||||
available=True, language=language).order_by('part'):
|
||||
user = f.instances.all()[0].volume.user
|
||||
for data in f.srt(offset):
|
||||
annotation = models.Annotation(
|
||||
|
@ -54,5 +63,12 @@ def load_subtitles(itemId):
|
|||
)
|
||||
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
|
||||
.filter(is_main=True, available=True, part=f.part)
|
||||
if duration:
|
||||
duration = duration[0].duration
|
||||
else:
|
||||
models.Annotation.objects.filter(layer=layer,item=item).delete()
|
||||
break
|
||||
offset += duration
|
||||
item.update_find()
|
||||
|
||||
|
|
|
@ -70,16 +70,14 @@ class Place(models.Model):
|
|||
j[key] = getattr(self, key)
|
||||
return j
|
||||
|
||||
def update_matches(self):
|
||||
"""
|
||||
import random
|
||||
self.matches = random.randint(0, 100)
|
||||
"""
|
||||
q = Q(value__icontains=self.name)
|
||||
def get_matches(self):
|
||||
q = Q(value__icontains=" " + self.name)|Q(value__startswith=self.name)
|
||||
for name in self.alternativeNames:
|
||||
q = q|Q(value__icontains=name)
|
||||
self.matches = Annotation.objects.filter(q).count()
|
||||
q = q|Q(value__icontains=" " + name)|Q(value__startswith=name)
|
||||
return Annotation.objects.filter(q)
|
||||
|
||||
def update_matches(self):
|
||||
self.matches = self.get_matches().count()
|
||||
self.save()
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
|
|
Loading…
Reference in a new issue