lazy load for videos

This commit is contained in:
Ville Rantanen
2022-03-28 14:27:55 +03:00
parent 68b1c0d905
commit afca67300e
2 changed files with 25 additions and 15 deletions

View File

@@ -1,5 +1,4 @@
__version__ = "20220124.0" __version__ = "20220328.0"
__version__ = "20211114.0"
def get_version(): def get_version():

View File

@@ -18,7 +18,9 @@ class Mirva:
self.medium_dir = os.path.join(self.resource_dir, "med") self.medium_dir = os.path.join(self.resource_dir, "med")
self.config_file = os.path.join(self.resource_dir, "config.cfg") self.config_file = os.path.join(self.resource_dir, "config.cfg")
self.config_backup = os.path.join(self.resource_dir, "config.cfg.bkp") self.config_backup = os.path.join(self.resource_dir, "config.cfg.bkp")
self.image_match = re.compile(".*\.jpg$|.*\.jpeg$|.*\.png$|.*\.gif$|.*\.tif$", re.I) self.image_match = re.compile(
".*\.jpg$|.*\.jpeg$|.*\.png$|.*\.gif$|.*\.tif$", re.I
)
self.video_match = re.compile(".*\.mp4$", re.I) self.video_match = re.compile(".*\.mp4$", re.I)
self.get_options() self.get_options()
os.chdir(self.options.folder) os.chdir(self.options.folder)
@@ -26,7 +28,9 @@ class Mirva:
self.file_list = self.get_files() self.file_list = self.get_files()
if self.options.config or not os.path.exists(self.config_file): if self.options.config or not os.path.exists(self.config_file):
self.create_config() self.create_config()
print("Config created: Exiting without gallery creation. Check config first.") print(
"Config created: Exiting without gallery creation. Check config first."
)
return return
self.get_config() self.get_config()
if self.options.exif: if self.options.exif:
@@ -88,7 +92,6 @@ class Mirva:
with open(self.config_file, "wt") as fp: with open(self.config_file, "wt") as fp:
self.config.write(fp) self.config.write(fp)
def get_files(self): def get_files(self):
image_match = re.compile(".*\.jpg$|.*\.jpeg$|.*\.png$|.*\.gif$|.*\.tif$", re.I) image_match = re.compile(".*\.jpg$|.*\.jpeg$|.*\.png$|.*\.gif$|.*\.tif$", re.I)
files = [] files = []
@@ -109,7 +112,10 @@ class Mirva:
) )
# parser.add_argument("-v", default=False, action="store_true") # parser.add_argument("-v", default=False, action="store_true")
parser.add_argument( parser.add_argument(
"--config", default=False, action="store_true", help="Write config and exit. Required if more images are added." "--config",
default=False,
action="store_true",
help="Write config and exit. Required if more images are added.",
) )
parser.add_argument( parser.add_argument(
"--force", "--force",
@@ -207,7 +213,7 @@ Released : 20110306
<div class="post"> <div class="post">
<div class="navigation">&nbsp;</div> <div class="navigation">&nbsp;</div>
<div class=center><a href="{image}"> <div class=center><a href="{image}">
<video class=post_image controls > <video class=post_image controls preload="metadata">
<source src="{image}" type="video/mp4" > <source src="{image}" type="video/mp4" >
</video> </video>
</a></div> </a></div>
@@ -229,7 +235,6 @@ Released : 20110306
image=image, title=title, content=content, med_dir=self.medium_dir image=image, title=title, content=content, med_dir=self.medium_dir
) )
def is_created_with_mirva(self): def is_created_with_mirva(self):
with open("index.html", "rt") as fp: with open("index.html", "rt") as fp:
@@ -242,7 +247,9 @@ Released : 20110306
if os.path.exists("index.html"): if os.path.exists("index.html"):
if not self.is_created_with_mirva(): if not self.is_created_with_mirva():
print("index.html exists, and it's not written with Mirva. Not overwriting.") print(
"index.html exists, and it's not written with Mirva. Not overwriting."
)
sys.exit(1) sys.exit(1)
with open("index.html", "wt") as fp: with open("index.html", "wt") as fp:
@@ -326,14 +333,14 @@ Released : 20110306
sys.stdout.write("\n") sys.stdout.write("\n")
def append_exif(self): def append_exif(self):
exif_format = ''' exif_format = """
<ul> <ul>
<li>Date: %[EXIF:DateTimeOriginal] <li>Date: %[EXIF:DateTimeOriginal]
<li>Camera: %[EXIF:Make] %[EXIF:Model] <li>Camera: %[EXIF:Make] %[EXIF:Model]
<li>Parameters: %[EXIF:ExposureTime]s / F%[EXIF:FNumber] / Focal %[EXIF:FocalLength] <li>Parameters: %[EXIF:ExposureTime]s / F%[EXIF:FNumber] / Focal %[EXIF:FocalLength]
<li>Size: %w x %h / {size} <li>Size: %w x %h / {size}
</ul> </ul>
''' """
for f in self.config: for f in self.config:
if f in self.file_list: if f in self.file_list:
@@ -341,16 +348,20 @@ Released : 20110306
sys.stdout.flush() sys.stdout.flush()
file_size = human_size(f) file_size = human_size(f)
p = subprocess.run( p = subprocess.run(
['identify','-format',exif_format.format(size=file_size),"{}[0]".format(f)], [
capture_output = True "identify",
"-format",
exif_format.format(size=file_size),
"{}[0]".format(f),
],
capture_output=True,
) )
self.config[f]['description'] += p.stdout.decode('utf-8') self.config[f]["description"] += p.stdout.decode("utf-8")
sys.stdout.write("\n") sys.stdout.write("\n")
self.write_config() self.write_config()
def human_size(file_name, precision=1): def human_size(file_name, precision=1):
size = os.path.getsize(file_name) size = os.path.getsize(file_name)