Files

61 lines
1.8 KiB
Python

#!/usr/bin/env python3
"""Entry point for the yt-dlp download manager TUI.
Sets up the bundled i18n library (see ``lib/i18n``) with the application's
own translation data (in ``i18n/<lang>/strings.json``) before starting the
Textual application.
Works unmodified from a plain source checkout, from a PyInstaller build, or
from a pex zipapp — see ``app/runtime_paths.py`` for how the base directory
is resolved in each case.
"""
from __future__ import annotations
import sys
from pathlib import Path
# main.py's own directory is already on sys.path (Python does this for the
# script it runs), so the local `app` package is importable immediately.
from app.runtime_paths import bundle_root
PROJECT_ROOT = bundle_root()
# The i18n library package lives in lib/, kept separate from the i18n/
# *data* directory (project_root/i18n/<lang>/strings.json) that the library
# itself expects to find at the project root. In a PyInstaller build this
# path doesn't exist on disk (the library's code is embedded directly in
# the bundle and importable regardless), so inserting it is a harmless
# no-op there.
sys.path.insert(0, str(PROJECT_ROOT / "lib"))
from i18n import I18n # noqa: E402 (import must follow sys.path setup)
DEFAULT_LANGUAGE = "en"
AVAILABLE_LANGUAGES = {
"en": "English",
"da": "Dansk",
"de": "Deutsch",
"es": "Español",
"fr": "Français",
"it": "Italiano",
}
def main() -> None:
# First construction configures the process-wide singleton; every other
# `I18n()` call elsewhere in the app returns this same instance.
I18n(
default_language=DEFAULT_LANGUAGE,
available_languages=AVAILABLE_LANGUAGES,
project_root=PROJECT_ROOT,
)
from app.tui_app import DownloadManagerApp
DownloadManagerApp().run()
if __name__ == "__main__":
main()