tune files

This commit is contained in:
j 2011-08-26 16:32:00 +02:00
parent a373d423eb
commit fde89554cc
3 changed files with 13 additions and 6 deletions

View file

@ -84,7 +84,9 @@ class File(models.Model):
self.folder = self.get_folder() self.folder = self.get_folder()
self.sort_name = utils.sort_string(canonicalTitle(self.name)) 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'): for key in ('duration', 'size'):
setattr(self, key, self.info.get(key, 0)) 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) self.pixels = int(self.width * self.height * float(utils.parse_decimal(self.framerate)) * self.duration)
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', '.webm')
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', '.oga')
self.is_subtitle = os.path.splitext(self.name)[-1] in ('.srt', ) 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_subtitle = True
self.is_audio = False
self.is_video = False
else: else:
self.is_subtitle = False self.is_subtitle = False

View file

@ -105,6 +105,7 @@ def update(request):
file__available=False, file__available=False,
file__wanted=True)] file__wanted=True)]
response['data']['file'] = [f.file.oshash for f in files.filter(file__is_subtitle=True, response['data']['file'] = [f.file.oshash for f in files.filter(file__is_subtitle=True,
file__available=False,
name__endswith='.srt')] name__endswith='.srt')]
return render_to_json_response(response) return render_to_json_response(response)
@ -149,6 +150,8 @@ def upload(request):
response = json_response(status=403, text='permissino denied') response = json_response(status=403, text='permissino denied')
if 'file' in request.FILES: if 'file' in request.FILES:
if not f.available: if not f.available:
if f.data:
f.data.delete()
f.data.save('data.raw', request.FILES['file']) f.data.save('data.raw', request.FILES['file'])
f.available = True f.available = True
f.save() f.save()

View file

@ -729,11 +729,11 @@ class Item(models.Model):
users = self.users_with_files() users = self.users_with_files()
if users.filter(is_superuser=True).count()>0: if users.filter(is_superuser=True).count()>0:
files = self.files.filter(instances__volume__user__is_superuser=True) 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() is_superuser=True).distinct()
elif users.filter(is_staff=True).count()>0: elif users.filter(is_staff=True).count()>0:
files = self.files.filter(instances__volume__user__is_staff=True) 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() is_staff=True).distinct()
else: else:
files = self.files.all() files = self.files.all()