Skip to content

Commit

Permalink
Refactor: configurable file extensions
Browse files Browse the repository at this point in the history
This change enables people to configure what file extensions should be
recognised as images and videos by setting:

`img_extensions` and `video_extensions`
  • Loading branch information
matelakat committed Nov 6, 2017
1 parent da91ae7 commit 1d6d44f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ alphabetical order):
- Keith Johnson
- Lukas Vacek
- Luke Cyca (@lukecyca)
- Mate Lakat
- Matthias Vogelgesang
- Miroslav Pavleski
- Nicolas Arnaud-Cormos
Expand Down
10 changes: 4 additions & 6 deletions sigal/gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Copyright (c) 2013 - Christophe-Marie Duquesne
# Copyright (c) 2014 - Jonas Kaufmann
# Copyright (c) 2015 - François D.
# Copyright (c) 2017 - Mate Lakat

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
Expand Down Expand Up @@ -66,7 +67,6 @@ class Media(UnicodeMixin):
"""

type = ''
extensions = ()

def __init__(self, filename, path, settings):
self.src_filename = self.filename = self.url = filename
Expand Down Expand Up @@ -152,7 +152,6 @@ class Image(Media):
"""Gather all informations on an image file."""

type = 'image'
extensions = ('.jpg', '.jpeg', '.png', '.gif')

@cached_property
def date(self):
Expand Down Expand Up @@ -188,7 +187,6 @@ class Video(Media):
"""Gather all informations on a video file."""

type = 'video'
extensions = ('.mov', '.avi', '.mp4', '.webm', '.ogv', '.3gp')

def __init__(self, filename, path, settings):
super(Video, self).__init__(filename, path, settings)
Expand Down Expand Up @@ -256,9 +254,9 @@ def __init__(self, path, settings, dirnames, filenames, gallery):

for f in filenames:
ext = splitext(f)[1]
if ext.lower() in Image.extensions:
if ext.lower() in settings['img_extensions']:
media = Image(f, self.path, settings)
elif ext.lower() in Video.extensions:
elif ext.lower() in settings['video_extensions']:
media = Video(f, self.path, settings)
else:
continue
Expand Down Expand Up @@ -401,7 +399,7 @@ def thumbnail(self):
# find and return the first landscape image
for f in self.medias:
ext = splitext(f.filename)[1]
if ext.lower() in Image.extensions:
if ext.lower() in self.settings['img_extensions']:
# Use f.size if available as it is quicker (in cache), but
# fallback to the size of src_path if dst_path is missing
size = f.size
Expand Down
6 changes: 4 additions & 2 deletions sigal/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Copyright (c) 2009-2016 - Simon Conseil
# Copyright (c) 2013 - Christophe-Marie Duquesne
# Copyright (c) 2017 - Mate Lakat

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
Expand Down Expand Up @@ -42,6 +43,7 @@
'google_tag_manager': '',
'ignore_directories': [],
'ignore_files': [],
'img_extensions': ['.jpg', '.jpeg', '.png', '.gif'],
'img_processor': 'ResizeToFit',
'img_size': (640, 480),
'index_in_url': False,
Expand Down Expand Up @@ -74,6 +76,7 @@
'title': '',
'use_assets_cdn': True,
'use_orig': False,
'video_extensions': ['.mov', '.avi', '.mp4', '.webm', '.ogv', '.3gp'],
'video_format': 'webm',
'video_size': (480, 360),
'watermark': '',
Expand Down Expand Up @@ -108,8 +111,7 @@ def get_thumb(settings, filename):
path, filen = os.path.split(filename)
name, ext = os.path.splitext(filen)

# FIXME: replace this list with Video.extensions
if ext.lower() in ('.mov', '.avi', '.mp4', '.webm', '.ogv', '.3gp'):
if ext.lower() in settings['video_extensions']:
ext = '.jpg'
return join(path, settings['thumb_dir'], settings['thumb_prefix'] +
name + settings['thumb_suffix'] + ext)
Expand Down
6 changes: 6 additions & 0 deletions sigal/templates/sigal.conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
# show_map = False
# leaflet_provider = 'OpenStreetMap.Mapnik'

# File extensions that should be treated as images
# img_extensions = ['.jpg', '.jpeg', '.png', '.gif'],

# Pilkit processor used to resize the image
# (see http://pilkit.readthedocs.org/en/latest/#processors)
# - ResizeToFit: fit the image within the specified dimensions (default)
Expand Down Expand Up @@ -136,6 +139,9 @@
# Video options
# -------------

# File extensions that should be treated as video files
# video_extensions = ['.mov', '.avi', '.mp4', '.webm', '.ogv', '.3gp']

# Video format
# specify an alternative format, valid are 'webm' (default) and 'mp4'
# video_format = 'webm'
Expand Down

0 comments on commit 1d6d44f

Please sign in to comment.