Skip to content

Commit db2fa51

Browse files
FEAT: Adding a Progress Bat to the Subtitles Translations with DeepL Python Project
1 parent 41ab412 commit db2fa51

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

Subtitles Translations with DeepL/main.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
from Logger import Logger # For logging output to both terminal and file
6464
from pathlib import Path # For handling file paths
6565
from shutil import copyfile # For copying files
66+
from tqdm import tqdm # For progress bars
6667

6768
# Macros:
6869
class BackgroundColors: # Colors for the terminal
@@ -332,17 +333,19 @@ def main():
332333
print(f"No .srt files found in directory: {INPUT_DIR}") # Output message
333334
return # Exit the program
334335

335-
for srt_file in srt_files: # Iterate through each SRT file
336-
print(f"{BackgroundColors.GREEN}Processing file: {BackgroundColors.CYAN}{srt_file}{Style.RESET_ALL}")
336+
for srt_file in tqdm(srt_files, desc=f"{BackgroundColors.GREEN}Translating SRT files{Style.RESET_ALL}", unit="file"): # Iterate through each SRT file with progress bar
337+
tqdm.write(f"{BackgroundColors.GREEN}Processing file: {BackgroundColors.CYAN}{srt_file}{Style.RESET_ALL}") # Show current file
338+
337339
srt_lines = read_srt(srt_file) # Read SRT
340+
338341
translated_lines = translate_srt_lines(srt_lines) # Translate
339-
342+
340343
relative_path = srt_file.relative_to(INPUT_DIR).parent # Get relative path
341344
output_subdir = OUTPUT_DIR / relative_path # Create output subdirectory path
342-
output_subdir.mkdir(parents=True, exist_ok=True) # Create output subdirectory if it doesn't exist
343-
345+
output_subdir.mkdir(parents=True, exist_ok=True) # Ensure output subdir exists
346+
344347
output_file = output_subdir / f"{srt_file.stem}_ptBR.srt" # Build output file path
345-
save_srt(translated_lines, output_file) # Save translated SRT
348+
save_srt(translated_lines, output_file) # Save translated SRT
346349

347350
finish_time = datetime.datetime.now() # Get the finish time of the program
348351
print(f"{BackgroundColors.GREEN}Start time: {BackgroundColors.CYAN}{start_time.strftime('%d/%m/%Y - %H:%M:%S')}\n{BackgroundColors.GREEN}Finish time: {BackgroundColors.CYAN}{finish_time.strftime('%d/%m/%Y - %H:%M:%S')}\n{BackgroundColors.GREEN}Execution time: {BackgroundColors.CYAN}{calculate_execution_time(start_time, finish_time)}{Style.RESET_ALL}") # Output start, finish, and execution times
28 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)