Skip to content

Improved SubDL provider: on-demand AI translation for missing languages (SubDL Plus/Pro)#3415

Open
subdl-maker wants to merge 1 commit into
morpheus65535:developmentfrom
subdl-maker:subdl-ai-translate
Open

Improved SubDL provider: on-demand AI translation for missing languages (SubDL Plus/Pro)#3415
subdl-maker wants to merge 1 commit into
morpheus65535:developmentfrom
subdl-maker:subdl-ai-translate

Conversation

@subdl-maker

Copy link
Copy Markdown

Description

Adds opt-in on-demand AI translation to the SubDL provider. When the SubDL API reports that a wanted language has no subtitles for a title but can be AI-translated (available to SubDL Plus/Pro accounts), the provider offers a virtual "AI translation" result. If Bazarr picks it, download_subtitle() submits a translation job to SubDL, polls until it finishes (typically under a minute, hard cap 3 minutes), and returns the translated file through the normal download flow.

What's included

  • New provider settings (both wired through config.py, get_providers.py, and the frontend provider list):
    • ai_translate — default off, following the same opt-in convention as opensubtitlescom.include_ai_translated, since it spends the user's SubDL monthly translation quota unattended.
    • include_ai_translated — default on; when off, results the API flags as ai_translated are filtered out. Flagged results are labeled "(AI translated)" in the uploader field.
  • Source selection by release match: a translation inherits the timing of the subtitle it is translated from, so the provider scores the API's suggested source subtitles against the video's release names (same utils.update_matches logic used for scoring) and submits the best match.
  • Quota/entitlement awareness: the API only advertises translation sources when the key's account can actually translate. Free keys get a single info log line per video; exhausted quota logs the reset date and goes quiet. The checkbox is inert for free accounts.
  • Throttle-safe failure handling: the AI download path never raises DownloadLimitExceeded/AuthenticationError/APIThrottled — a failed or slow translation sets subtitle.content = None and logs, so the provider's regular searches and downloads are never throttled by a failed translation. If the deadline passes, the job still completes server-side and the finished subtitle appears as a regular search result afterwards (re-requesting it is answered instantly without consuming quota again).
  • Fully backward compatible: all new behavior keys off optional fields in the API response; against an API without these fields the provider behaves exactly as before. No new required settings.

Tests

tests/subliminal_patch/test_subdl.py gains 11 mocked tests (no live API key needed) covering candidate synthesis, source selection by release match, suppression when not entitled / quota exhausted / language already available / setting disabled, the submit→poll→download flow, job reuse, job failure, and that quota errors do not raise throttling exceptions.

11 passed (new tests; the 2 pre-existing tests require a live SUBDL_TOKEN)

🤖 Generated with Claude Code

When the SubDL API reports that a wanted language has no subtitles but can
be AI-translated (SubDL Plus/Pro accounts), the provider now offers a
virtual "AI translation" candidate. Picking it submits a translation job,
waits for completion (typically under a minute), and returns the translated
file through the normal download flow.

- New provider settings: ai_translate (default off) and
  include_ai_translated (default on, filters subtitles the API flags as
  AI-translated)
- The translation source is chosen by matching its release names against
  the video, since translations inherit the source's timing
- Translation failures never raise DownloadLimitExceeded/AuthenticationError
  so regular downloads are never throttled by a failed translation
- Fully backward compatible: without the API's translation fields the
  provider behaves exactly as before

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant