mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Implement IMDb duplicate title checking support
This commit is contained in:
parent
4f91641e80
commit
61439eb17f
3 changed files with 34 additions and 10 deletions
|
@ -26,6 +26,8 @@ import com.lagradost.nicehttp.RequestBodyTypes
|
|||
import okhttp3.Interceptor
|
||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import kotlin.math.absoluteValue
|
||||
|
@ -1246,6 +1248,16 @@ interface LoadResponse {
|
|||
return this.syncData[aniListIdPrefix]
|
||||
}
|
||||
|
||||
fun LoadResponse.getImdbId(): String? {
|
||||
val simklId = this.syncData[simklIdPrefix] ?: return null
|
||||
return try {
|
||||
val jsonObject = JSONObject(simklId)
|
||||
jsonObject.optString("Imdb")
|
||||
} catch (e: JSONException) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun LoadResponse.addMalId(id: Int?) {
|
||||
this.syncData[malIdPrefix] = (id ?: return).toString()
|
||||
this.addSimklId(SimklApi.Companion.SyncServices.Mal, id.toString())
|
||||
|
|
|
@ -25,6 +25,7 @@ import com.lagradost.cloudstream3.CommonActivity.getCastSession
|
|||
import com.lagradost.cloudstream3.CommonActivity.showToast
|
||||
import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer
|
||||
import com.lagradost.cloudstream3.LoadResponse.Companion.getAniListId
|
||||
import com.lagradost.cloudstream3.LoadResponse.Companion.getImdbId
|
||||
import com.lagradost.cloudstream3.LoadResponse.Companion.getMalId
|
||||
import com.lagradost.cloudstream3.LoadResponse.Companion.isMovie
|
||||
import com.lagradost.cloudstream3.metaproviders.SyncRedirector
|
||||
|
@ -830,6 +831,7 @@ class ResultViewModel2 : ViewModel() {
|
|||
R.string.duplicate_message_bookmarks,
|
||||
response.name,
|
||||
response.year,
|
||||
response.getImdbId(),
|
||||
getAllBookmarkedDataByWatchType()[status] ?: emptyList()
|
||||
) { shouldContinue: Boolean, duplicateId: Int? ->
|
||||
if (!shouldContinue) return@checkAndWarnDuplicates
|
||||
|
@ -852,7 +854,8 @@ class ResultViewModel2 : ViewModel() {
|
|||
response.url,
|
||||
response.apiName,
|
||||
response.type,
|
||||
response.posterUrl
|
||||
response.posterUrl,
|
||||
response.getImdbId()
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -899,6 +902,7 @@ class ResultViewModel2 : ViewModel() {
|
|||
R.string.duplicate_message_subscriptions,
|
||||
response.name,
|
||||
response.year,
|
||||
response.getImdbId(),
|
||||
getAllSubscriptions(),
|
||||
) { shouldContinue: Boolean, duplicateId: Int? ->
|
||||
if (!shouldContinue) {
|
||||
|
@ -924,7 +928,8 @@ class ResultViewModel2 : ViewModel() {
|
|||
response.url,
|
||||
response.apiName,
|
||||
response.type,
|
||||
response.posterUrl
|
||||
response.posterUrl,
|
||||
response.getImdbId()
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -960,6 +965,7 @@ class ResultViewModel2 : ViewModel() {
|
|||
R.string.duplicate_message_favorites,
|
||||
response.name,
|
||||
response.year,
|
||||
response.getImdbId(),
|
||||
getAllFavorites(),
|
||||
) { shouldContinue: Boolean, duplicateId: Int? ->
|
||||
if (!shouldContinue) {
|
||||
|
@ -984,7 +990,8 @@ class ResultViewModel2 : ViewModel() {
|
|||
response.url,
|
||||
response.apiName,
|
||||
response.type,
|
||||
response.posterUrl
|
||||
response.posterUrl,
|
||||
response.getImdbId()
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -1002,6 +1009,7 @@ class ResultViewModel2 : ViewModel() {
|
|||
message: Int,
|
||||
name: String,
|
||||
year: Int?,
|
||||
imdbId: String?,
|
||||
data: List<DataStoreHelper.BaseSearchResponse>,
|
||||
checkDuplicatesCallback: (shouldContinue: Boolean, duplicateId: Int?) -> Unit
|
||||
) {
|
||||
|
@ -1015,11 +1023,11 @@ class ResultViewModel2 : ViewModel() {
|
|||
return input.trim().replace("\\s+".toRegex(), " ")
|
||||
}
|
||||
|
||||
// TODO support checking IMDB ID rather than name + year when available
|
||||
val duplicateEntry = data.find {
|
||||
// Normalize both strings for comparison
|
||||
normalizeString(it.name) == normalizeString(name) && it.year == year
|
||||
imdbId != null && it.imdbId == imdbId ||
|
||||
normalizeString(it.name) == normalizeString(name) && it.year == year
|
||||
}
|
||||
|
||||
if (duplicateEntry == null || context == null) {
|
||||
checkDuplicatesCallback.invoke(true, null)
|
||||
return
|
||||
|
|
|
@ -360,6 +360,7 @@ object DataStoreHelper {
|
|||
@JsonProperty("apiName") override val apiName: String,
|
||||
@JsonProperty("type") override var type: TvType? = null,
|
||||
@JsonProperty("posterUrl") override var posterUrl: String?,
|
||||
@JsonProperty("imdbId") open val imdbId: String? = null,
|
||||
@JsonProperty("quality") override var quality: SearchQuality? = null,
|
||||
@JsonProperty("posterHeaders") override var posterHeaders: Map<String, String>? = null
|
||||
) : SearchResponse
|
||||
|
@ -375,9 +376,10 @@ object DataStoreHelper {
|
|||
override val apiName: String,
|
||||
override var type: TvType?,
|
||||
override var posterUrl: String?,
|
||||
override var imdbId: String? = null,
|
||||
override var quality: SearchQuality? = null,
|
||||
override var posterHeaders: Map<String, String>? = null
|
||||
) : BaseSearchResponse(id, name, year, url, apiName, type, posterUrl, quality, posterHeaders) {
|
||||
) : BaseSearchResponse(id, name, year, url, apiName, type, posterUrl, imdbId, quality, posterHeaders) {
|
||||
fun toLibraryItem(): SyncAPI.LibraryItem? {
|
||||
return SyncAPI.LibraryItem(
|
||||
name,
|
||||
|
@ -402,9 +404,10 @@ object DataStoreHelper {
|
|||
override val apiName: String,
|
||||
override var type: TvType?,
|
||||
override var posterUrl: String?,
|
||||
override var imdbId: String? = null,
|
||||
override var quality: SearchQuality? = null,
|
||||
override var posterHeaders: Map<String, String>? = null
|
||||
) : BaseSearchResponse(id, name, year, url, apiName, type, posterUrl, quality, posterHeaders) {
|
||||
) : BaseSearchResponse(id, name, year, url, apiName, type, posterUrl, imdbId, quality, posterHeaders) {
|
||||
fun toLibraryItem(id: String): SyncAPI.LibraryItem {
|
||||
return SyncAPI.LibraryItem(
|
||||
name,
|
||||
|
@ -429,9 +432,10 @@ object DataStoreHelper {
|
|||
override val apiName: String,
|
||||
override var type: TvType?,
|
||||
override var posterUrl: String?,
|
||||
override var imdbId: String? = null,
|
||||
override var quality: SearchQuality? = null,
|
||||
override var posterHeaders: Map<String, String>? = null
|
||||
) : BaseSearchResponse(id, name, year, url, apiName, type, posterUrl, quality, posterHeaders) {
|
||||
) : BaseSearchResponse(id, name, year, url, apiName, type, posterUrl, imdbId, quality, posterHeaders) {
|
||||
fun toLibraryItem(): SyncAPI.LibraryItem? {
|
||||
return SyncAPI.LibraryItem(
|
||||
name,
|
||||
|
@ -460,7 +464,7 @@ object DataStoreHelper {
|
|||
override var posterUrl: String?,
|
||||
override var quality: SearchQuality? = null,
|
||||
override var posterHeaders: Map<String, String>? = null
|
||||
) : BaseSearchResponse(id, name, null, url, apiName, type, posterUrl, quality, posterHeaders)
|
||||
) : BaseSearchResponse(id, name, null, url, apiName, type, posterUrl, null, quality, posterHeaders)
|
||||
|
||||
/**
|
||||
* A datastore wide account for future implementations of a multiple account system
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue