Fix CBL tagging
This commit is contained in:
parent
3cf75cf2ec
commit
4b6d35fd3a
@ -379,14 +379,15 @@ class RarArchiver(UnknownArchiver):
|
||||
|
||||
def get_comment(self) -> str:
|
||||
rarc = self.get_rar_obj()
|
||||
return str(rarc.comment) if rarc else ""
|
||||
return rarc.comment.decode("utf-8") if rarc else ""
|
||||
|
||||
def set_comment(self, comment: str) -> bool:
|
||||
if rar_support and self.rar_exe_path:
|
||||
try:
|
||||
# write comment to temp file
|
||||
with tempfile.NamedTemporaryFile() as tmp_file:
|
||||
tmp_file.write(comment.encode("utf-8"))
|
||||
with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as tmp_dir:
|
||||
tmp_file = pathlib.Path(tmp_dir) / "rar_comment.txt"
|
||||
tmp_file.write_text(comment, encoding="utf-8")
|
||||
|
||||
working_dir = os.path.dirname(os.path.abspath(self.path))
|
||||
|
||||
@ -396,7 +397,7 @@ class RarArchiver(UnknownArchiver):
|
||||
"c",
|
||||
f"-w{working_dir}",
|
||||
"-c-",
|
||||
f"-z{tmp_file.name}",
|
||||
f"-z{tmp_file}",
|
||||
str(self.path),
|
||||
]
|
||||
subprocess.run(
|
||||
|
@ -112,8 +112,8 @@ class ComicBookInfo:
|
||||
metadata.credits = []
|
||||
|
||||
# need the language string to be ISO
|
||||
if metadata.language is not None:
|
||||
metadata.language = utils.get_language(metadata.language)
|
||||
if metadata.language:
|
||||
metadata.language = utils.get_language_iso(metadata.language)
|
||||
|
||||
metadata.is_empty = False
|
||||
|
||||
|
@ -193,18 +193,15 @@ def get_language_from_iso(iso: str | None) -> str | None:
|
||||
return languages[iso]
|
||||
|
||||
|
||||
def get_language(string: str | None) -> str | None:
|
||||
def get_language_iso(string: str | None) -> str | None:
|
||||
if string is None:
|
||||
return None
|
||||
string = string.casefold()
|
||||
lang = string.casefold()
|
||||
|
||||
lang = get_language_from_iso(string)
|
||||
|
||||
if lang is None:
|
||||
try:
|
||||
return str(pycountry.languages.lookup(string).name)
|
||||
except LookupError:
|
||||
return None
|
||||
try:
|
||||
return getattr(pycountry.languages.lookup(string), "alpha_2", None)
|
||||
except LookupError:
|
||||
pass
|
||||
return lang
|
||||
|
||||
|
||||
|
@ -47,6 +47,56 @@ def test_save_cix(tmp_comic):
|
||||
md = tmp_comic.read_cix()
|
||||
|
||||
|
||||
def test_save_cbi(tmp_comic):
|
||||
md = tmp_comic.read_cix()
|
||||
md.set_default_page_list(tmp_comic.get_number_of_pages())
|
||||
|
||||
assert tmp_comic.write_cbi(md)
|
||||
|
||||
md = tmp_comic.read_cbi()
|
||||
|
||||
|
||||
def test_save_cix_rar(tmp_path):
|
||||
cbr_path = datadir / "fake_cbr.cbr"
|
||||
shutil.copy(cbr_path, tmp_path)
|
||||
|
||||
tmp_comic = comicapi.comicarchive.ComicArchive(tmp_path / cbr_path.name)
|
||||
assert tmp_comic.write_cix(comicapi.genericmetadata.md_test)
|
||||
|
||||
md = tmp_comic.read_cix()
|
||||
assert md.replace(pages=[]) == comicapi.genericmetadata.md_test.replace(pages=[])
|
||||
|
||||
|
||||
def test_save_cbi_rar(tmp_path):
|
||||
cbr_path = datadir / "fake_cbr.cbr"
|
||||
shutil.copy(cbr_path, tmp_path)
|
||||
|
||||
tmp_comic = comicapi.comicarchive.ComicArchive(tmp_path / cbr_path.name)
|
||||
assert tmp_comic.write_cbi(comicapi.genericmetadata.md_test)
|
||||
|
||||
md = tmp_comic.read_cbi()
|
||||
assert md.replace(pages=[]) == comicapi.genericmetadata.md_test.replace(
|
||||
pages=[],
|
||||
day=None,
|
||||
alternate_series=None,
|
||||
alternate_number=None,
|
||||
alternate_count=None,
|
||||
imprint=None,
|
||||
notes=None,
|
||||
web_link=None,
|
||||
format=None,
|
||||
manga=None,
|
||||
page_count=None,
|
||||
maturity_rating=None,
|
||||
story_arc=None,
|
||||
series_group=None,
|
||||
scan_info=None,
|
||||
characters=None,
|
||||
teams=None,
|
||||
locations=None,
|
||||
)
|
||||
|
||||
|
||||
def test_page_type_save(tmp_comic):
|
||||
md = tmp_comic.read_cix()
|
||||
t = md.pages[0]
|
||||
|
@ -18,7 +18,6 @@ def test_cbi():
|
||||
md = CBI.metadata_from_string(string)
|
||||
md_test = comicapi.genericmetadata.md_test.replace(
|
||||
day=None,
|
||||
language="English",
|
||||
page_count=None,
|
||||
maturity_rating=None,
|
||||
story_arc=None,
|
||||
|
@ -63,17 +63,18 @@ def test_xlate(value, result):
|
||||
|
||||
|
||||
language_values = [
|
||||
("en", "English"),
|
||||
("EN", "English"),
|
||||
("En", "English"),
|
||||
("", None),
|
||||
("english", "en"),
|
||||
("ENGLISH", "en"),
|
||||
("EnglisH", "en"),
|
||||
("", ""),
|
||||
("aaa", None), # does not have a 2-letter code
|
||||
(None, None),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value, result", language_values)
|
||||
def test_get_language(value, result):
|
||||
assert result == comicapi.utils.get_language(value)
|
||||
def test_get_language_iso(value, result):
|
||||
assert result == comicapi.utils.get_language_iso(value)
|
||||
|
||||
|
||||
def test_unique_file(tmp_path):
|
||||
|
Loading…
Reference in New Issue
Block a user