save media settings in SimpleWebPage
This commit is contained in:
@@ -12,8 +12,10 @@ from glob import fnmatch
|
|||||||
import base64
|
import base64
|
||||||
import random
|
import random
|
||||||
|
|
||||||
VERSION = "20200619"
|
VERSION = "20210128"
|
||||||
IMAGE_EXTENSIONS = ["png", "gif", "jpg", "jpeg", "tif", "tiff"]
|
IMAGE_EXTENSIONS = ["png", "gif", "jpg", "jpeg", "tif", "tiff"]
|
||||||
|
AUDIO_EXTENSIONS = ["wav", "mp3", "ogg"]
|
||||||
|
VIDEO_EXTENSIONS = ["mp4", "ogg", "webm"]
|
||||||
|
|
||||||
|
|
||||||
def setup():
|
def setup():
|
||||||
@@ -79,6 +81,14 @@ def setup():
|
|||||||
default=False,
|
default=False,
|
||||||
help="Show images with <img> tags",
|
help="Show images with <img> tags",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--media",
|
||||||
|
action="store_true",
|
||||||
|
dest="media",
|
||||||
|
default=False,
|
||||||
|
help="Make media playable",
|
||||||
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--include",
|
"--include",
|
||||||
"-i",
|
"-i",
|
||||||
@@ -112,6 +122,7 @@ def setup2HTML(opts):
|
|||||||
"parent=%s" % opts.parent,
|
"parent=%s" % opts.parent,
|
||||||
"title=%s" % urllib.parse.quote(opts.title),
|
"title=%s" % urllib.parse.quote(opts.title),
|
||||||
"images=%s" % opts.images,
|
"images=%s" % opts.images,
|
||||||
|
"media=%s" % opts.media,
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -134,6 +145,8 @@ def HTML2setup(opts):
|
|||||||
opts.title = urllib.parse.unquote(v)
|
opts.title = urllib.parse.unquote(v)
|
||||||
if k == "images":
|
if k == "images":
|
||||||
opts.images = v == "True"
|
opts.images = v == "True"
|
||||||
|
if k == "media":
|
||||||
|
opts.media = v == "True"
|
||||||
read_config = True
|
read_config = True
|
||||||
print("Reading options from existing " + opts.filename)
|
print("Reading options from existing " + opts.filename)
|
||||||
break
|
break
|
||||||
@@ -196,7 +209,7 @@ def generate_index(opts):
|
|||||||
for di in dirs:
|
for di in dirs:
|
||||||
f.write(get_pathlink(path, di))
|
f.write(get_pathlink(path, di))
|
||||||
for fi in files:
|
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_footer())
|
||||||
f.write(get_wget_lines(files))
|
f.write(get_wget_lines(files))
|
||||||
f.close()
|
f.close()
|
||||||
@@ -238,7 +251,7 @@ def generate_password_page(path, password_file, password):
|
|||||||
return "{}.{}{}".format(target_base, target_middle, target_ext)
|
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(
|
if os.path.islink(os.path.join(path, fname)) and not os.path.exists(
|
||||||
os.path.join(path, fname)
|
os.path.join(path, fname)
|
||||||
):
|
):
|
||||||
@@ -249,10 +262,13 @@ def get_filelink(path, fname, images=False):
|
|||||||
fsstrb = str(fsize)
|
fsstrb = str(fsize)
|
||||||
fdate = time.localtime(os.path.getmtime(os.path.join(path, fname)))
|
fdate = time.localtime(os.path.getmtime(os.path.join(path, fname)))
|
||||||
fdstr = time.strftime("%Y/%m/%d %H:%M:%S", fdate)
|
fdstr = time.strftime("%Y/%m/%d %H:%M:%S", fdate)
|
||||||
|
fname_str = fname
|
||||||
if images and is_imagefile(fname):
|
if images and is_imagefile(fname):
|
||||||
fname_str = get_imagestr(fname)
|
fname_str = get_imagestr(fname)
|
||||||
else:
|
if media and is_audiofile(fname):
|
||||||
fname_str = fname
|
fname_str = get_audiostr(fname)
|
||||||
|
if media and is_videofile(fname):
|
||||||
|
fname_str = get_videostr(fname)
|
||||||
return (
|
return (
|
||||||
'<tr><td><a class="link_file" href="%s">%s</a><td class="right">%s</td><td class="right bytes">%s</td><td class="right">%s</td></tr>\n'
|
'<tr><td><a class="link_file" href="%s">%s</a><td class="right">%s</td><td class="right bytes">%s</td><td class="right">%s</td></tr>\n'
|
||||||
% (urllib.parse.quote(fname), fname_str, fsstr, fsstrb, fdstr)
|
% (urllib.parse.quote(fname), fname_str, fsstr, fsstrb, fdstr)
|
||||||
@@ -272,6 +288,20 @@ def get_imagestr(fname):
|
|||||||
return '<img src="%s" title="%s"/>' % (urllib.parse.quote(fname), fname)
|
return '<img src="%s" title="%s"/>' % (urllib.parse.quote(fname), fname)
|
||||||
|
|
||||||
|
|
||||||
|
def get_audiostr(fname):
|
||||||
|
return '%s<br><audio src="%s" controls class=audio></audio>' % (
|
||||||
|
fname,
|
||||||
|
urllib.parse.quote(fname),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_videostr(fname):
|
||||||
|
return '%s<br><video class=video controls><source src="%s"></video>' % (
|
||||||
|
fname,
|
||||||
|
urllib.parse.quote(fname),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_pathlink(path, dname):
|
def get_pathlink(path, dname):
|
||||||
fdate = time.localtime(os.path.getmtime(os.path.join(path, dname)))
|
fdate = time.localtime(os.path.getmtime(os.path.join(path, dname)))
|
||||||
fdstr = time.strftime("%Y/%m/%d %H:%M:%S", fdate)
|
fdstr = time.strftime("%Y/%m/%d %H:%M:%S", fdate)
|
||||||
@@ -466,6 +496,13 @@ def get_header(opts):
|
|||||||
.bytes {
|
.bytes {
|
||||||
font-size: xx-small;
|
font-size: xx-small;
|
||||||
}
|
}
|
||||||
|
.audio {
|
||||||
|
width: 90%;
|
||||||
|
}
|
||||||
|
.video {
|
||||||
|
width: 320;
|
||||||
|
height: 240;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
/*
|
/*
|
||||||
@@ -814,6 +851,20 @@ def is_imagefile(fname):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def is_audiofile(fname):
|
||||||
|
for ext in AUDIO_EXTENSIONS:
|
||||||
|
if fname.lower().endswith(ext):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def is_videofile(fname):
|
||||||
|
for ext in VIDEO_EXTENSIONS:
|
||||||
|
if fname.lower().endswith(ext):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def match_files(files, glob_list):
|
def match_files(files, glob_list):
|
||||||
matched = []
|
matched = []
|
||||||
for f in files:
|
for f in files:
|
||||||
|
|||||||
Reference in New Issue
Block a user