From 335d97ec2d3ca4216e8b7c4fb9ffe536a0ec0914 Mon Sep 17 00:00:00 2001 From: Lovi <62809003+Lovi-0@users.noreply.github.com> Date: Sat, 8 Feb 2025 17:16:56 +0100 Subject: [PATCH] Try fix _tmp on linux --- .../Lib/Downloader/HLS/segments.py | 1 - StreamingCommunity/Lib/M3U8/estimator.py | 10 +++--- StreamingCommunity/Util/os.py | 32 +++++++++++-------- config.json | 4 +-- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/StreamingCommunity/Lib/Downloader/HLS/segments.py b/StreamingCommunity/Lib/Downloader/HLS/segments.py index 081a434..c4e6026 100644 --- a/StreamingCommunity/Lib/Downloader/HLS/segments.py +++ b/StreamingCommunity/Lib/Downloader/HLS/segments.py @@ -384,7 +384,6 @@ class M3U8_Segments: return ( f"{Colors.YELLOW}Proc{Colors.WHITE}: " f"{Colors.RED}{{percentage:.2f}}% " - f"{Colors.WHITE}| " f"{Colors.CYAN}{{remaining}}{{postfix}} {Colors.WHITE}]" ) diff --git a/StreamingCommunity/Lib/M3U8/estimator.py b/StreamingCommunity/Lib/M3U8/estimator.py index f68db29..882625d 100644 --- a/StreamingCommunity/Lib/M3U8/estimator.py +++ b/StreamingCommunity/Lib/M3U8/estimator.py @@ -127,16 +127,16 @@ class M3U8_Ts_Estimator: retry_count = self.segments_instance.active_retries if self.segments_instance else 0 progress_str = ( #f"{Colors.WHITE}[ {Colors.GREEN}{number_file_downloaded} {Colors.WHITE}< " - f"{Colors.GREEN}{number_file_total_size} {Colors.RED}{units_file_total_size} " - f"{Colors.WHITE}| {Colors.CYAN}{average_internet_speed} {Colors.RED}{average_internet_unit} " - f"{Colors.WHITE}| {Colors.GREEN}CRR {Colors.RED}{retry_count}" + f"{Colors.GREEN}{number_file_total_size} {Colors.RED}{units_file_total_size}" + f"{Colors.WHITE} {Colors.CYAN}{average_internet_speed} {Colors.RED}{average_internet_unit}" + f"{Colors.WHITE} {Colors.GREEN}CRR {Colors.RED}{retry_count} " ) else: retry_count = self.segments_instance.active_retries if self.segments_instance else 0 progress_str = ( #f"{Colors.WHITE}[ {Colors.GREEN}{number_file_downloaded} {Colors.WHITE}< " - f"{Colors.GREEN}{number_file_total_size} {Colors.RED}{units_file_total_size} " - f"{Colors.WHITE}| {Colors.GREEN}CRR {Colors.RED}{retry_count}" + f"{Colors.GREEN}{number_file_total_size} {Colors.RED}{units_file_total_size}" + f"{Colors.WHITE} {Colors.GREEN}CRR {Colors.RED}{retry_count} " ) progress_counter.set_postfix_str(progress_str) diff --git a/StreamingCommunity/Util/os.py b/StreamingCommunity/Util/os.py index 37b5b12..eda0b38 100644 --- a/StreamingCommunity/Util/os.py +++ b/StreamingCommunity/Util/os.py @@ -202,20 +202,26 @@ class OsManager: """ try: - # List all files in the folder - files_in_folder = os.listdir(folder_path) - - # Iterate over each file in the folder - for file_name in files_in_folder: - file_path = os.path.join(folder_path, file_name) - - # Check if the file is not the one to keep and is a regular file - if file_name != keep_file and os.path.isfile(file_path): - os.remove(file_path) # Delete the file - + # First, try to make all files writable + for root, dirs, files in os.walk(self.temp_dir): + for dir_name in dirs: + dir_path = os.path.join(root, dir_name) + os.chmod(dir_path, 0o755) # rwxr-xr-x + for file_name in files: + file_path = os.path.join(root, file_name) + os.chmod(file_path, 0o644) # rw-r--r-- + + # Then remove the directory tree + shutil.rmtree(self.temp_dir, ignore_errors=True) + + # If directory still exists after rmtree, try force remove + if os.path.exists(self.temp_dir): + import subprocess + subprocess.run(['rm', '-rf', self.temp_dir], check=True) + except Exception as e: - logging.error(f"An error occurred: {e}") - raise + logging.error(f"Failed to cleanup temporary directory: {str(e)}") + pass def check_file(self, file_path: str) -> bool: """ diff --git a/config.json b/config.json index 05664c0..a536aab 100644 --- a/config.json +++ b/config.json @@ -22,7 +22,7 @@ "telegram_bot": false }, "REQUESTS": { - "timeout": 20, + "timeout": 25, "max_retry": 8, "proxy_start_min": 0.1, "proxy_start_max": 0.5 @@ -31,7 +31,7 @@ "tqdm_delay": 0.01, "default_video_workser": 12, "default_audio_workser": 12, - "segment_timeout": 7, + "segment_timeout": 8, "download_audio": true, "merge_audio": true, "specific_list_audio": [