lazy load for videos
This commit is contained in:
@@ -18,7 +18,9 @@ class Mirva:
|
||||
self.medium_dir = os.path.join(self.resource_dir, "med")
|
||||
self.config_file = os.path.join(self.resource_dir, "config.cfg")
|
||||
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.get_options()
|
||||
os.chdir(self.options.folder)
|
||||
@@ -26,7 +28,9 @@ class Mirva:
|
||||
self.file_list = self.get_files()
|
||||
if self.options.config or not os.path.exists(self.config_file):
|
||||
self.create_config()
|
||||
print("Config created: Exiting without gallery creation. Check config first.")
|
||||
print(
|
||||
"Config created: Exiting without gallery creation. Check config first."
|
||||
)
|
||||
return
|
||||
self.get_config()
|
||||
if self.options.exif:
|
||||
@@ -88,7 +92,6 @@ class Mirva:
|
||||
with open(self.config_file, "wt") as fp:
|
||||
self.config.write(fp)
|
||||
|
||||
|
||||
def get_files(self):
|
||||
image_match = re.compile(".*\.jpg$|.*\.jpeg$|.*\.png$|.*\.gif$|.*\.tif$", re.I)
|
||||
files = []
|
||||
@@ -109,7 +112,10 @@ class Mirva:
|
||||
)
|
||||
# parser.add_argument("-v", default=False, action="store_true")
|
||||
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(
|
||||
"--force",
|
||||
@@ -207,7 +213,7 @@ Released : 20110306
|
||||
<div class="post">
|
||||
<div class="navigation"> </div>
|
||||
<div class=center><a href="{image}">
|
||||
<video class=post_image controls >
|
||||
<video class=post_image controls preload="metadata">
|
||||
<source src="{image}" type="video/mp4" >
|
||||
</video>
|
||||
</a></div>
|
||||
@@ -229,7 +235,6 @@ Released : 20110306
|
||||
image=image, title=title, content=content, med_dir=self.medium_dir
|
||||
)
|
||||
|
||||
|
||||
def is_created_with_mirva(self):
|
||||
|
||||
with open("index.html", "rt") as fp:
|
||||
@@ -242,7 +247,9 @@ Released : 20110306
|
||||
|
||||
if os.path.exists("index.html"):
|
||||
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)
|
||||
|
||||
with open("index.html", "wt") as fp:
|
||||
@@ -326,14 +333,14 @@ Released : 20110306
|
||||
sys.stdout.write("\n")
|
||||
|
||||
def append_exif(self):
|
||||
exif_format = '''
|
||||
exif_format = """
|
||||
<ul>
|
||||
<li>Date: %[EXIF:DateTimeOriginal]
|
||||
<li>Camera: %[EXIF:Make] %[EXIF:Model]
|
||||
<li>Parameters: %[EXIF:ExposureTime]s / F%[EXIF:FNumber] / Focal %[EXIF:FocalLength]
|
||||
<li>Size: %w x %h / {size}
|
||||
</ul>
|
||||
'''
|
||||
"""
|
||||
|
||||
for f in self.config:
|
||||
if f in self.file_list:
|
||||
@@ -341,16 +348,20 @@ Released : 20110306
|
||||
sys.stdout.flush()
|
||||
file_size = human_size(f)
|
||||
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")
|
||||
self.write_config()
|
||||
|
||||
|
||||
|
||||
def human_size(file_name, precision=1):
|
||||
size = os.path.getsize(file_name)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user