From 2c28bcc6a9046ba7cef0c0f7ca5a6e234d0c5b1c Mon Sep 17 00:00:00 2001 From: Basil Shubin Date: Sat, 18 May 2019 20:36:43 +0700 Subject: [PATCH] fix #13 --- video_encoding/files.py | 17 +++++++++++++---- video_encoding/tasks.py | 7 +++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/video_encoding/files.py b/video_encoding/files.py index 4912c40..5051f61 100644 --- a/video_encoding/files.py +++ b/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): @@ -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 diff --git a/video_encoding/tasks.py b/video_encoding/tasks.py index 1c95d2c..f342799 100644 --- a/video_encoding/tasks.py +++ b/video_encoding/tasks.py @@ -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()