merge img and vid into media and update themes
This commit is contained in:
@@ -5,7 +5,7 @@ python:
|
||||
before_install:
|
||||
# Dependencies to build PIL
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install -qq libfreetype6-dev libjpeg8-dev zlib1g-dev
|
||||
- sudo apt-get install -qq libfreetype6-dev libjpeg8-dev zlib1g-dev ffmpeg
|
||||
install:
|
||||
- pip install pytest --use-mirrors
|
||||
- pip install . --use-mirrors
|
||||
|
||||
@@ -5,3 +5,4 @@ Markdown
|
||||
Pillow
|
||||
pilkit
|
||||
pytest
|
||||
ffmpeg
|
||||
|
||||
@@ -41,6 +41,9 @@ from .writer import Writer
|
||||
|
||||
DESCRIPTION_FILE = "index.md"
|
||||
|
||||
class FileExtensionError(Exception):
|
||||
"""Raised if we made an error when handling file extensions"""
|
||||
pass
|
||||
|
||||
class PathsDb(object):
|
||||
"""Container for all the information on the directory structure.
|
||||
@@ -94,20 +97,16 @@ class PathsDb(object):
|
||||
|
||||
self.db['paths_list'].append(relpath)
|
||||
self.db[relpath] = {
|
||||
'img': [f for f in filenames
|
||||
if os.path.splitext(f)[1] in self.img_ext_list],
|
||||
'vid': [f for f in filenames
|
||||
if os.path.splitext(f)[1] in self.vid_ext_list],
|
||||
'medias': [ f for f in filenames if os.path.splitext(f)[1]
|
||||
in (self.img_ext_list + self.vid_ext_list) ],
|
||||
'subdir': dirnames
|
||||
}
|
||||
self.db[relpath].update(get_metadata(path))
|
||||
|
||||
path_media = [path for path in self.db['paths_list']
|
||||
if (self.db[path]['img'] or self.db[path]['vid'])
|
||||
and path != '.']
|
||||
if self.db[path]['medias'] and path != '.']
|
||||
path_nomedia = [path for path in self.db['paths_list']
|
||||
if not (self.db[path]['img'] or self.db[path]['vid'])
|
||||
and path !='.']
|
||||
if not self.db[path]['medias'] and path !='.']
|
||||
|
||||
# dir with images: check the thumbnail, and find it if necessary
|
||||
for path in path_media:
|
||||
@@ -142,20 +141,17 @@ class PathsDb(object):
|
||||
return
|
||||
|
||||
# find and return the first landscape image
|
||||
for f in self.db[path]['img']:
|
||||
im = PILImage.open(join(self.basepath, path, f))
|
||||
if im.size[0] > im.size[1]:
|
||||
self.db[path]['thumbnail'] = f
|
||||
return
|
||||
for f in self.db[path]['medias']:
|
||||
base, ext = os.path.splitext(f)
|
||||
if ext in self.img_ext_list:
|
||||
im = PILImage.open(join(self.basepath, path, f))
|
||||
if im.size[0] > im.size[1]:
|
||||
self.db[path]['thumbnail'] = f
|
||||
return
|
||||
|
||||
# else try returning the 1st image
|
||||
if self.db[path]['img']:
|
||||
self.db[path]['thumbnail'] = self.db[path]['img'][0]
|
||||
return
|
||||
|
||||
# last, we try the first vid
|
||||
if self.db[path]['vid']:
|
||||
self.db[path]['thumbnail'] = self.db[path]['vid'][0]
|
||||
# else simply return the 1st media file
|
||||
if self.db[path]['medias']:
|
||||
self.db[path]['thumbnail'] = self.db[path]['medias'][0]
|
||||
return
|
||||
|
||||
self.db[path]['thumbnail'] = ''
|
||||
@@ -192,24 +188,22 @@ class Gallery(object):
|
||||
# loop on directories in reversed order, to process subdirectories
|
||||
# before their parent
|
||||
for path in reversed(self.db['paths_list']):
|
||||
imglist = [os.path.normpath(join(self.settings['source'], path, f))
|
||||
for f in self.db[path]['img']]
|
||||
vidlist = [os.path.normpath(join(self.settings['source'], path, f))
|
||||
for f in self.db[path]['vid']]
|
||||
media_files = [os.path.normpath(join(self.settings['source'], path, f))
|
||||
for f in self.db[path]['medias']]
|
||||
|
||||
# output dir for the current path
|
||||
outpath = os.path.normpath(join(self.settings['destination'],
|
||||
path))
|
||||
check_or_create_dir(outpath)
|
||||
|
||||
if len(imglist) != 0 or len(vidlist) != 0:
|
||||
self.process_dir(imglist, vidlist, outpath, path,
|
||||
label_width=label_width)
|
||||
if len(media_files) != 0:
|
||||
self.process_dir(media_files, outpath, path,
|
||||
label_width=label_width)
|
||||
|
||||
if self.settings['write_html']:
|
||||
self.writer.write(self.db, path)
|
||||
|
||||
def process_dir(self, imglist, vidlist, outpath, dirname, label_width=20):
|
||||
def process_dir(self, media_files, outpath, dirname, label_width=20):
|
||||
"""Process a list of images in a directory."""
|
||||
|
||||
# Create thumbnails directory and optionally the one for original img
|
||||
@@ -218,8 +212,6 @@ class Gallery(object):
|
||||
if self.settings['keep_orig']:
|
||||
check_or_create_dir(join(outpath, self.settings['orig_dir']))
|
||||
|
||||
media_files = imglist + vidlist
|
||||
|
||||
# use progressbar if level is > INFO
|
||||
if self.logger.getEffectiveLevel() > 20:
|
||||
label = colored.green(dirname.ljust(label_width))
|
||||
@@ -235,19 +227,24 @@ class Gallery(object):
|
||||
# loop on images
|
||||
for f in media_iterator:
|
||||
filename = os.path.split(f)[1]
|
||||
if f in imglist:
|
||||
base, ext = os.path.splitext(filename)
|
||||
if ext in self.settings['img_ext_list']:
|
||||
outname = join(outpath, filename)
|
||||
elif ext in self.settings['vid_ext_list']:
|
||||
outname = join(outpath, base + '.webm')
|
||||
else:
|
||||
outname = join(outpath, os.path.splitext(filename)[0] + '.webm')
|
||||
raise FileExtensionError
|
||||
|
||||
if os.path.isfile(outname) and not self.force:
|
||||
self.logger.info("%s exists - skipping", filename)
|
||||
else:
|
||||
self.logger.info(filename)
|
||||
if f in imglist:
|
||||
if ext in self.settings['img_ext_list']:
|
||||
process_image(f, outpath, self.settings)
|
||||
else:
|
||||
elif ext in self.settings['vid_ext_list']:
|
||||
process_video(f, outpath, self.settings)
|
||||
else:
|
||||
raise FileExtensionError
|
||||
|
||||
except KeyboardInterrupt:
|
||||
sys.exit('Interrupted')
|
||||
|
||||
@@ -67,36 +67,38 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if images or videos %}
|
||||
{% if medias %}
|
||||
<div id="gallery" class="row">
|
||||
{% for image in images %}
|
||||
<div class="four columns thumbnail
|
||||
{% if loop.index % 3 == 1 %}alpha{% endif%}
|
||||
{% if loop.index % 3 == 0 %}omega{% endif%}">
|
||||
<a href="{{ image.file }}" class="gallery" title="{{ image.file }}"
|
||||
{% if image.big %} data-big="{{ image.big }}"{% endif %}>
|
||||
<img src="{{ image.thumb }}" alt="{{ image.file }}"
|
||||
title="{{ image.file }}" /></a>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% for video in videos %}
|
||||
<div class="four columns thumbnail
|
||||
{% if loop.index % 3 == 1 %}alpha{% endif%}
|
||||
{% if loop.index % 3 == 0 %}omega{% endif%}">
|
||||
<a href="#{{ video.file|replace('.', '') }}" class="gallery"
|
||||
inline='yes' title="{{ video.file }}"
|
||||
{% if video.big %} data-big="{{ video.big }}"{% endif %}>
|
||||
<img src="{{ video.thumb }}" alt="{{ video.file }}"
|
||||
title="{{ video.file }}" /></a>
|
||||
</div>
|
||||
<!-- This contains the hidden content for inline calls -->
|
||||
<div style='display:none'>
|
||||
<div id="{{ video.file|replace('.', '') }}">
|
||||
<video controls>
|
||||
<source src='{{ video.file }}' type='video/webm' />
|
||||
</video>
|
||||
{% for media in medias %}
|
||||
{% if media.type == "img" %}
|
||||
<div class="four columns thumbnail
|
||||
{% if loop.index % 3 == 1 %}alpha{% endif%}
|
||||
{% if loop.index % 3 == 0 %}omega{% endif%}">
|
||||
<a href="{{ media.file }}" class="gallery" title="{{ media.file }}"
|
||||
{% if media.big %} data-big="{{ media.big }}"{% endif %}>
|
||||
<img src="{{ media.thumb }}" alt="{{ media.file }}"
|
||||
title="{{ media.file }}" /></a>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if media.type == "vid" %}
|
||||
<div class="four columns thumbnail
|
||||
{% if loop.index % 3 == 1 %}alpha{% endif%}
|
||||
{% if loop.index % 3 == 0 %}omega{% endif%}">
|
||||
<a href="#{{ media.file|replace('.', '') }}" class="gallery"
|
||||
inline='yes' title="{{ media.file }}"
|
||||
{% if media.big %} data-big="{{ media.big }}"{% endif %}>
|
||||
<img src="{{ media.thumb }}" alt="{{ media.file }}"
|
||||
title="{{ media.file }}" /></a>
|
||||
</div>
|
||||
<!-- This contains the hidden content for the video -->
|
||||
<div style='display:none'>
|
||||
<div id="{{ media.file|replace('.', '') }}">
|
||||
<video controls>
|
||||
<source src='{{ media.file }}' type='video/webm' />
|
||||
</video>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
@@ -109,7 +111,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if images or videos %}
|
||||
{% if medias %}
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
|
||||
<script>!window.jQuery && document.write(unescape('%3Cscript src="{{ theme.url }}/js/jquery-1.10.2.min.js"%3E%3C/script%3E'))</script>
|
||||
<script src="{{ theme.url }}/js/jquery.colorbox.min.js"></script>
|
||||
|
||||
@@ -57,26 +57,28 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if images or videos %}
|
||||
{% if medias %}
|
||||
<div id="gallery">
|
||||
{% for image in images %}
|
||||
<a href="{{ image.file }}">
|
||||
<img src="{{ image.thumb }}" alt="{{ image.file }}"
|
||||
data-title="{{ image.file }}"
|
||||
{%- if image.big %} data-description="<a href='{{ image.big }}'>Full size</a>"{% endif %}/>
|
||||
</a>
|
||||
{% endfor %}
|
||||
{% for video in videos %}
|
||||
<a href="{{ theme.url }}/img/empty.png">
|
||||
<img src="{{ video.thumb }}" alt="{{ video.file }}"
|
||||
{# TODO: stop using inline css, put this in the main css file #}
|
||||
data-layer="<video style='position:absolute;
|
||||
top:10%;
|
||||
width:100%;
|
||||
margin=0 auto;' controls>
|
||||
<source src={{ video.file }} type='video/webm' />
|
||||
</video>" />
|
||||
</a>
|
||||
{% for media in medias %}
|
||||
{% if media.type == "img" %}
|
||||
<a href="{{ media.file }}">
|
||||
<img src="{{ media.thumb }}" alt="{{ media.file }}"
|
||||
data-title="{{ media.file }}"
|
||||
{%- if image.big %} data-description="<a href='{{ media.big }}'>Full size</a>"{% endif %}/>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if media.type == "vid" %}
|
||||
<a href="{{ theme.url }}/img/empty.png">
|
||||
<img src="{{ media.thumb }}" alt="{{ media.file }}"
|
||||
{# TODO: stop using inline css, put this in the main css file #}
|
||||
data-layer="<video style='position:absolute;
|
||||
top:10%;
|
||||
width:100%;
|
||||
margin=0 auto;' controls>
|
||||
<source src={{ media.file }} type='video/webm' />
|
||||
</video>" />
|
||||
</a>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
@@ -94,7 +96,7 @@
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
{% if images or videos %}
|
||||
{% if medias %}
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
|
||||
<script>!window.jQuery && document.write(unescape('%3Cscript src="{{ theme.url }}/js/jquery-1.8.2.min.js"%3E%3C/script%3E'))</script>
|
||||
<script src="{{ theme.url }}/js/galleria-1.2.9.min.js"></script>
|
||||
|
||||
@@ -90,8 +90,7 @@ class Writer(object):
|
||||
self.ctx = {
|
||||
'sigal_link': sigal_link,
|
||||
'theme': {'name': os.path.basename(self.theme)},
|
||||
'images': [],
|
||||
'videos': [],
|
||||
'medias': [],
|
||||
'albums': [],
|
||||
'breadcumb': ''
|
||||
}
|
||||
@@ -136,20 +135,19 @@ class Writer(object):
|
||||
if relpath != '.':
|
||||
ctx['breadcumb'] = self.get_breadcumb(paths, relpath)
|
||||
|
||||
for i in paths[relpath]['img']:
|
||||
img_ctx = {'file': i,
|
||||
'thumb': get_thumb(self.settings, i)}
|
||||
if self.settings['keep_orig']:
|
||||
img_ctx['big'] = get_orig(self.settings, i)
|
||||
ctx['images'].append(img_ctx)
|
||||
|
||||
for i in paths[relpath]['vid']:
|
||||
for i in paths[relpath]['medias']:
|
||||
media_ctx = {}
|
||||
base, ext = os.path.splitext(i)
|
||||
vid_ctx = {'file': base + '.webm',
|
||||
'thumb': get_thumb(self.settings, i)}
|
||||
if ext in self.settings['img_ext_list']:
|
||||
media_ctx['type'] = 'img'
|
||||
media_ctx['file'] = i
|
||||
else:
|
||||
media_ctx['type'] = 'vid'
|
||||
media_ctx['file'] = base + '.webm'
|
||||
media_ctx['thumb'] = get_thumb(self.settings, i)
|
||||
if self.settings['keep_orig']:
|
||||
vid_ctx['big'] = get_orig(self.settings, i)
|
||||
ctx['videos'].append(vid_ctx)
|
||||
media_ctx['big'] = get_orig(self.settings, i)
|
||||
ctx['medias'].append(media_ctx)
|
||||
|
||||
for d in paths[relpath]['subdir']:
|
||||
dpath = os.path.normpath(os.path.join(relpath, d))
|
||||
@@ -165,8 +163,8 @@ class Writer(object):
|
||||
base, ext = os.path.splitext(source)
|
||||
if ext in self.settings['img_ext_list']:
|
||||
sigal.image.generate_thumbnail(
|
||||
source, thumb_path, self.settings['thumb_size'], None,
|
||||
fit=self.settings['thumb_fit'])
|
||||
source, thumb_path, self.settings['thumb_size'],
|
||||
None, fit=self.settings['thumb_fit'])
|
||||
else:
|
||||
sigal.video.generate_thumbnail(
|
||||
source, thumb_path, self.settings['thumb_size'],
|
||||
|
||||
@@ -13,41 +13,35 @@ REF = {
|
||||
'dir1': {
|
||||
'title': 'An example gallery',
|
||||
'thumbnail': 'test1/11.jpg',
|
||||
'img': [],
|
||||
'vid': []
|
||||
'medias': [],
|
||||
},
|
||||
'dir1/test1': {
|
||||
'title': 'An example sub-category',
|
||||
'thumbnail': '11.jpg',
|
||||
'img': ['11.jpg', 'archlinux-kiss-1024x640.png'],
|
||||
'vid': []
|
||||
'medias': ['11.jpg', 'archlinux-kiss-1024x640.png'],
|
||||
},
|
||||
'dir1/test2': {
|
||||
'title': 'Test2',
|
||||
'thumbnail': '21.jpg',
|
||||
'img': ['21.jpg', '22.jpg'],
|
||||
'vid': []
|
||||
'medias': ['21.jpg', '22.jpg'],
|
||||
},
|
||||
'dir2': {
|
||||
'title': 'Another example gallery',
|
||||
'thumbnail': 'm57_the_ring_nebula-587px.jpg',
|
||||
'img': ['exo20101028-b-full.jpg',
|
||||
'medias': ['exo20101028-b-full.jpg',
|
||||
'm57_the_ring_nebula-587px.jpg',
|
||||
'Hubble ultra deep field.jpg',
|
||||
'Hubble Interacting Galaxy NGC 5257.jpg'],
|
||||
'vid': [],
|
||||
},
|
||||
u'accentué': {
|
||||
'title': u'Accentué',
|
||||
'thumbnail': u'hélicoïde.jpg',
|
||||
'img': [u'hélicoïde.jpg', 'superdupont_source_wikipedia_en.jpg'],
|
||||
'vid': [],
|
||||
'medias': [u'hélicoïde.jpg', 'superdupont_source_wikipedia_en.jpg'],
|
||||
},
|
||||
'video': {
|
||||
'title': 'Video',
|
||||
'thumbnail': 'stallman-software-freedom-day-low.ogv',
|
||||
'img': [],
|
||||
'vid': ['stallman-software-freedom-day-low.ogv']
|
||||
'medias': ['stallman-software-freedom-day-low.ogv']
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +70,7 @@ def test_filelist(db):
|
||||
'dir1/test2', 'dir2', u'accentué', 'video'])
|
||||
|
||||
assert set(db['skipped_dir']) == set(['empty', 'dir1/empty'])
|
||||
assert db['.']['img'] == []
|
||||
assert db['.']['medias'] == []
|
||||
assert set(db['.']['subdir']) == set([u'accentué', 'dir1', 'dir2',
|
||||
'video'])
|
||||
|
||||
@@ -91,14 +85,9 @@ def test_thumbnail(db):
|
||||
assert db[p]['thumbnail'] == REF[p]['thumbnail']
|
||||
|
||||
|
||||
def test_imglist(db):
|
||||
def test_medialist(db):
|
||||
for p in REF.keys():
|
||||
assert set(db[p]['img']) == set(REF[p]['img'])
|
||||
|
||||
|
||||
def test_vidlist(db):
|
||||
for p in REF.keys():
|
||||
assert set(db[p]['vid']) == set(REF[p]['vid'])
|
||||
assert set(db[p]['medias']) == set(REF[p]['medias'])
|
||||
|
||||
|
||||
def test_get_subdir(paths):
|
||||
|
||||
Reference in New Issue
Block a user