Depend on LoadResponse Directly

This commit is contained in:
KingLucius 2024-05-10 17:50:35 +03:00
parent 0556bff907
commit 628d1e7bb5
10 changed files with 54 additions and 51 deletions

View file

@ -1,5 +1,6 @@
package com.lagradost.cloudstream3.subtitles package com.lagradost.cloudstream3.subtitles
import com.lagradost.cloudstream3.LoadResponse
import com.lagradost.cloudstream3.TvType import com.lagradost.cloudstream3.TvType
class AbstractSubtitleEntities { class AbstractSubtitleEntities {
@ -19,8 +20,11 @@ class AbstractSubtitleEntities {
data class SubtitleSearch( data class SubtitleSearch(
var query: String = "", var query: String = "",
var imdb: String? = null,
var lang: String? = null, var lang: String? = null,
var imdbId: String? = null,
var tmdbId: Int? = null,
var malId: Int? = null,
var aniListId: Int? = null,
var epNumber: Int? = null, var epNumber: Int? = null,
var seasonNumber: Int? = null, var seasonNumber: Int? = null,
var year: Int? = null var year: Int? = null

View file

@ -98,7 +98,7 @@ class IndexSubtitleApi : AbstractSubApi {
} }
override suspend fun search(query: AbstractSubtitleEntities.SubtitleSearch): List<AbstractSubtitleEntities.SubtitleEntity> { override suspend fun search(query: AbstractSubtitleEntities.SubtitleSearch): List<AbstractSubtitleEntities.SubtitleEntity> {
val imdbId = query.imdb?.replace("tt", "")?.toLong() ?: 0 val imdbId = query.imdbId?.replace("tt", "")?.toLong() ?: 0
val lang = query.lang val lang = query.lang
val queryLang = SubtitleHelper.fromTwoLettersToLanguage(lang.toString()) val queryLang = SubtitleHelper.fromTwoLettersToLanguage(lang.toString())
val queryText = query.query val queryText = query.query

View file

@ -185,7 +185,7 @@ class OpenSubtitlesApi(index: Int) : InAppAuthAPIManager(index), AbstractSubApi
throwIfCantDoRequest() throwIfCantDoRequest()
val fixedLang = fixLanguage(query.lang) val fixedLang = fixLanguage(query.lang)
val imdbId = query.imdb?.replace("tt", "")?.toInt() ?: 0 val imdbId = query.imdbId?.replace("tt", "")?.toInt() ?: 0
val queryText = query.query val queryText = query.query
val epNum = query.epNumber ?: 0 val epNum = query.epNumber ?: 0
val seasonNum = query.seasonNumber ?: 0 val seasonNum = query.seasonNumber ?: 0

View file

@ -6,7 +6,6 @@ import com.lagradost.cloudstream3.app
import com.lagradost.cloudstream3.subtitles.AbstractSubProvider import com.lagradost.cloudstream3.subtitles.AbstractSubProvider
import com.lagradost.cloudstream3.subtitles.AbstractSubtitleEntities import com.lagradost.cloudstream3.subtitles.AbstractSubtitleEntities
import com.lagradost.cloudstream3.subtitles.SubtitleResource import com.lagradost.cloudstream3.subtitles.SubtitleResource
import com.lagradost.cloudstream3.utils.AppUtils
class SubDL : AbstractSubProvider { class SubDL : AbstractSubProvider {
//API Documentation: https://subdl.com/api-doc //API Documentation: https://subdl.com/api-doc
@ -21,20 +20,25 @@ class SubDL : AbstractSubProvider {
override suspend fun search(query: AbstractSubtitleEntities.SubtitleSearch): List<AbstractSubtitleEntities.SubtitleEntity>? { override suspend fun search(query: AbstractSubtitleEntities.SubtitleSearch): List<AbstractSubtitleEntities.SubtitleEntity>? {
val imdbId = query.imdb
val queryText = query.query val queryText = query.query
val epNum = query.epNumber ?: 0 val epNum = query.epNumber ?: 0
val seasonNum = query.seasonNumber ?: 0 val seasonNum = query.seasonNumber ?: 0
val yearNum = query.year ?: 0 val yearNum = query.year ?: 0
val idQuery = when {
query.imdbId != null -> "&imdb_id=${query.imdbId}"
query.tmdbId != null -> "&tmdb_id=${query.tmdbId}"
else -> null
}
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 (idQuery) {
//Use imdb_id to search if its valid //Use imdb/tmdb id to search if its valid
null -> "$APIENDPOINT?api_key=$APIKEY&film_name=$queryText&languages=${query.lang}$epQuery$seasonQuery$yearQuery" null -> "$APIENDPOINT?api_key=$APIKEY&film_name=$queryText&languages=${query.lang}$epQuery$seasonQuery$yearQuery"
else -> "$APIENDPOINT?api_key=$APIKEY&imdb_id=$imdbId&languages=${query.lang}$epQuery$seasonQuery$yearQuery" else -> "$APIENDPOINT?api_key=$APIKEY$idQuery&languages=${query.lang}$epQuery$seasonQuery$yearQuery"
} }
val req = app.get( val req = app.get(
@ -44,24 +48,13 @@ class SubDL : AbstractSubProvider {
) )
) )
if (!req.isSuccessful) { return req.parsedSafe<ApiResponse>()?.subtitles?.map { subtitle ->
return null
}
val results = mutableListOf<AbstractSubtitleEntities.SubtitleEntity>()
AppUtils.tryParseJson<ApiResponse>(req.text)?.let {resp ->
resp.subtitles?.forEach { subtitle ->
val name = subtitle.releaseName val name = subtitle.releaseName
val lang = subtitle.lang.replaceFirstChar { it.uppercase() } val lang = subtitle.lang.replaceFirstChar { it.uppercase() }
val resEpNum = subtitle.episode ?: query.epNumber val resEpNum = subtitle.episode ?: query.epNumber
val resSeasonNum = subtitle.season ?: query.seasonNumber val resSeasonNum = subtitle.season ?: query.seasonNumber
val year = resp.results?.firstOrNull()?.year ?: query.year
val type = if ((resSeasonNum ?: 0) > 0) TvType.TvSeries else TvType.Movie val type = if ((resSeasonNum ?: 0) > 0) TvType.TvSeries else TvType.Movie
results.add(
AbstractSubtitleEntities.SubtitleEntity( AbstractSubtitleEntities.SubtitleEntity(
idPrefix = this.idPrefix, idPrefix = this.idPrefix,
name = name, name = name,
@ -71,15 +64,10 @@ class SubDL : AbstractSubProvider {
source = this.name, source = this.name,
epNumber = resEpNum, epNumber = resEpNum,
seasonNumber = resSeasonNum, seasonNumber = resSeasonNum,
year = year,
)
) )
} }
} }
return results
}
override suspend fun SubtitleResource.getResources(data: AbstractSubtitleEntities.SubtitleEntity) { override suspend fun SubtitleResource.getResources(data: AbstractSubtitleEntities.SubtitleEntity) {
this.addZipUrl(data.data) { name, _ -> this.addZipUrl(data.data) { name, _ ->
name name

View file

@ -32,6 +32,7 @@ import com.lagradost.cloudstream3.CommonActivity.keyEventListener
import com.lagradost.cloudstream3.CommonActivity.playerEventListener import com.lagradost.cloudstream3.CommonActivity.playerEventListener
import com.lagradost.cloudstream3.CommonActivity.screenHeight import com.lagradost.cloudstream3.CommonActivity.screenHeight
import com.lagradost.cloudstream3.CommonActivity.screenWidth import com.lagradost.cloudstream3.CommonActivity.screenWidth
import com.lagradost.cloudstream3.LoadResponse
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.databinding.PlayerCustomLayoutBinding import com.lagradost.cloudstream3.databinding.PlayerCustomLayoutBinding
import com.lagradost.cloudstream3.databinding.SubtitleOffsetBinding import com.lagradost.cloudstream3.databinding.SubtitleOffsetBinding
@ -177,7 +178,7 @@ open class FullScreenPlayer : AbstractPlayerFragment() {
open fun openOnlineSubPicker( open fun openOnlineSubPicker(
context: Context, context: Context,
imdbId: String?, loadResponse: LoadResponse?,
dismissCallback: (() -> Unit) dismissCallback: (() -> Unit)
) { ) {
throw NotImplementedError() throw NotImplementedError()

View file

@ -25,6 +25,10 @@ import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.APIHolder.getApiFromNameNull import com.lagradost.cloudstream3.APIHolder.getApiFromNameNull
import com.lagradost.cloudstream3.AcraApplication.Companion.setKey import com.lagradost.cloudstream3.AcraApplication.Companion.setKey
import com.lagradost.cloudstream3.CommonActivity.showToast import com.lagradost.cloudstream3.CommonActivity.showToast
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.getTMDbId
import com.lagradost.cloudstream3.databinding.DialogOnlineSubtitlesBinding import com.lagradost.cloudstream3.databinding.DialogOnlineSubtitlesBinding
import com.lagradost.cloudstream3.databinding.FragmentPlayerBinding import com.lagradost.cloudstream3.databinding.FragmentPlayerBinding
import com.lagradost.cloudstream3.databinding.PlayerSelectSourceAndSubsBinding import com.lagradost.cloudstream3.databinding.PlayerSelectSourceAndSubsBinding
@ -39,7 +43,6 @@ import com.lagradost.cloudstream3.ui.player.PlayerSubtitleHelper.Companion.toSub
import com.lagradost.cloudstream3.ui.player.source_priority.QualityDataHelper import com.lagradost.cloudstream3.ui.player.source_priority.QualityDataHelper
import com.lagradost.cloudstream3.ui.player.source_priority.QualityProfileDialog import com.lagradost.cloudstream3.ui.player.source_priority.QualityProfileDialog
import com.lagradost.cloudstream3.ui.result.* import com.lagradost.cloudstream3.ui.result.*
import com.lagradost.cloudstream3.ui.settings.Globals
import com.lagradost.cloudstream3.ui.settings.Globals.EMULATOR import com.lagradost.cloudstream3.ui.settings.Globals.EMULATOR
import com.lagradost.cloudstream3.ui.settings.Globals.TV import com.lagradost.cloudstream3.ui.settings.Globals.TV
import com.lagradost.cloudstream3.ui.settings.Globals.isLayout import com.lagradost.cloudstream3.ui.settings.Globals.isLayout
@ -286,7 +289,7 @@ class GeneratorPlayer : FullScreenPlayer() {
} }
override fun openOnlineSubPicker( override fun openOnlineSubPicker(
context: Context, imdbId: String?, dismissCallback: (() -> Unit) context: Context, loadResponse: LoadResponse?, dismissCallback: (() -> Unit)
) { ) {
val providers = subsProviders val providers = subsProviders
val isSingleProvider = subsProviders.size == 1 val isSingleProvider = subsProviders.size == 1
@ -379,6 +382,7 @@ class GeneratorPlayer : FullScreenPlayer() {
} }
val currentTempMeta = getMetaData() val currentTempMeta = getMetaData()
// bruh idk why it is not correct // bruh idk why it is not correct
val color = ColorStateList.valueOf(context.colorFromAttribute(R.attr.colorAccent)) val color = ColorStateList.valueOf(context.colorFromAttribute(R.attr.colorAccent))
binding.searchLoadingBar.progressTintList = color binding.searchLoadingBar.progressTintList = color
@ -426,7 +430,10 @@ class GeneratorPlayer : FullScreenPlayer() {
val search = val search =
AbstractSubtitleEntities.SubtitleSearch( AbstractSubtitleEntities.SubtitleSearch(
query = query ?: return@ioSafe, query = query ?: return@ioSafe,
imdb = imdbId ?: currentTempMeta.imdbId, imdbId = loadResponse?.getImdbId(),
tmdbId = loadResponse?.getTMDbId()?.toInt(),
malId = loadResponse?.getMalId()?.toInt(),
aniListId = loadResponse?.getAniListId()?.toInt(),
epNumber = currentTempMeta.episode, epNumber = currentTempMeta.episode,
seasonNumber = currentTempMeta.season, seasonNumber = currentTempMeta.season,
lang = currentLanguageTwoLetters.ifBlank { null }, lang = currentLanguageTwoLetters.ifBlank { null },
@ -635,6 +642,8 @@ class GeneratorPlayer : FullScreenPlayer() {
} }
if (subsProvidersIsActive) { if (subsProvidersIsActive) {
val currentLoadResponse = viewModel.getLoadResponse()
val loadFromOpenSubsFooter: TextView = layoutInflater.inflate( val loadFromOpenSubsFooter: TextView = layoutInflater.inflate(
R.layout.sort_bottom_footer_add_choice, null R.layout.sort_bottom_footer_add_choice, null
) as TextView ) as TextView
@ -645,7 +654,7 @@ class GeneratorPlayer : FullScreenPlayer() {
loadFromOpenSubsFooter.setOnClickListener { loadFromOpenSubsFooter.setOnClickListener {
shouldDismiss = false shouldDismiss = false
sourceDialog.dismissSafe(activity) sourceDialog.dismissSafe(activity)
openOnlineSubPicker(it.context, null) { openOnlineSubPicker(it.context, currentLoadResponse) {
dismiss() dismiss()
} }
} }

View file

@ -5,6 +5,7 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.lagradost.cloudstream3.LoadResponse
import com.lagradost.cloudstream3.mvvm.Resource import com.lagradost.cloudstream3.mvvm.Resource
import com.lagradost.cloudstream3.mvvm.launchSafe import com.lagradost.cloudstream3.mvvm.launchSafe
import com.lagradost.cloudstream3.mvvm.logError import com.lagradost.cloudstream3.mvvm.logError
@ -111,6 +112,9 @@ class PlayerGeneratorViewModel : ViewModel() {
} }
} }
} }
fun getLoadResponse(): LoadResponse? {
return normalSafeApiCall { (generator as? RepoLinkGenerator?)?.page }
}
fun getMeta(): Any? { fun getMeta(): Any? {
return normalSafeApiCall { generator?.getCurrent() } return normalSafeApiCall { generator?.getCurrent() }

View file

@ -51,7 +51,6 @@ data class ResultEpisode(
/** Sum of all previous season episode counts + episode */ /** Sum of all previous season episode counts + episode */
val totalEpisodeIndex: Int? = null, val totalEpisodeIndex: Int? = null,
val airDate: Long? = null, val airDate: Long? = null,
val imdbId: String? = null,
) )
fun ResultEpisode.getRealPosition(): Long { fun ResultEpisode.getRealPosition(): Long {
@ -88,7 +87,6 @@ fun buildResultEpisode(
parentId: Int, parentId: Int,
totalEpisodeIndex: Int? = null, totalEpisodeIndex: Int? = null,
airDate: Long? = null, airDate: Long? = null,
imdbId: String? = null,
): ResultEpisode { ): ResultEpisode {
val posDur = getViewPos(id) val posDur = getViewPos(id)
val videoWatchState = getVideoWatchState(id) ?: VideoWatchState.None val videoWatchState = getVideoWatchState(id) ?: VideoWatchState.None
@ -113,7 +111,6 @@ fun buildResultEpisode(
videoWatchState, videoWatchState,
totalEpisodeIndex, totalEpisodeIndex,
airDate, airDate,
imdbId,
) )
} }

View file

@ -12,6 +12,7 @@ import androidx.core.view.isGone
import androidx.core.view.isVisible import androidx.core.view.isVisible
import com.lagradost.cloudstream3.CommonActivity.screenHeight import com.lagradost.cloudstream3.CommonActivity.screenHeight
import com.lagradost.cloudstream3.CommonActivity.screenWidth import com.lagradost.cloudstream3.CommonActivity.screenWidth
import com.lagradost.cloudstream3.LoadResponse
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.ui.player.CSPlayerEvent import com.lagradost.cloudstream3.ui.player.CSPlayerEvent
import com.lagradost.cloudstream3.ui.player.PlayerEventSource import com.lagradost.cloudstream3.ui.player.PlayerEventSource
@ -110,7 +111,7 @@ open class ResultTrailerPlayer : ResultFragmentPhone() {
override fun openOnlineSubPicker( override fun openOnlineSubPicker(
context: Context, context: Context,
imdbId: String?, loadResponse: LoadResponse?,
dismissCallback: () -> Unit dismissCallback: () -> Unit
) { ) {
} }

View file

@ -2363,7 +2363,6 @@ class ResultViewModel2 : ViewModel() {
loadResponse.type, loadResponse.type,
mainId, mainId,
null, null,
imdbId = loadResponse.getImdbId(),
) )
) )
} }