Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
bashu committed May 18, 2019
1 parent 50d228d commit 2c28bcc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
17 changes: 13 additions & 4 deletions video_encoding/files.py
@@ -1,8 +1,10 @@
import os

from django.core.files import File
from django.core.files.storage import default_storage

from .backends import get_backend
from .exceptions import FFmpegError


class VideoFile(File):
Expand Down Expand Up @@ -39,8 +41,15 @@ def _get_video_info(self):
if not hasattr(self, '_info_cache'):
encoding_backend = get_backend()
try:
path = os.path.abspath(self.path)
except AttributeError:
path = os.path.abspath(self.name)
self._info_cache = encoding_backend.get_media_info(path)
_path = getattr(self, 'path', self.name)
except NotImplementedError:
_path = self.name
try:
path = default_storage.path(_path)
except NotImplementedError:
path = default_storage.url(_path)
try:
self._info_cache = encoding_backend.get_media_info(path)
except FFmpegError:
self._info_cache = {}
return self._info_cache
7 changes: 5 additions & 2 deletions video_encoding/tasks.py
Expand Up @@ -40,8 +40,11 @@ def convert_video(fieldfile, force=False):
instance = fieldfile.instance
field = fieldfile.field

filename = os.path.basename(fieldfile.path)
source_path = fieldfile.path
try:
source_path = fieldfile.path
except NotImplementedError:
source_path = fieldfile.url
filename = os.path.basename(source_path)

encoding_backend = get_backend()

Expand Down

0 comments on commit 2c28bcc

Please sign in to comment.