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: else:
path = file.path path = file.path
size = file.size size = file.size
if offset == None: if offset is None:
offset = size offset = size
elif offset > size: elif offset > size:
return False, size return False, size

View file

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

View file

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