diff --git a/app/src/main/java/com/lagradost/cloudstream3/metaproviders/TmdbProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/metaproviders/TmdbProvider.kt index 314177af..f8a7180a 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/metaproviders/TmdbProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/metaproviders/TmdbProvider.kt @@ -10,7 +10,10 @@ import com.uwetrottmann.tmdb2.Tmdb import com.uwetrottmann.tmdb2.entities.* import com.uwetrottmann.tmdb2.enumerations.AppendToResponseItem import com.uwetrottmann.tmdb2.enumerations.VideoType +import info.movito.themoviedbapi.TmdbApi +import org.apache.commons.lang3.ObjectUtils.Null import retrofit2.awaitResponse +import java.time.Year import java.util.* /** @@ -42,6 +45,7 @@ open class TmdbProvider : MainAPI() { // Fuck it, public private api key because github actions won't co-operate. // Please no stealy. private val tmdb = Tmdb("e6333b32409e02a4a6eba6fb7ff866bb") + private val tmdbApi = TmdbApi("e6333b32409e02a4a6eba6fb7ff866bb") private fun getImageUrl(link: String?): String? { if (link == null) return null @@ -361,4 +365,21 @@ open class TmdbProvider : MainAPI() { it.movie?.toSearchResponse() ?: it.tvShow?.toSearchResponse() } } + + open fun getImdb(query: String, year: Int=0): String { + val searches = tmdbApi.search + val search = searches.searchMovie(query,year,null,true,0) + val movieId: Int + if (search.totalResults > 0) + movieId = search.results[0].id + else + return "" + val movies = tmdbApi.movies + val movie = movies.getMovie(movieId, null) + if (movie == null) + return "" + else + return movie.imdbID + } + } diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/OpenSubtitlesApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/OpenSubtitlesApi.kt index 0fbe851f..50401962 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/OpenSubtitlesApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/OpenSubtitlesApi.kt @@ -6,6 +6,7 @@ import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.AcraApplication.Companion.getKey import com.lagradost.cloudstream3.AcraApplication.Companion.removeKey import com.lagradost.cloudstream3.AcraApplication.Companion.setKey +import com.lagradost.cloudstream3.metaproviders.TmdbProvider import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.subtitles.AbstractSubApi import com.lagradost.cloudstream3.subtitles.AbstractSubtitleEntities @@ -166,19 +167,18 @@ class OpenSubtitlesApi(index: Int) : InAppAuthAPIManager(index), AbstractSubApi val queryText = query.query.replace(" ", "+") val epNum = query.epNumber ?: 0 val seasonNum = query.seasonNumber ?: 0 - val ans = getImdb(queryText) + val yearNum = query.year ?: 0 + val tmdbprov = TmdbProvider() var imdbId = "" - var yearNum = 0 - if (ans[0] != "" && ans[1] != "" && seasonNum == 0 && epNum == 0) { - imdbId = ans[0] - yearNum = ans[1].toInt() + if (seasonNum == 0 && epNum == 0) { // applicable only for movies for now + imdbId = tmdbprov.getImdb(queryText, yearNum) } val epQuery = if (epNum > 0) "&episode_number=$epNum" else "" val seasonQuery = if (seasonNum > 0) "&season_number=$seasonNum" else "" val yearQuery = if (yearNum > 0) "&year=$yearNum" else "" val searchQueryUrl = when (imdbId != "") { - //Use imdb_id to search if its valid + //Use imdbId to search if its valid true -> "$host/subtitles?imdb_id=$imdbId&languages=${fixedLang}$yearQuery$epQuery$seasonQuery" false -> "$host/subtitles?query=$queryText&languages=${fixedLang}$yearQuery$epQuery$seasonQuery" } @@ -236,20 +236,6 @@ class OpenSubtitlesApi(index: Int) : InAppAuthAPIManager(index), AbstractSubApi return results } - private fun getImdb(s: String): Array { - val searches = TmdbApi("b2960a64f51310954666c97170072562").search - val search = searches.searchMovie(s,0,null,true,0) - val movie_id = search.results[0].id - val movies = TmdbApi("b2960a64f51310954666c97170072562").movies - val movie = movies.getMovie(movie_id, null) - if (movie == null) { - return arrayOf("", "") - } - else { - return arrayOf(movie.imdbID, movie.releaseDate.substring(0,4)) - } - } - /* Process data returned from search. Returns string url for the subtitle file.