fix: catch OSError when string is too long

`OSError: [Errno 36] File name too long`
This commit is contained in:
ᡥᠠᡳᡤᡳᠶᠠ ᡥᠠᠯᠠ·ᠨᡝᡴᠣ 猫 2024-07-07 04:26:59 +08:00 committed by GitHub
parent 7e55bb3298
commit 53c08488fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -8,10 +8,13 @@ def read_bvids(bvids: str) -> list[str]:
bvids_list = None
file = Path(bvids)
if file.exists() and file.is_file():
with open(file, "r", encoding="utf-8") as f:
bvids_list = f.read().split()
else:
try:
if file.exists() and file.is_file():
with open(file, "r", encoding="utf-8") as f:
bvids_list = f.read().split()
else:
raise Exception("Not a file")
except Exception as _:
bvids_list = bvids.split()
del bvids
@ -26,4 +29,4 @@ def read_bvids(bvids: str) -> list[str]:
def read_bvids_from_txt(txt_path: Union[Path,str]) -> List[str]:
with open(txt_path, "r", encoding="utf-8") as f:
bvids = [line.strip() for line in f if line.strip().startswith("BV")]
return bvids
return bvids