Skip to main content

The MLLP-VRAIN's transLectures Platform (TLP) Python3 API client library and tools

Project description

tlp-client

tlp-client is a set of python3 client libraries and tools for the transLectures Platform (TLP), developed by the MLLP-VRAIN research group. It can be used to integrate your media repository's backend with all TLP services, which include automatic multilingual subtitling, dubbing, and professional post-editing for on-demand contents.

Installation

tlp-client is avalable on PyPI:

--$ python3 -m pip install tlp-client
# or
--$ pip3 install tlp-client

It supports Python 3.5+.

Library

tlp-client module mainly implements the TLPSpeechClient, TLPTextClient and TLPWebClient classes that provides several methods to interact with the /speech, /text and /web APIs of the transLectures-UPV Platform.

Below are shown some examples on interacting with the /speech API. Using this library to query /text and /web API interfaces is pretty similar.

First, we have to import the tlp_client library and create a TLPSpeechClient class instance, using the appropriate argument values. E.g.:

>>> import tlp_client
>>> tlp = tlp_client.TLPSpeechClient("https://my-tlp-instance.com/api/v3", 
                                     "https://my-tlp-instance.com/player", 
                                     "my-api-user", 
                                     "my-api-key")

To get the list of subtitle languages available for a particular Media ID:

>>> tlp.api_langs("media-id-1")
>>> print(tlp.get_printable_response_data())

To download a subtitles file, for instance, English subtitles in SRT format:

>>> tlp.api_get("media-id-1", "en", form="srt")
>>> tlp.save_response_data("/path/to/my/media_subs.en.srt")

To Generate and upload a Media Package File to the TLP Server is also quite straightforward:

>>> # Initialise Manifest, definining media ID:
>>> tlp.manifest_init("media-id-2")
>>> # Add some metadata (media language and title are mandatory)
>>> tlp.manifest_set_metadata(language="en", title="Testing tlp_client")
>>> # Add video/audio file (can be a public URL/URI, also)
>>> tlp.manifest_set_main_media_file("/path/to/my/media_file.mp4")
>>> # Enable Ingest Service's Test Mode, since we are doing a test:
>>> tlp.manifest_set_options(test_mode=True)
>>> # Generate Media Package File and upload it via the /ingest/new interface:
>>> tlp.api_ingest_new()
>>> # Why to print the response? I just want the upload ID!
>>> upload_id = tlp.ret_data['id']

To track the progress of our first upload:

>>> tlp.api_status(upload_id)
>>> print(tlp.get_printable_response_data())

You can build the most complex Media Package in the world, but only if you want!

>>> tlp.manifest_init("media-id-3")
>>> tlp.manifest_set_metadata(language="en", title="Really testing tlp_client")
>>> tlp.manifest_set_main_media_file("/path/to/my/media_file.mp4")
>>> # Add a related text file to improve transcription quality
>>> tlp.manifest_add_attachment("/path/to/my/doc_file.pdf", 
                                 tlp_client.TLPClient.FTYPE_CODE_DOCUMENT)
>>> # Request Spanish subtitles (English are generated by default):
>>> tlp.manifest_add_subtitles_request("es")
>>> # Request also a text-to-speech synthesized Spanish audiotrack:
>>> tlp.manifest_add_audiotrack_request("es")
>>> # ...
>>> # AND FINALLY...
>>> tlp.api_ingest_new()
>>> # Mere curiosity... print me the generated Manifest JSON object!
>>> print(tlp.get_printable_manifest())

Extended documentation of this module can be find either here or running help(tlp_client).

For further information you might check the full documentation of the transLectures-UPV Platform.

Commandline tools

tlp-client comes with three handy command-line tools that make use of the tlp_client python3 module:

  • tlp-api-cli
  • tlp-player-urlgen
  • tlp-transedit-urlgen.

All them require a configuration file (config.ini) to work. By default they look on the working directory. The --config-fileoption allows to provide it manually. Please note that the--print-sample-config-fileoption can be used to generate a templateconfig.ini` file:

--$ tlp-api-cli --print-sample-config-file
[general]
web_service_url = 
player_url = 
translation_editor_url = 
web_translation_editor_url = 

[http_auth]
enabled = no
username = 
password = 

[api_client_auth]
enabled = yes
username = 
secret_key = 
request_key_expire_lifetime = 

[player_user_info]
user_id = 
user_full_name = 
user_confidence = 

Configuration parameters have to be properly set up, using your TLP's instance service URLs and API credentials. These can be retrieved from the API section of your TLP instance's web platform interface (e.g. https://ttp.mllp.upv.es/index.php?page=api).

tlp-api-cli

tlp-api-cli makes use of the TLP Python3 Client Library (tlp-client) and implements all TLP API endpoint calls.

Examples of use:

  • To upload a new English video file (with ID "my-media-1234") and request English and Spanish subtitles [/speech/ingest/new API call]:
--$ tlp-api-cli speech ingest new --language "en" \
                                  --title "My first video" \
                                  --media-file "/path/to/my/video.mp4" \
                                  --requested-languages-subs en \
                                  --requested-languages-subs es \
                                  "my-media-1234"
  • To check the status of an uploaded video, using an upload ID returned by the /speech/ingest/new interface (i.e. "up-1234") [/speech/status API
    call:
--$ tlp-api-cli speech status "up-1234"
  • To get the subtitle languages available for the video ID "my-media-1234" [/speech/langs API call]:
--$ tlp-api-cli speech langs "my-media-1234"
  • To get English subtitles in SRT format for the video ID "my-media-1234" [/speech/get API call]:
--$ tlp-api-cli speech get --format "srt" "my-media-1234" "en" 

tlp-player-urlgen

tlp-player-urlgen generates valid URLs to call/embed the TLP Player for a media object ID.

--$ tlp-player-urlgen my-media-1234

tlp-transedit-urlgen

tlp-transedit-urlgen generates valid URLs to call/embed the TLP translation editor for a document object ID and translation language.

--$ tlp-transedit-urlgen my-document-5678 en

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tlp-client-3.12.0.tar.gz (34.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tlp_client-3.12.0-py3-none-any.whl (36.0 kB view details)

Uploaded Python 3

File details

Details for the file tlp-client-3.12.0.tar.gz.

File metadata

  • Download URL: tlp-client-3.12.0.tar.gz
  • Upload date:
  • Size: 34.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for tlp-client-3.12.0.tar.gz
Algorithm Hash digest
SHA256 2ef8df28d08c2540f5398d2a1635cbd3d96b6dc86ddc7b8f2b49dd0f2f749654
MD5 3454c2e8810cad652105e96e2866f601
BLAKE2b-256 5c58cdf8d4cb835f4b95e9a91c57b224efb78197d6c175a41d90e6e77d5e8473

See more details on using hashes here.

File details

Details for the file tlp_client-3.12.0-py3-none-any.whl.

File metadata

  • Download URL: tlp_client-3.12.0-py3-none-any.whl
  • Upload date:
  • Size: 36.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for tlp_client-3.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 96b76093ccce168b7453f80e9dd1ee84adbdd72b179447ef1b886e3bf5b40885
MD5 aae0fd7ef7be810724d99b201af93ba3
BLAKE2b-256 3cff879f339d8b0715e6dc604272863d551674da7c7ea58965b925aa4ab6e235

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page