From 2b2073eeefa983fb47fad7462a209fb6323d9957 Mon Sep 17 00:00:00 2001 From: Lawrence Angrave Date: Sat, 27 Jan 2024 16:19:16 -0600 Subject: [PATCH] Add Configurable KALTURA_TIMEOUT --- PythonRpcServer/kaltura.py | 4 ++-- PythonRpcServer/utils.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/PythonRpcServer/kaltura.py b/PythonRpcServer/kaltura.py index 41528b9..4120461 100644 --- a/PythonRpcServer/kaltura.py +++ b/PythonRpcServer/kaltura.py @@ -16,7 +16,7 @@ KALTURA_PARTNER_ID = int(os.getenv('KALTURA_PARTNER_ID', default=0)) KALTURA_TOKEN_ID = os.getenv('KALTURA_TOKEN_ID', default=None) KATLURA_APP_TOKEN = os.getenv('KALTURA_APP_TOKEN', default=None) - +KALTURA_TIMEOUT= int( os.getenv('KALTURA_TIMEOUT', default=30)) # Examples of Playlists URLs the user is likely to see- # Playlist 1_eilnj5er is Angrave's short set of example vidos @@ -181,7 +181,7 @@ def getMediaInfosForKalturaChannel(self, partnerInfo, channelId): return self.getSensibleMediaInfos(res) def downloadLecture(self, url): - filePath, extension = download_file(url) + filePath, extension = download_file(url, timeout=KALTURA_TIMEOUT) return filePath, extension #Exxpects diff --git a/PythonRpcServer/utils.py b/PythonRpcServer/utils.py index 1cc7996..39b02a7 100644 --- a/PythonRpcServer/utils.py +++ b/PythonRpcServer/utils.py @@ -87,12 +87,12 @@ def extension_from_magic_bytes(filepath): # Filepath and cookies may be specified # Returns a two tuple, [filepath, extension] # An appropriate Extension is guessed based on the mimetype in the 'content-type' response header -def download_file(url, filepath=None, cookies=None): +def download_file(url, filepath=None, cookies=None, timeout=60): # NOTE the stream=True parameter below if not filepath: filepath = getTmpFile() extension = None - with requests.get(url, stream=True, allow_redirects=True, cookies=cookies) as r: + with requests.get(url, stream=True, allow_redirects=True, cookies=cookies, timeout=timeout) as r: r.raise_for_status()