Skip to content

Commit

Permalink
fix: Don't crash when trying to compute a download's name
Browse files Browse the repository at this point in the history
Issue #68: #68
  • Loading branch information
pawamoy committed Apr 17, 2022
1 parent 2b302e9 commit c0cfbce
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/aria2p/downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
torrent files, files and downloads in aria2c.
"""

from contextlib import suppress
from datetime import datetime, timedelta
from pathlib import Path
from typing import List, Optional
Expand Down Expand Up @@ -293,12 +294,11 @@ def name(self) -> str: # noqa: WPS231
dir_path = str(self.dir.absolute())
if file_path.startswith(dir_path):
start_pos = len(dir_path) + 1
self._name = Path(file_path[start_pos:]).parts[0]
with suppress(IndexError):
self._name = Path(file_path[start_pos:]).parts[0]
else:
try:
with suppress(IndexError):
self._name = self.files[0].uris[0]["uri"].split("/")[-1] # noqa: WPS219
except IndexError:
pass # noqa: WPS420 (we don't want to fail here)
return self._name

@property
Expand Down

0 comments on commit c0cfbce

Please sign in to comment.