reload stream from db before updating after encode, fixes #2442

This commit is contained in:
j 2014-07-29 17:43:38 +02:00
parent a520b7edaf
commit cfa7628551

View file

@ -624,6 +624,9 @@ class Stream(models.Model):
return stream return stream
def path(self, name=''): def path(self, name=''):
if self.source:
return os.path.join(os.path.dirname(self.source.media.name), name)
else:
return self.file.get_path(name) return self.file.get_path(name)
def extract_derivatives(self, rebuild=False): def extract_derivatives(self, rebuild=False):
@ -649,37 +652,26 @@ class Stream(models.Model):
return True return True
def encode(self): def encode(self):
if self.source: media = self.source.media.path if self.source else self.file.data
media = self.source.media.path ffmpeg = ox.file.cmd('ffmpeg')
if not self.media: if self.source or ffmpeg == 'ffmpeg':
self.media.name = os.path.join(os.path.dirname(self.source.media.name), self.name()) ffmpeg = None
target = self.media.path
info = ox.avinfo(media)
ok, error = extract.stream(media, target, self.name(), info)
if ok:
self.available = True
self.error = ''
if self.file.failed:
self.file.failed = False
self.file.save()
else:
self.media = None
self.available = False
self.error = error
self.file.failed = True
self.file.save()
self.save()
elif self.file.data:
media = self.file.data.path
if not self.media: if not self.media:
self.media.name = self.path(self.name()) self.media.name = self.path(self.name())
target = self.media.path target = self.media.path
info = ox.avinfo(media) info = ox.avinfo(media)
ffmpeg = ox.file.cmd('ffmpeg')
if ffmpeg == 'ffmpeg':
ffmpeg = None
ok, error = extract.stream(media, target, self.name(), info, ffmpeg) ok, error = extract.stream(media, target, self.name(), info, ffmpeg)
# file could have been moved while encoding
# get current version from db and update
_self = Stream.objects.get(id=self.id)
_self.update_status(ok, error)
def update_status(self, ok, error):
if ok: if ok:
if not self.media:
self.media.name = self.path(self.name())
self.available = True self.available = True
self.error = '' self.error = ''
if self.file.failed: if self.file.failed: