diff --git a/src/mediacatch_s2t/__main__.py b/src/mediacatch_s2t/__main__.py index 0b7ff5e..22e993b 100644 --- a/src/mediacatch_s2t/__main__.py +++ b/src/mediacatch_s2t/__main__.py @@ -14,9 +14,12 @@ def main() -> None: parser.add_argument("api_key", type=str, help="MediaCatch API key.") parser.add_argument("file", type=str, help="A media file.") parser.add_argument("--quota", type=str, default=None, help="The quota to bill usage to. Defaults to None.") - parser.add_argument("--fallback_language", type=str, default=None, help="Overrides the language to transcribe in if language identification fails. If None, uses the default language of the quota.") + parser.add_argument("--fallback_language", type=str, default=True, help="Overrides the language to transcribe in if language identification fails. If True or None, it uses the default language of the quota. If False, the quota default language is ignored.") args = parser.parse_args() + if args.fallback_language in ['True', 'False', 'None']: + args.fallback_language = eval(args.fallback_language) + console = Console() with console.status( "[bold green]Uploading file to MediaCatch..."): diff --git a/src/mediacatch_s2t/uploader.py b/src/mediacatch_s2t/uploader.py index a756b48..83866ac 100644 --- a/src/mediacatch_s2t/uploader.py +++ b/src/mediacatch_s2t/uploader.py @@ -1,7 +1,7 @@ import requests from concurrent.futures import ThreadPoolExecutor, as_completed from pathlib import Path -from typing import Optional, Generator +from typing import Optional, Generator, Union from mediacatch_s2t import ( URL, @@ -203,13 +203,14 @@ def _is_response_successful(response: requests.Response) -> bool: """ return 200 <= response.status_code < 300 -def upload_and_get_transcription(file: str, api_key: str, quota: Optional[str] = None, fallback_language: Optional[str] = None) -> dict[str, str]: +def upload_and_get_transcription(file: str, api_key: str, quota: Optional[str] = None, fallback_language: Optional[Union[str, bool]] = None) -> dict[str, str]: """Uploads a file and returns its transcription. Args: file (str): The path to the file to be uploaded. api_key (str): The API key for authentication. quota (str | None): The quota to bill transcription hours from. Use None if user only has 1 quota. + fallback_language (str | bool | None): Overrides the language to transcribe in if language identification fails. If True or None, it uses the default language of the quota. If False, the quota default language is ignored. Returns: dict[str, str]: A dictionary containing the transcription or error message.