Skip to content
m314devPublic

About

Go client for the SubDL and OpenSubtitles subtitle APIs: search by TMDB/IMDb id or title, unpack season packs to the right episode, plus SubDL AI translate/transcribe. Standard library only.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

subapi

Go client for the SubDL and OpenSubtitles subtitle APIs.

go get github.com/m314dev/subapi

One dependency beyond the standard library: rardecode, for .rar packs.

Searching

Both sites implement the same Source interface. Find returns candidates; nothing is downloaded until you call Fetch on one, because downloads are the metered part on OpenSubtitles.

sources := []subapi.Source{
    &subapi.SubDL{APIKey: subdlKey},
    &subapi.OpenSubtitles{
        APIKey:    osKey,
        Username:  username,
        Password:  password,
        UserAgent: "myapp v1.0",
    },
}

q := subapi.Query{TMDBID: 1396, Season: 1, Episode: 1, Lang: "ar"}

for _, src := range sources {
    cands, err := src.Find(ctx, q)
    if err != nil {
        continue
    }
    for _, c := range cands {
        srt, err := c.Fetch(ctx)
        if err != nil {
            continue
        }
        fmt.Println(c.Source, c.Release, len(srt))
    }
}

A Query takes a TMDB id, an IMDb id, or a title and year, in that order of preference. Season and Episode are 0 for a movie. An empty Lang means any language.

What Fetch returns is always one SRT file:

  • SubDL serves a bare .srt, a .zip or a .rar, often a whole season or a whole series even when it says otherwise, sometimes one archive per season inside another (up to 3 deep). Everything is opened and the member for the requested episode is picked by its filename (S01E02, 1x02, or a bare episode number when that is unambiguous). When the pack has season folders (Season 2/05.srt, Show.S02.rar/05.srt), only the requested season's folder counts. If the episode isn't in the pack, Fetch returns an error rather than a neighbour.
  • OpenSubtitles results are sorted by download count and requested as SRT. Each download costs one unit of your daily allowance (20/day free).

Pass your own *http.Client in the HTTP field to control timeouts or proxies. The default has a 60 second timeout.

SubDL AI endpoints

SubDL Pro documents AI endpoints on its v2 API, exposed here as methods on SubDL:

sd := &subapi.SubDL{APIKey: subdlKey}

job, err := sd.Translate(ctx, nID, "FA", subapi.ToneFaithful)
job, err = sd.WaitTranslation(ctx, job.Ref(), 0)
srt, err := sd.DownloadTranslation(ctx, job)

m, err := sd.FilenameSearch(ctx, "that.movie.2021.WEBRip.mkv")
q := m.Query("en")

job, err = sd.Transcribe(ctx, "https://host/episode.mp3", "en")

The nID for Translate is the ID of a SubDL candidate. When that candidate is a season pack, use TranslateEp to say which episode, otherwise SubDL answers 409 with the list of files:

job, err := sd.TranslateEp(ctx, nID, "FA", subapi.ToneFaithful, 1, 5) // S01E05

Translations lists your jobs, newest first, a page at a time: pass "" for the first page, then the cursor it returned.

jobs, next, err := sd.Translations(ctx, "")

The code follows SubDL's documented contract: create and status answers nest the job under job, errors are {code, message}, and download_url is a path on the API host. Translations count against a quota on your Pro plan; a spent quota comes back as an error.

License

MIT

About

Go client for the SubDL and OpenSubtitles subtitle APIs: search by TMDB/IMDb id or title, unpack season packs to the right episode, plus SubDL AI translate/transcribe. Standard library only.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages