Skip to content

Commit

Permalink
Merge 2e6a15d into 50d228d
Browse files Browse the repository at this point in the history
  • Loading branch information
lifenautjoe committed Sep 11, 2019
2 parents 50d228d + 2e6a15d commit 66f5b1d
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions video_encoding/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,23 @@ def _get_width(self):
Returns video width in pixels.
"""
return self._get_video_info().get('width', 0)

width = property(_get_width)

def _get_height(self):
"""
Returns video height in pixels.
"""
return self._get_video_info().get('height', 0)

height = property(_get_height)

def _get_duration(self):
"""
Returns duration in seconds.
"""
return self._get_video_info().get('duration', 0)

duration = property(_get_duration)

def _get_video_info(self):
Expand All @@ -38,9 +41,33 @@ 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)

if hasattr(self, 'file'):
# Its an actual file
try:
path = os.path.abspath(self.path)
except AttributeError:
path = os.path.abspath(self.name)

info_cache = encoding_backend.get_media_info(path)
else:
# Its not an actual file, so assume storage abstraction
storage_path = getattr(self, 'path', self.name)
if not hasattr(self, 'storage'):
raise Exception(
'VideoFile uses storages yet has no self.storage'
)

storage = self.storage

try:
# If its a storage with file system implementation
storage_local_path = storage.path(storage_path)
except NotImplementedError:
storage_local_path = storage.url(storage_path)

info_cache = encoding_backend.get_media_info(storage_local_path)

self._info_cache = info_cache

return self._info_cache

0 comments on commit 66f5b1d

Please sign in to comment.