Skip to content

Refactor localizemedia: add multi-threading, ETA, and resume support#39

Open
julius-gun wants to merge 1 commit into
ankitects:mainfrom
julius-gun:feature/localize_media_multithreaded-localization
Open

Refactor localizemedia: add multi-threading, ETA, and resume support#39
julius-gun wants to merge 1 commit into
ankitects:mainfrom
julius-gun:feature/localize_media_multithreaded-localization

Conversation

@julius-gun

Copy link
Copy Markdown

Description

This PR refactors the localizemedia add-on from a single-file synchronous script into a modular, multi-threaded package. These changes significantly improve performance for users with large collections and provide a more resilient UX.

Key Improvements

  • Multi-threading: Implemented ThreadPoolExecutor (5 workers) to download media in parallel.
  • Progress & ETA: Added a real-time ETA calculation and progress updates to the progress bar.
  • Resume Capability: If a process is interrupted or cancelled, users can now "Resume Remaining" notes without restarting the entire batch.
  • Reliability:
    • Added domain-specific rate limiting/locking to avoid 429 errors.
    • Improved URL normalization (handling special characters like &).
    • Added a session cache to prevent redundant downloads of the same URL within a single batch.
  • Safety: Implemented explicit locking for Anki collection access to ensure thread safety.

Architectural Changes

Moved logic into a src/ sub-package:

  • media_handler.py: Network requests and file writing.
  • note_logic.py: Regex parsing and note modification.
  • ui_commands.py: Background operations and UI interaction.
  • stats.py: Thread-safe counters and error logging.

Testing

  • Verified with notes containing multiple images and audio tags.
  • Tested "Cancel" and "Resume" functionality.
  • Verified that undo entries are correctly merged upon completion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant