mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
use class Tmdb provider for the already defined api, clean code
This commit is contained in:
parent
c0f57b1368
commit
19cc629165
2 changed files with 27 additions and 20 deletions
|
@ -10,7 +10,10 @@ import com.uwetrottmann.tmdb2.Tmdb
|
||||||
import com.uwetrottmann.tmdb2.entities.*
|
import com.uwetrottmann.tmdb2.entities.*
|
||||||
import com.uwetrottmann.tmdb2.enumerations.AppendToResponseItem
|
import com.uwetrottmann.tmdb2.enumerations.AppendToResponseItem
|
||||||
import com.uwetrottmann.tmdb2.enumerations.VideoType
|
import com.uwetrottmann.tmdb2.enumerations.VideoType
|
||||||
|
import info.movito.themoviedbapi.TmdbApi
|
||||||
|
import org.apache.commons.lang3.ObjectUtils.Null
|
||||||
import retrofit2.awaitResponse
|
import retrofit2.awaitResponse
|
||||||
|
import java.time.Year
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,6 +45,7 @@ open class TmdbProvider : MainAPI() {
|
||||||
// Fuck it, public private api key because github actions won't co-operate.
|
// Fuck it, public private api key because github actions won't co-operate.
|
||||||
// Please no stealy.
|
// Please no stealy.
|
||||||
private val tmdb = Tmdb("e6333b32409e02a4a6eba6fb7ff866bb")
|
private val tmdb = Tmdb("e6333b32409e02a4a6eba6fb7ff866bb")
|
||||||
|
private val tmdbApi = TmdbApi("e6333b32409e02a4a6eba6fb7ff866bb")
|
||||||
|
|
||||||
private fun getImageUrl(link: String?): String? {
|
private fun getImageUrl(link: String?): String? {
|
||||||
if (link == null) return null
|
if (link == null) return null
|
||||||
|
@ -361,4 +365,21 @@ open class TmdbProvider : MainAPI() {
|
||||||
it.movie?.toSearchResponse() ?: it.tvShow?.toSearchResponse()
|
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
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import com.lagradost.cloudstream3.*
|
||||||
import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
|
import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
|
||||||
import com.lagradost.cloudstream3.AcraApplication.Companion.removeKey
|
import com.lagradost.cloudstream3.AcraApplication.Companion.removeKey
|
||||||
import com.lagradost.cloudstream3.AcraApplication.Companion.setKey
|
import com.lagradost.cloudstream3.AcraApplication.Companion.setKey
|
||||||
|
import com.lagradost.cloudstream3.metaproviders.TmdbProvider
|
||||||
import com.lagradost.cloudstream3.mvvm.logError
|
import com.lagradost.cloudstream3.mvvm.logError
|
||||||
import com.lagradost.cloudstream3.subtitles.AbstractSubApi
|
import com.lagradost.cloudstream3.subtitles.AbstractSubApi
|
||||||
import com.lagradost.cloudstream3.subtitles.AbstractSubtitleEntities
|
import com.lagradost.cloudstream3.subtitles.AbstractSubtitleEntities
|
||||||
|
@ -166,19 +167,18 @@ class OpenSubtitlesApi(index: Int) : InAppAuthAPIManager(index), AbstractSubApi
|
||||||
val queryText = query.query.replace(" ", "+")
|
val queryText = query.query.replace(" ", "+")
|
||||||
val epNum = query.epNumber ?: 0
|
val epNum = query.epNumber ?: 0
|
||||||
val seasonNum = query.seasonNumber ?: 0
|
val seasonNum = query.seasonNumber ?: 0
|
||||||
val ans = getImdb(queryText)
|
val yearNum = query.year ?: 0
|
||||||
|
val tmdbprov = TmdbProvider()
|
||||||
var imdbId = ""
|
var imdbId = ""
|
||||||
var yearNum = 0
|
if (seasonNum == 0 && epNum == 0) { // applicable only for movies for now
|
||||||
if (ans[0] != "" && ans[1] != "" && seasonNum == 0 && epNum == 0) {
|
imdbId = tmdbprov.getImdb(queryText, yearNum)
|
||||||
imdbId = ans[0]
|
|
||||||
yearNum = ans[1].toInt()
|
|
||||||
}
|
}
|
||||||
val epQuery = if (epNum > 0) "&episode_number=$epNum" else ""
|
val epQuery = if (epNum > 0) "&episode_number=$epNum" else ""
|
||||||
val seasonQuery = if (seasonNum > 0) "&season_number=$seasonNum" else ""
|
val seasonQuery = if (seasonNum > 0) "&season_number=$seasonNum" else ""
|
||||||
val yearQuery = if (yearNum > 0) "&year=$yearNum" else ""
|
val yearQuery = if (yearNum > 0) "&year=$yearNum" else ""
|
||||||
|
|
||||||
val searchQueryUrl = when (imdbId != "") {
|
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"
|
true -> "$host/subtitles?imdb_id=$imdbId&languages=${fixedLang}$yearQuery$epQuery$seasonQuery"
|
||||||
false -> "$host/subtitles?query=$queryText&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
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getImdb(s: String): Array<String> {
|
|
||||||
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.
|
Process data returned from search.
|
||||||
Returns string url for the subtitle file.
|
Returns string url for the subtitle file.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue