Permalink
Browse files

get_poster_url working.

moved new width & height definition out of the loop in convert
Fixed some pep8 nonconformances.
  • Loading branch information...
1 parent deb400e commit 1ed67d4a78b777d44d8e6617af2057d6265991d7 @nmfm committed Oct 26, 2011
Showing with 20 additions and 20 deletions.
  1. +4 −5 filer/fields/multistorage_file.py
  2. +16 −15 filer/models/videomodels.py
View
9 filer/fields/multistorage_file.py
@@ -21,6 +21,7 @@
'private': filer_settings.FILER_PRIVATEMEDIA_FORMATS_STORAGE,
}
+
def generate_filename_multistorage(instance, filename):
if instance.is_public:
upload_to = filer_settings.FILER_PUBLICMEDIA_UPLOAD_TO
@@ -48,10 +49,9 @@ def get_format_url(self, ext):
raise NameError
def get_poster_url(self):
- original_path = self.formats_storage.path(self.name)
- original_path, filename = os.path.split(original_path)
+ original_path, filename = os.path.split(self.name)
basename = os.path.splitext(filename)[0]
- return os.path.join(original_path, basename + '.png')
+ return self.format_storage.url(os.path.join(original_path, basename + '.png'))
class MultiStorageFieldFile(ThumbnailerNameMixin,
@@ -87,7 +87,6 @@ def thumbnail_storage(self):
else:
return self.thumbnail_storages['private']
-
@property
def format_storage(self):
if self.instance.is_public:
@@ -98,7 +97,7 @@ def format_storage(self):
def get_format(self, options, save=True):
#wtf is opaque vs transparent???
pass
-
+
class MultiStorageFileField(easy_thumbnails_fields.ThumbnailerField):
attr_class = MultiStorageFieldFile
View
31 filer/models/videomodels.py
@@ -6,13 +6,15 @@
from filer.models.filemodels import File
from filer.utils.video import convert_video, grab_poster, get_dimensions
+
VIDEO_STATUS_TYPE = (
- ('new',_('New')),
- ('process',_('Being precessed')),
+ ('new', _('New')),
+ ('process', _('Being precessed')),
('ok', _('Converted successfully')),
('error', _('Conversion failed')),
)
+
class Video(File):
file_type = 'Video'
_icon = "video"
@@ -41,15 +43,15 @@ class Meta:
app_label = 'filer'
verbose_name = _('video')
verbose_name_plural = _('videos')
-
+
@classmethod
def matches_file_type(cls, iname, ifile, request):
- iext = os.path.splitext(iname)[1].lower().lstrip('.')
- return iext in filer_settings.FILER_SOURCE_VIDEO_FORMATS
+ iext = os.path.splitext(iname)[1].lower().lstrip('.')
+ return iext in filer_settings.FILER_SOURCE_VIDEO_FORMATS
def set_initial_dimensions(self):
sourcefile = self.file.storage.path(self.file.name)
- x,y = get_dimensions(sourcefile)
+ x, y = get_dimensions(sourcefile)
self.original_width = x
self.original_height = y
self.width = x
@@ -86,16 +88,16 @@ def poster(self):
def convert(self):
original_path = self.file.storage.path(self.file.name)
path = os.path.split(self.file.format_storage.path(self.file.name))[0]
- # loop in all
+ # loop in all
full_res = True
- full_out = ''
+ full_out = ''
+ #only set new dimensions if diferent from the original and not zero
+ if self.width and self.height and (
+ self.width != self.original_width or self.height != self.original_height):
+ new_dimensions = "%sx%s" % (self.width, self.height)
+ else:
+ new_dimensions = ""
for extension in filer_settings.FILER_VIDEO_FORMATS:
- #only set new dimensions if diferent from the original and not zero
- if self.width and self.height and (
- self.width != self.original_width or self.height != self.original_height):
- new_dimensions = "%sx%s" % (self.width, self.height)
- else:
- new_dimensions = ""
res, out = convert_video(original_path, path, extension, new_dimensions)
res = res or full_res
full_out += out
@@ -108,4 +110,3 @@ def convert(self):
#def get_video_flv_url(self):
#return self.file.formats_storage.url(self.flv())
-

0 comments on commit 1ed67d4

Please sign in to comment.