path_manager¶
path_manager
¶
Utility for managing cross-platform application paths and temporary files.
Supports Windows, macOS, and Linux following platform-specific standards.
_get_base_app_dir
¶
Internal helper to determine base directories across platforms.
dir_type: 'data', 'config', 'cache', 'logs'.
Source code in src/utils/path_manager.py
get_app_data_dir
¶
get_app_config_dir
¶
get_app_cache_dir
¶
get_piper_voice_dir
¶
Returns the directory holding downloaded Piper TTS voice models.
Each voice is one <voice_id>.onnx + <voice_id>.onnx.json
pair, downloaded on demand from HuggingFace via Settings → Voice
→ Piper. Files persist across sessions (unlike the TTS cache,
which is wiped on app start) — voice models are slow to fetch
(25–60 MB each) and the user explicitly opted in to install them.
Lives under app_data_dir rather than cache_dir so a cache
wipe doesn't blow away the user's downloaded voices.
Source code in src/utils/path_manager.py
get_tts_cache_dir
¶
wipe_tts_cache
¶
Removes all cached Listen-button TTS audio files.
Called at app start so each session begins with a clean TTS cache. Missing directory or individual permission errors are ignored — the cache is best-effort and rebuilds on demand.
Source code in src/utils/path_manager.py
get_llm_endpoint_cache_path
¶
Returns the JSON file persisting Custom-LLM endpoint probe results.
Holds the chat-vs-responses API choice and the working chat payload
variant per (endpoint, model) so CLI / MCP / desktop sessions
don't re-pay the variant probe on every cold start. Lives under the
cache dir because it's regenerable best-effort state — wiping it
just costs one round-trip on the next call.
Source code in src/utils/path_manager.py
get_app_logs_dir
¶
get_app_temp_dir
¶
ensure_app_dirs_exist
¶
Ensures all necessary application directories exist on the system.
Should be called during application startup.
Source code in src/utils/path_manager.py
configure_logging
¶
Configures centralized logging for the application.
Sets up a file handler for all application loggers and a console handler for DEBUG+ messages. Should be called once from app startup.
Source code in src/utils/path_manager.py
get_desktop_path
¶
Returns the user's Desktop directory path cross-platform.
On Linux, reads XDG_DESKTOP_DIR from user-dirs.dirs if available.
On Windows/macOS, ~/Desktop is the standard location.
Falls back to the user's home directory if the Desktop cannot be resolved.
Source code in src/utils/path_manager.py
_resolve_output_dir
¶
Resolves the output directory from a setting key with fallback.
Priority: user-configured storage path → source file's parent directory (if it exists) → Desktop fallback. When the configured path can't be created (permission denied, read-only mount, etc.) the same fallback chain kicks in so a stale or invalid setting doesn't crash the translation pipeline.
| PARAMETER | DESCRIPTION |
|---|---|
setting_key
|
INI settings key for the storage path.
TYPE:
|
source_parent
|
Parent directory of the source file.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Path
|
Resolved output directory (created if absent). |
Source code in src/utils/path_manager.py
_unique_path
¶
Returns a unique file path, appending _1, _2, … on collision.
| PARAMETER | DESCRIPTION |
|---|---|
directory
|
Target directory.
TYPE:
|
stem
|
Base file name without extension.
TYPE:
|
ext
|
File extension including the leading dot.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Path
|
A Path that does not collide with existing files. |
Source code in src/utils/path_manager.py
generate_extraction_output_path
¶
Generates a unique output path for an extracted text file.
| PARAMETER | DESCRIPTION |
|---|---|
source_file_path
|
Original image file path.
TYPE:
|
ext
|
Output file extension (e.g. ".txt", ".docx").
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Path
|
Unique Path for the extracted text output file. |
Source code in src/utils/path_manager.py
generate_subtitle_output_path
¶
Generates a unique output path for a subtitle file.
| PARAMETER | DESCRIPTION |
|---|---|
source_file_path
|
Original audio/video file path.
TYPE:
|
ext
|
Output file extension (e.g. ".srt", ".vtt").
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Path
|
Unique Path for the subtitle output file. |
Source code in src/utils/path_manager.py
generate_voice_output_path
¶
Generates a unique output path for a voice audio file.
| PARAMETER | DESCRIPTION |
|---|---|
source_file_path
|
Original subtitle file path.
TYPE:
|
ext
|
Output file extension (e.g. ".mp3", ".wav").
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Path
|
Unique Path for the voice audio output file. |
Source code in src/utils/path_manager.py
generate_live_session_output_path
¶
Generates a timestamped output path for a Live session artefact.
Used by the Live page to save the session's audio recording
(.wav) and/or transcript (.txt). Both share the same
folder and timestamp so a paired live_audio_<ts>.wav /
live_transcript_<ts>.txt lands together.
Storage folder = SETTING_LIVE_OUTPUT_PATH if set, else a
live_audio/ folder under the user's app-data directory.
| PARAMETER | DESCRIPTION |
|---|---|
extension
|
Output file extension (e.g.
TYPE:
|
stem_prefix
|
File name prefix (e.g.
TYPE:
|
timestamp
|
Optional pre-formatted timestamp for pairing — pass the same string to two calls so the audio and transcript files share an exact stem suffix. When None, a fresh timestamp is generated.
TYPE:
|
Source code in src/utils/path_manager.py
get_default_live_output_dir
¶
Returns the default folder for Live session recordings.
~/Documents/AI Translate Live (cross-platform — Path.home()
works on Linux, macOS, and Windows). Picked for discoverability:
burying recordings in app-data leaves users unable to find their
files without docs. Documents is where users instinctively look
for app-saved content.
Used both as the silent fallback in
:func:generate_live_session_output_path (when the configured
path is empty / unwritable) AND as the default the Settings UI
auto-fills into the path picker when the user opts into save mode.
Source code in src/utils/path_manager.py
get_dubbing_storage_dir
¶
Returns a persistent storage directory for a dubbing entry.
Used to store checkpoints and intermediate files (voice audio) that survive pause/resume cycles.
| PARAMETER | DESCRIPTION |
|---|---|
entry_id
|
Dubbing history entry ID.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Path
|
Path to the storage directory (created if absent). |
Source code in src/utils/path_manager.py
generate_dubbing_output_path
¶
Generates a unique output path for a dubbed video file.
| PARAMETER | DESCRIPTION |
|---|---|
source_file_path
|
Original video file path.
TYPE:
|
src_lang
|
Source language label (e.g. "English (US)").
TYPE:
|
target_lang
|
Target language label (e.g. "Vietnamese").
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Path
|
Unique Path for the dubbed video output file. |
Source code in src/utils/path_manager.py
generate_output_path
¶
Generates a unique output path for a translated file.
Priority: user-configured storage path → source file's parent directory (if it exists) → Desktop fallback.
| PARAMETER | DESCRIPTION |
|---|---|
source_file_path
|
Original file path to translate.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Path
|
Unique Path for the translated output file. |