merging changes

This commit is contained in:
rolux 2011-08-25 19:25:13 +00:00
commit 1096aefdd6
4 changed files with 27 additions and 16 deletions

View file

@ -84,7 +84,9 @@ class File(models.Model):
self.folder = self.get_folder()
self.sort_name = utils.sort_string(canonicalTitle(self.name))
if self.info:
if not os.path.splitext(self.name)[-1] in (
'.srt', '.rar', '.sub', '.idx', '.txt', '.jpg', '.png', '.nfo') \
and self.info:
for key in ('duration', 'size'):
setattr(self, key, self.info.get(key, 0))
@ -128,12 +130,14 @@ class File(models.Model):
self.pixels = int(self.width * self.height * float(utils.parse_decimal(self.framerate)) * self.duration)
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_video = os.path.splitext(self.name)[-1] in ('.avi', '.mkv', '.dv', '.ogv', '.mpeg', '.mov', '.webm')
self.is_audio = os.path.splitext(self.name)[-1] in ('.mp3', '.wav', '.ogg', '.flac', '.oga')
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 self.name.endswith('.srt'):
self.is_subtitle = True
self.is_audio = False
self.is_video = False
else:
self.is_subtitle = False
@ -147,7 +151,11 @@ class File(models.Model):
def save(self, *args, **kwargs):
if self.auto:
self.set_state()
self.available = self.streams.filter(source=None, available=True).count() > 0
if self.is_subtitle:
self.available = self.data and True or False
else:
self.available = not self.uploading and \
self.streams.filter(source=None, available=True).count() > 0
super(File, self).save(*args, **kwargs)
#upload and data handling

View file

@ -101,5 +101,5 @@ def process_stream(fileId):
stream = streams[0]
stream.make_timeline()
stream.extract_derivatives()
file.item.update_timeline()
file.item.update_selected()
return True

View file

@ -105,6 +105,7 @@ def update(request):
file__available=False,
file__wanted=True)]
response['data']['file'] = [f.file.oshash for f in files.filter(file__is_subtitle=True,
file__available=False,
name__endswith='.srt')]
return render_to_json_response(response)
@ -149,9 +150,11 @@ def upload(request):
response = json_response(status=403, text='permissino denied')
if 'file' in request.FILES:
if not f.available:
if f.data:
f.data.delete()
f.data.save('data.raw', request.FILES['file'])
f.available = True
f.save()
item.tasks.load_subtitles.delay(f.item.itemId)
response = json_response(text='file saved')
else:
response = json_response(status=403, text='permissino denied')
@ -188,7 +191,6 @@ def firefogg_upload(request):
if not f.save_chunk(c, chunk_id, form.cleaned_data['done']):
response['result'] = -1
elif form.cleaned_data['done']:
f.available = True
f.uploading = False
f.save()
#FIXME: this fails badly if rabbitmq goes down
@ -206,7 +208,6 @@ def firefogg_upload(request):
f = get_object_or_404(models.File, oshash=oshash)
if f.editable(request.user):
f.streams.all().delete()
f.available = False
f.uploading = True
f.save()
response = {

View file

@ -515,6 +515,7 @@ class Item(models.Model):
#FIXME:
qs = Annotation.objects.filter(layer__name='subtitles', item=self).order_by('start')
save('subtitles', '\n'.join([l.value for l in qs]))
save('filename', '\n'.join([u'%s/%s' % (f.folder, f.name) for f in self.files.all()]))
def update_sort(self):
try:
@ -660,7 +661,10 @@ class Item(models.Model):
for key in self.facet_keys + ['title']:
current_values = self.get(key, [])
if key == 'title':
current_values = [current_values]
if current_values:
current_values = [current_values]
else:
current_values = []
ot = self.get('original_title')
if ot:
current_values.append(ot)
@ -729,11 +733,11 @@ class Item(models.Model):
users = self.users_with_files()
if users.filter(is_superuser=True).count()>0:
files = self.files.filter(instances__volume__user__is_superuser=True)
users = User.objects.filter(volumes__files__file__item__in=files,
users = User.objects.filter(volumes__files__file__in=files,
is_superuser=True).distinct()
elif users.filter(is_staff=True).count()>0:
files = self.files.filter(instances__volume__user__is_staff=True)
users = User.objects.filter(volumes__files__file__item__in=files,
users = User.objects.filter(volumes__files__file__in=files,
is_staff=True).distinct()
else:
files = self.files.all()
@ -916,8 +920,7 @@ class Item(models.Model):
poster = os.path.abspath(os.path.join(settings.MEDIA_ROOT, poster))
frame = self.get_poster_frame_path()
timeline = self.path('timeline.64.png')
timeline = os.path.abspath(os.path.join(settings.MEDIA_ROOT, timeline))
timeline = '%s.64.png' % self.timeline_prefix
director = u', '.join(self.get('director', ['Unknown Director']))
cmd = [settings.ITEM_POSTER,
@ -985,8 +988,7 @@ class Item(models.Model):
frame = self.get_poster_frame_path()
icon = self.path('icon.jpg')
self.icon.name = icon
timeline = self.path('timeline.64.png')
timeline = os.path.abspath(os.path.join(settings.MEDIA_ROOT, timeline))
timeline = '%s.64.png' % self.timeline_prefix
cmd = [settings.ITEM_ICON,
'-i', self.icon.path
]