mirror of
https://github.com/flibusta-apps/books_downloader.git
synced 2025-12-06 15:05:37 +01:00
Fix exception catching
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import asyncio
|
||||
from typing import Optional, AsyncIterator, cast
|
||||
import zipfile
|
||||
|
||||
import aiofiles
|
||||
import aiofiles.os
|
||||
@@ -133,7 +134,13 @@ class FLDownloader(BaseDownloader):
|
||||
)
|
||||
|
||||
return data
|
||||
except (NotSuccess, ReceivedHTML, ConvertationError, FileNotFoundError):
|
||||
except (
|
||||
NotSuccess,
|
||||
ReceivedHTML,
|
||||
ConvertationError,
|
||||
FileNotFoundError,
|
||||
ValueError,
|
||||
):
|
||||
continue
|
||||
|
||||
tasks_ = pending
|
||||
@@ -157,7 +164,7 @@ class FLDownloader(BaseDownloader):
|
||||
return await asyncio.get_event_loop().run_in_executor(
|
||||
process_pool_executor, unzip, temp_file.name, "fb2"
|
||||
)
|
||||
except FileNotFoundError:
|
||||
except (FileNotFoundError, zipfile.BadZipFile):
|
||||
return None
|
||||
|
||||
async def _download_with_converting(
|
||||
|
||||
@@ -22,9 +22,10 @@ def remove_temp_file(filename: str) -> bool:
|
||||
|
||||
|
||||
def unzip(temp_zipfile: str, file_type: str) -> Optional[str]:
|
||||
zip_file = zipfile.ZipFile(temp_zipfile)
|
||||
|
||||
result = tempfile.NamedTemporaryFile(delete=False)
|
||||
|
||||
zip_file = zipfile.ZipFile(temp_zipfile)
|
||||
for name in zip_file.namelist(): # type: str
|
||||
if file_type.lower() in name.lower() or name.lower() == "elector":
|
||||
with zip_file.open(name, "r") as internal_file:
|
||||
|
||||
Reference in New Issue
Block a user