From 0b1cf5845f9df9ca6ff721fc687e052589118ea4 Mon Sep 17 00:00:00 2001 From: Ville Rantanen Date: Thu, 28 Jan 2021 14:57:30 +0200 Subject: [PATCH] save media settings in SimpleWebPage --- web/SimpleWebPage.py | 61 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/web/SimpleWebPage.py b/web/SimpleWebPage.py index 2ab1c9d..95fa8aa 100755 --- a/web/SimpleWebPage.py +++ b/web/SimpleWebPage.py @@ -12,8 +12,10 @@ from glob import fnmatch import base64 import random -VERSION = "20200619" +VERSION = "20210128" IMAGE_EXTENSIONS = ["png", "gif", "jpg", "jpeg", "tif", "tiff"] +AUDIO_EXTENSIONS = ["wav", "mp3", "ogg"] +VIDEO_EXTENSIONS = ["mp4", "ogg", "webm"] def setup(): @@ -79,6 +81,14 @@ def setup(): default=False, help="Show images with tags", ) + parser.add_argument( + "--media", + action="store_true", + dest="media", + default=False, + help="Make media playable", + ) + parser.add_argument( "--include", "-i", @@ -112,6 +122,7 @@ def setup2HTML(opts): "parent=%s" % opts.parent, "title=%s" % urllib.parse.quote(opts.title), "images=%s" % opts.images, + "media=%s" % opts.media, ] ) @@ -134,6 +145,8 @@ def HTML2setup(opts): opts.title = urllib.parse.unquote(v) if k == "images": opts.images = v == "True" + if k == "media": + opts.media = v == "True" read_config = True print("Reading options from existing " + opts.filename) break @@ -196,7 +209,7 @@ def generate_index(opts): for di in dirs: f.write(get_pathlink(path, di)) for fi in files: - f.write(get_filelink(path, fi, opts.images)) + f.write(get_filelink(path, fi, opts.images, opts.media)) f.write(get_footer()) f.write(get_wget_lines(files)) f.close() @@ -238,7 +251,7 @@ def generate_password_page(path, password_file, password): return "{}.{}{}".format(target_base, target_middle, target_ext) -def get_filelink(path, fname, images=False): +def get_filelink(path, fname, images=False, media=False): if os.path.islink(os.path.join(path, fname)) and not os.path.exists( os.path.join(path, fname) ): @@ -249,10 +262,13 @@ def get_filelink(path, fname, images=False): fsstrb = str(fsize) fdate = time.localtime(os.path.getmtime(os.path.join(path, fname))) fdstr = time.strftime("%Y/%m/%d %H:%M:%S", fdate) + fname_str = fname if images and is_imagefile(fname): fname_str = get_imagestr(fname) - else: - fname_str = fname + if media and is_audiofile(fname): + fname_str = get_audiostr(fname) + if media and is_videofile(fname): + fname_str = get_videostr(fname) return ( '%s%s%s%s\n' % (urllib.parse.quote(fname), fname_str, fsstr, fsstrb, fdstr) @@ -272,6 +288,20 @@ def get_imagestr(fname): return '' % (urllib.parse.quote(fname), fname) +def get_audiostr(fname): + return '%s
' % ( + fname, + urllib.parse.quote(fname), + ) + + +def get_videostr(fname): + return '%s
' % ( + fname, + urllib.parse.quote(fname), + ) + + def get_pathlink(path, dname): fdate = time.localtime(os.path.getmtime(os.path.join(path, dname))) fdstr = time.strftime("%Y/%m/%d %H:%M:%S", fdate) @@ -466,6 +496,13 @@ def get_header(opts): .bytes { font-size: xx-small; } + .audio { + width: 90%; + } + .video { + width: 320; + height: 240; + }