This commit is contained in:
j 2016-07-01 17:41:53 +02:00
parent 3166bf5beb
commit d780045306
6 changed files with 72 additions and 70 deletions

View file

@ -23,7 +23,7 @@ def save_chunk(obj, file, chunk, offset, name, done_cb=None):
else:
path = file.path
size = file.size
if offset == None:
if offset is None:
offset = size
elif offset > size:
return False, size

View file

@ -24,7 +24,8 @@ from person.models import get_name_sort
from chunk import save_chunk
import extract
def data_path(f, x): return f.get_path('data.bin')
def data_path(f, x):
return f.get_path('data.bin')
class File(models.Model):
AV_INFO = (
@ -161,11 +162,11 @@ class File(models.Model):
data['isEpisode'] = True
data['directorSort'] = [get_name_sort(n) for n in self.item.get('director', [])]
data['isEpisode'] = 'isEpisode' in data \
or data.get('season') != None \
or data.get('episode') != None \
or data.get('season') is not None \
or data.get('episode') is not None \
or data.get('episodes') not in ([], None) \
or (data.get('seriesTitle') != None and data.get('episodeTitle') != None)
if data['isEpisode'] and data['seriesYear'] == None:
or (data.get('seriesTitle') is not None and data.get('episodeTitle') is not None)
if data['isEpisode'] and data['seriesYear'] is None:
data['seriesYear'] = data['year']
data['type'] = 'unknown'
if 'extension' in data and data['extension']:
@ -193,6 +194,7 @@ class File(models.Model):
files = []
volume = self.instances.all()[0].volume
def add_file(f):
instance = f.instances.all()[0]
files.append(f.get_path_info())
@ -268,7 +270,7 @@ class File(models.Model):
self.available = self.data and True or False
else:
self.available = not self.uploading and \
self.streams.filter(source=None, available=True).count() > 0
self.streams.filter(source=None, available=True).count()
super(File, self).save(*args, **kwargs)
if update_path:
self.path = self.normalize_path()
@ -279,7 +281,7 @@ class File(models.Model):
return os.path.join('media', h[:2], h[2:4], h[4:6], h[6:], name)
def contents(self):
if self.data != None:
if self.data is not None:
self.data.seek(0)
return self.data.read()
return None
@ -335,8 +337,7 @@ class File(models.Model):
def save_chunk_stream(self, chunk, offset, resolution, format, done):
if not self.available:
stream, created = Stream.objects.get_or_create(
file=self, resolution=resolution, format=format)
stream, created = Stream.objects.get_or_create(file=self, resolution=resolution, format=format)
name = stream.path(stream.name())
def done_cb():
@ -436,7 +437,7 @@ class File(models.Model):
extract.frame_direct(filename, fr.frame.path, pos)
if os.path.exists(fr.frame.path):
fr.save()
os.chmod(fr.frame.path, 0644)
os.chmod(fr.frame.path, 0o644)
self.item.select_frame()
def extract_stream(self):
@ -636,8 +637,8 @@ def delete_frame(sender, **kwargs):
f.frame.delete(save=False)
pre_delete.connect(delete_frame, sender=Frame)
def stream_path(f, x): return f.path(x)
def stream_path(f, x):
return f.path(x)
class Stream(models.Model):
@ -696,7 +697,8 @@ class Stream(models.Model):
if resolution <= self.resolution:
for f in config['formats']:
derivative, created = Stream.objects.get_or_create(file=self.file,
resolution=resolution, format=f)
resolution=resolution,
format=f)
if created:
derivative.source = self
derivative.save()

View file

@ -31,7 +31,7 @@ def get_or_create_file(volume, f, user, item=None):
def update_or_create_instance(volume, f):
# instance with oshash exists
instance = models.Instance.objects.filter(file__oshash=f['oshash'], volume=volume)
if instance.count()>0:
if instance.count():
instance = instance[0]
updated = False
for key in _INSTANCE_KEYS:
@ -44,7 +44,7 @@ def update_or_create_instance(volume, f):
instance.file.save()
else:
instance = models.Instance.objects.filter(path=f['path'], volume=volume)
if instance.count()>0:
if instance.count():
# same path, other oshash, keep path/item mapping, remove instance
item = instance[0].file.item
instance.delete()
@ -144,7 +144,7 @@ def extract_stream(fileId):
def extract_derivatives(fileId, rebuild=False):
file = models.File.objects.get(id=fileId)
streams = file.streams.filter(source=None)
if streams.count() > 0:
if streams.count():
streams[0].extract_derivatives(rebuild)
return True

View file

@ -141,7 +141,7 @@ def upload(request, data=None):
if fr.frame:
fr.frame.delete()
fr.frame.save(name, frame)
os.chmod(fr.frame.path, 0644)
os.chmod(fr.frame.path, 0o644)
fr.save()
f.item.select_frame()
f.item.save()
@ -152,7 +152,7 @@ def upload(request, data=None):
f.data.delete()
f.data.save('data.raw', request.FILES['file'])
f.save()
os.chmod(f.data.path, 0644)
os.chmod(f.data.path, 0o644)
item.tasks.load_subtitles.delay(f.item.public_id)
response = json_response(text='file saved')
else: