Skip to content

An Android library for querying and downloading subtitles from Open Subtitles.

License

Notifications You must be signed in to change notification settings

masterwok/open-subtitles-android

Repository files navigation

Release

open-subtitles-android

An Android library for querying and downloading subtitles from Open Subtitles.

Usage

The OpenSubtitlesUrlBuilder is used to build a valid Open Subtitels url (as described here). For example, the following will build a url that is used to search for the German subtitles of the movie Hackers from 1995:

val url = OpenSubtitlesUrlBuilder()
        .query("Hackers 1995")
        .subLanguageId("ger")
        .build()
        
// url = "https://rest.opensubtitles.org/search/query-Hackers+1995/sublanguageid-ger"

For available query parameters, take a look at the OpenSubtitlesUrlBuilder class. For available language codes, take a look at the IdSubLanguage column of the available language codes here.

TheOpenSubtitlesService class is used to query and download subtitles. For example, to search for subtitles one can do the following:

val service = OpenSubtitlesService()
val url = ...as shown above...
val searchResult: Array<OpenSubtitleItem> = service.search(OpenSubtitlesService.TemporaryUserAgent, url)

As you can see, OpenSubtitleService.search(userAgent: String, url: String) returns an array of OpenSubtitleItem instances. If no subtitles are found, then an empty array is returned. To download some subtitle file from the search results to some destination file specified by the destination Uri, one can do the following:

val searchResult: Array<OpenSubtitleItem> = ...as shown above...
val destinationUri: Uri = ...

service.downloadSubtitle(
        context
        , searchResult.first()
        , destinationUri
)

Configuration

Add this in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

and add the following in the dependent module:

dependencies {
    implementation 'com.github.masterwok:open-subtitles-android:0.0.8'
}

Projects using open-subtitles-android

About

An Android library for querying and downloading subtitles from Open Subtitles.

Resources

License

Stars

Watchers

Forks

Packages

No packages published