Skip to content

Commit

Permalink
fix: catch OSError when string is too long
Browse files Browse the repository at this point in the history
`OSError: [Errno 36] File name too long`
  • Loading branch information
OverflowCat authored Jul 6, 2024
1 parent 7e55bb3 commit 53c0848
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions biliarchiver/cli_tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 53c0848

Please sign in to comment.