diff --git a/Dockers/iptv-filter/main.py b/Dockers/iptv-filter/main.py index 00feb1f..0629828 100644 --- a/Dockers/iptv-filter/main.py +++ b/Dockers/iptv-filter/main.py @@ -14,6 +14,8 @@ SOURCE_URL = base64.b64decode(ENCODED_SOURCE_URL).decode('utf-8') if ENCODED_SOU PORT = int(os.environ.get('PORT', 8000)) M3U8_DIR = '/m3u8' LOCAL_FILE_PATH = os.path.join(M3U8_DIR, 'playlist.m3u8') +# Set a long timeout (10 minutes) for downloading large M3U8 files +DOWNLOAD_TIMEOUT = 600 # seconds app = Flask(__name__) @@ -23,8 +25,8 @@ def download_m3u8(): # Ensure the directory exists os.makedirs(M3U8_DIR, exist_ok=True) - print(f"{datetime.now()} - Downloading M3U8 from source") - response = requests.get(SOURCE_URL, timeout=30) + print(f"{datetime.now()} - Downloading M3U8 from source (timeout: {DOWNLOAD_TIMEOUT}s)") + response = requests.get(SOURCE_URL, timeout=DOWNLOAD_TIMEOUT) if response.status_code == 200: with open(LOCAL_FILE_PATH, 'wb') as f: @@ -34,6 +36,9 @@ def download_m3u8(): else: print(f"{datetime.now()} - Failed to download M3U8. Status code: {response.status_code}") return False + except requests.exceptions.Timeout: + print(f"{datetime.now()} - Timeout error: The request took longer than {DOWNLOAD_TIMEOUT} seconds") + return False except Exception as e: print(f"{datetime.now()} - Error downloading M3U8: {str(e)}") return False