From 89015d51fe0a61608f959be297cfa201ce77eb8d Mon Sep 17 00:00:00 2001 From: bender Date: Sun, 12 Nov 2023 13:56:20 -0500 Subject: [PATCH] Progress bar --- Chop_Tag_Audio/exportchapters.py | 30 +++++------------------------- Chop_Tag_Audio/progress_bar.py | 28 ++++++++++++++++++++++++++++ requirements.txt | 3 ++- 3 files changed, 35 insertions(+), 26 deletions(-) create mode 100644 Chop_Tag_Audio/progress_bar.py diff --git a/Chop_Tag_Audio/exportchapters.py b/Chop_Tag_Audio/exportchapters.py index 3a9a091..8d9f34e 100644 --- a/Chop_Tag_Audio/exportchapters.py +++ b/Chop_Tag_Audio/exportchapters.py @@ -1,9 +1,8 @@ -import sys -import random import os import shutil from pydub import AudioSegment from XML_JSON.json_scripts import load_config +from Chop_Tag_Audio.progress_bar import process_progress, get_chapter_count parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) config_path = os.path.join(parent_dir, 'config.json') @@ -28,20 +27,8 @@ def export_audio_file(combined, start_ms, end_ms, name, circulation, author_name return export_folder # Return the folder path where the file was exported def split_mp3s(annex, circulation): - update_messages = [ - "Getting close...", - "Hang in there...", - "Still running...", - "Almost done...", - "It'll all be over soon...", - "Bear with me..." - ] - - # Shuffle the list of messages - random.shuffle(update_messages) - - # An iterator over the shuffled list of messages - message_cycle = iter(update_messages) + total_chapters = get_chapter_count(annex) + overall_progress_bar = process_progress(total_chapters) for folder in sorted(os.listdir(annex)): folder_path = os.path.join(annex, folder) @@ -69,16 +56,9 @@ def split_mp3s(annex, circulation): export_folder = export_audio_file(combined, start_ms, end_ms, formatted_name, circulation, author_name.strip(), folder_name.strip()) artwork_and_metadata(export_folder, folder_path) + overall_progress_bar.update(1) + file_count += 1 # Increment file_count after each file is exported - - message = next(message_cycle, None) - - if message is None: # If the end of the list is reached, shuffle and restart - random.shuffle(update_messages) - message_cycle = iter(update_messages) - message = next(message_cycle) - - print(message) except Exception as e: print(f"Error processing {folder}: {e}") diff --git a/Chop_Tag_Audio/progress_bar.py b/Chop_Tag_Audio/progress_bar.py new file mode 100644 index 0000000..00370e7 --- /dev/null +++ b/Chop_Tag_Audio/progress_bar.py @@ -0,0 +1,28 @@ +import sys +import os +import fnmatch +from tqdm import tqdm + +parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +sys.path.insert(0, parent_dir) + +from XML_JSON.json_scripts import load_config + +parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +config_path = os.path.join(parent_dir, 'config.json') + +config = load_config(config_path) + +directory = config['circulation'] + +def get_chapter_count(directory): + total_chapters = 0 + for root, _, files in os.walk(directory): + for filename in fnmatch.filter(files, 'overdrive_chapters_ms_spans.txt'): + file_path = os.path.join(root, filename) + with open(file_path, 'r') as f: + total_chapters += sum(1 for _ in f) + return total_chapters + +def process_progress(total_chapters): + return tqdm(total=total_chapters, ncols=75, desc="Splitting mp3's...") \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index d346a67..1cabccc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ mutagen==1.46.0 -pydub==0.25.1 \ No newline at end of file +pydub==0.25.1 +tqdm==4.64.1 \ No newline at end of file