Chapterize-Audiobooks icon indicating copy to clipboard operation
Chapterize-Audiobooks copied to clipboard

Progress bar + info [Request]

Open dxcore35 opened this issue 1 year ago • 0 comments

Hello, it will be very nice to give it a progressbard: with current line where is the transcription to keep user entertained, and actualy see if something is going on

Template

15% [███████░░░░░░░░░░░░░░░░░░░░░] | [00:15:23] The quick brown fox jumps over the lazy dog

CHAPTERS:

00:01:45 | Chapter: Prologue 00:05:30 | Chapter: Chapter 1

Scripts

def display_progress(percentage: float, time_str: str, current_text: str, width: int = 50) -> None:
    """Display a self-updating progress bar with current sentence.
    
    :param percentage: Current progress percentage (0-100)
    :param time_str: Current time position in format HH:MM:SS
    :param current_text: Current text being processed
    :param width: Width of the progress bar in characters
    """
    import shutil
    terminal_width = shutil.get_terminal_size().columns
    
    # Calculate progress bar
    filled = int(width * percentage / 100)
    bar = '█' * filled + '░' * (width - filled)
    
    # Create output string
    output = f'\r{percentage:>3.0f}% [{bar}] | [{time_str}] {current_text}'
    
    # Clear the line and print new content
    print(f'\r{" " * terminal_width}', end='', flush=True)
    print(output[:terminal_width], end='', flush=True)

def display_chapters() -> callable:
    """Create a function to handle chapter display in terminal.
    
    :return: Function to add chapters to display
    """
    _chapters = []
    _header_printed = False
    
    def add_chapter(time: str, chapter: str) -> None:
        """Add a new chapter to the display.
        
        :param time: Chapter start time in format HH:MM:SS
        :param chapter: Chapter title/name
        """
        nonlocal _header_printed
        
        if not _header_printed:
            print("\nCHAPTERS:")
            print("-" * 14)
            _header_printed = True
            
        _chapters.append(f"{time} | Chapter: {chapter}")
        print(_chapters[-1])
    
    return add_chapter

dxcore35 avatar Nov 15 '24 09:11 dxcore35