Always apply the default page list when writing metadata

This commit is contained in:
Timmy Welch 2023-12-20 21:24:12 -08:00
parent c3a8221d99
commit ceb3b30e5c
3 changed files with 19 additions and 15 deletions

View File

@ -21,7 +21,6 @@ import pathlib
import shutil
import sys
import traceback
from typing import cast
from comicapi import utils
from comicapi.archivers import Archiver, UnknownArchiver, ZipArchiver
@ -179,6 +178,7 @@ class ComicArchive:
def write_metadata(self, metadata: GenericMetadata, style: str) -> bool:
if style in self.md:
del self.md[style]
metadata.apply_default_page_list(self.get_page_name_list())
return metadata_styles[style].set_metadata(metadata, self.archiver)
def has_metadata(self, style: str) -> bool:
@ -270,19 +270,7 @@ class ComicArchive:
def get_page_name_list(self) -> list[str]:
if not self.page_list:
# get the list file names in the archive, and sort
files: list[str] = self.archiver.get_filename_list()
files = cast(list[str], utils.os_sorted(files))
# make a sub-list of image files
self.page_list = []
for name in files:
if (
os.path.splitext(name)[1].casefold() in [".jpg", ".jpeg", ".png", ".gif", ".webp"]
and os.path.basename(name)[0] != "."
):
self.page_list.append(name)
self.page_list = utils.get_page_name_list(self.archiver.get_filename_list())
return self.page_list

View File

@ -289,6 +289,7 @@ class GenericMetadata:
def apply_default_page_list(self, page_list: Sequence[str]) -> None:
# generate a default page list, with the first page marked as the cover
# Create a dictionary of all pages in the metadata
pages = {p["image_index"]: p for p in self.pages}
cover_set = False

View File

@ -23,7 +23,7 @@ import unicodedata
from collections import defaultdict
from collections.abc import Iterable, Mapping
from shutil import which # noqa: F401
from typing import Any, TypeVar
from typing import Any, TypeVar, cast
import comicapi.data
from comicapi import filenamelexer, filenameparser
@ -195,6 +195,21 @@ def path_to_short_str(original_path: pathlib.Path, renamed_path: pathlib.Path |
return path_str
def get_page_name_list(files: list[str]) -> list[str]:
# get the list file names in the archive, and sort
files = cast(list[str], os_sorted(files))
# make a sub-list of image files
page_list = []
for name in files:
if (
os.path.splitext(name)[1].casefold() in [".jpg", ".jpeg", ".png", ".gif", ".webp"]
and os.path.basename(name)[0] != "."
):
page_list.append(name)
return page_list
def get_recursive_filelist(pathlist: list[str]) -> list[str]:
"""Get a recursive list of of all files under all path items in the list"""