summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Honz <exislow+github@gmail.com>2024-01-12 08:38:41 +0100
committerRobert Honz <exislow+github@gmail.com>2024-01-12 08:38:41 +0100
commit69cf0b4707ea95789616309847698fb78a6a633d (patch)
treeae051f1bdadcc14dff4346037493139499a2766f
parent1494490476d57a49ff8a69ed4baecf5eea4a0d97 (diff)
downloadtidal-dl-ng-69cf0b4707ea95789616309847698fb78a6a633d.tar.gz
🛠️ Implemented timeout for `requests calls.
-rw-r--r--tidal_dl_ng/api.py5
-rw-r--r--tidal_dl_ng/constants.py1
-rw-r--r--tidal_dl_ng/download.py4
-rw-r--r--tidal_dl_ng/metadata.py3
4 files changed, 9 insertions, 4 deletions
diff --git a/tidal_dl_ng/api.py b/tidal_dl_ng/api.py
index c68665e..20a2ace 100644
--- a/tidal_dl_ng/api.py
+++ b/tidal_dl_ng/api.py
@@ -61,6 +61,8 @@ __ERROR_KEY__ = (
},
)
+from constants import REQUESTS_TIMEOUT_SEC
+
def getNum():
return len(__API_KEYS__["keys"])
@@ -94,7 +96,8 @@ def getVersion():
# Load from gist
try:
- respond = requests.get("https://api.github.com/gists/48d01f5a24b4b7b37f19443977c22cd6")
+ respond = requests.get("https://api.github.com/gists/48d01f5a24b4b7b37f19443977c22cd6",
+ timeout=REQUESTS_TIMEOUT_SEC)
if respond.status_code == 200:
content = respond.json()["files"]["tidal-api-key.json"]["content"]
__API_KEYS__ = json.loads(content)
diff --git a/tidal_dl_ng/constants.py b/tidal_dl_ng/constants.py
index 41564db..d2c9e5b 100644
--- a/tidal_dl_ng/constants.py
+++ b/tidal_dl_ng/constants.py
@@ -1,6 +1,7 @@
from enum import Enum
CTX_TIDAL: str = "tidal"
+REQUESTS_TIMEOUT_SEC = 45
class QualityVideo(Enum):
diff --git a/tidal_dl_ng/download.py b/tidal_dl_ng/download.py
index 2e15bd8..c9ffe41 100644
--- a/tidal_dl_ng/download.py
+++ b/tidal_dl_ng/download.py
@@ -17,7 +17,7 @@ from rich.progress import Progress
from tidalapi import Album, Mix, Playlist, Session, Track, UserPlaylist, Video
from tidal_dl_ng.config import Settings
-from tidal_dl_ng.constants import MediaType
+from tidal_dl_ng.constants import REQUESTS_TIMEOUT_SEC, MediaType
from tidal_dl_ng.helper.decryption import decrypt_file, decrypt_security_token
from tidal_dl_ng.helper.exceptions import MediaUnknown
from tidal_dl_ng.helper.path import check_file_exists, format_path_media, path_validate
@@ -134,7 +134,7 @@ class Download:
try:
# Streaming, so we can iterate over the response.
- r = requests.get(stream_url, stream=True)
+ r = requests.get(stream_url, stream=True, timeout=REQUESTS_TIMEOUT_SEC)
r.raise_for_status()
total_size_in_bytes = int(r.headers.get("content-length", 0))
block_size = 4096
diff --git a/tidal_dl_ng/metadata.py b/tidal_dl_ng/metadata.py
index 7b60f2b..cb88eeb 100644
--- a/tidal_dl_ng/metadata.py
+++ b/tidal_dl_ng/metadata.py
@@ -2,6 +2,7 @@ import pathlib
import mutagen
import requests
+from constants import REQUESTS_TIMEOUT_SEC
from mutagen import flac, mp4
from mutagen.id3 import APIC, TALB, TCOM, TCOP, TDRC, TIT2, TOPE, TPE1, TRCK, TSRC, USLT
@@ -158,7 +159,7 @@ class Metadata:
if url:
try:
- result = requests.get(url).content
+ result = requests.get(url, timeout=REQUESTS_TIMEOUT_SEC).content
except:
pass
elif path_file: