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