Skip to content

Commit

Permalink
Merge pull request #42 from mediacatch/41-add-true-or-false-as-option…
Browse files Browse the repository at this point in the history
…s-for-fallback_language

Add docs for fallback_language and True and False options
  • Loading branch information
FredHaa authored Mar 22, 2024
2 parents d57fb54 + 82a9ce0 commit 2cfa717
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/mediacatch_s2t/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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..."):
Expand Down
5 changes: 3 additions & 2 deletions src/mediacatch_s2t/uploader.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 2cfa717

Please sign in to comment.