mirror of
https://github.com/flibusta-apps/books_downloader.git
synced 2025-12-06 15:05:37 +01:00
Refactoring
This commit is contained in:
@@ -75,16 +75,16 @@ class FLDownloader(BaseDownloader):
|
|||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
response = await client.send(request, stream=True)
|
response = await client.send(request, stream=True)
|
||||||
except asyncio.CancelledError:
|
except (asyncio.CancelledError, httpx.ReadError, httpx.ConnectError) as e:
|
||||||
await client.aclose()
|
await client.aclose()
|
||||||
raise
|
raise NotSuccess(str(e))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
content_type = response.headers.get("Content-Type")
|
|
||||||
|
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
raise NotSuccess(f"Status code is {response.status_code}!")
|
raise NotSuccess(f"Status code is {response.status_code}!")
|
||||||
|
|
||||||
|
content_type = response.headers.get("Content-Type")
|
||||||
|
|
||||||
if "text/html" in content_type:
|
if "text/html" in content_type:
|
||||||
raise ReceivedHTML()
|
raise ReceivedHTML()
|
||||||
|
|
||||||
@@ -128,10 +128,13 @@ class FLDownloader(BaseDownloader):
|
|||||||
try:
|
try:
|
||||||
data = task.result()
|
data = task.result()
|
||||||
|
|
||||||
await self._close_other_done(
|
for t_task in pending:
|
||||||
{ttask for ttask in pending if not ttask.cancel()}
|
if not t_task.done() or t_task.cancelled():
|
||||||
)
|
continue
|
||||||
|
|
||||||
|
t_task.cancel()
|
||||||
|
|
||||||
|
await self._close_other_done(pending)
|
||||||
await self._close_other_done(
|
await self._close_other_done(
|
||||||
{ttask for ttask in done if ttask != task}
|
{ttask for ttask in done if ttask != task}
|
||||||
)
|
)
|
||||||
@@ -213,12 +216,9 @@ class FLDownloader(BaseDownloader):
|
|||||||
converter_response = await converter_client.send(
|
converter_response = await converter_client.send(
|
||||||
converter_request, stream=True
|
converter_request, stream=True
|
||||||
)
|
)
|
||||||
except httpx.ReadTimeout:
|
except (httpx.ConnectError, httpx.ReadTimeout, asyncio.CancelledError):
|
||||||
await converter_client.aclose()
|
await converter_client.aclose()
|
||||||
raise ConvertationError()
|
raise ConvertationError
|
||||||
except asyncio.CancelledError:
|
|
||||||
await converter_client.aclose()
|
|
||||||
raise
|
|
||||||
finally:
|
finally:
|
||||||
await aiofiles.os.remove(filename_to_convert)
|
await aiofiles.os.remove(filename_to_convert)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user