trailers fix + crash fix

This commit is contained in:
reduplicated 2022-08-25 03:59:20 +02:00
parent abeda3e758
commit 7a6d16d2c1
12 changed files with 91 additions and 33 deletions

View file

@ -107,7 +107,7 @@ dependencies {
testImplementation 'org.json:json:20180813'
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'androidx.appcompat:appcompat:1.4.2' // need target 32 for 1.5.0
// dont change this to 1.6.0 it looks ugly af
implementation 'com.google.android.material:material:1.5.0'
@ -194,7 +194,7 @@ dependencies {
//implementation 'com.github.HaarigerHarald:android-youtubeExtractor:master-SNAPSHOT'
// newpipe yt
implementation 'com.github.recloudstream:NewPipeExtractor:master-SNAPSHOT'
implementation 'com.github.recloudstream:NewPipeExtractor:0.22.1'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
// Library/extensions searching with Levenshtein distance

View file

@ -236,8 +236,8 @@ object APIHolder {
val defaultSet = default.map { it.toString() }.toSet()
val currentPrefMedia = try {
PreferenceManager.getDefaultSharedPreferences(this)
.getStringSet(this.getString(R.string.prefer_media_type_key), defaultSet)
?.mapNotNull { it.toIntOrNull() ?: return@mapNotNull null }
.getStringSet(this.getString(R.string.prefer_media_type_key), defaultSet)
?.mapNotNull { it.toIntOrNull() ?: return@mapNotNull null }
} catch (e: Throwable) {
null
} ?: default
@ -891,8 +891,11 @@ data class TvSeriesSearchResponse(
) : SearchResponse
data class TrailerData(
var mirros: List<ExtractorLink>,
var subtitles: List<SubtitleFile> = emptyList(),
val extractorUrl: String,
val referer: String?,
val raw: Boolean,
//var mirros: List<ExtractorLink>,
//var subtitles: List<SubtitleFile> = emptyList(),
)
interface LoadResponse {
@ -971,7 +974,8 @@ interface LoadResponse {
addRaw: Boolean = false
) {
if (!isTrailersEnabled || trailerUrl.isNullOrBlank()) return
val links = arrayListOf<ExtractorLink>()
this.trailers.add(TrailerData(trailerUrl, referer, addRaw))
/*val links = arrayListOf<ExtractorLink>()
val subs = arrayListOf<SubtitleFile>()
if (!loadExtractor(
trailerUrl,
@ -995,12 +999,13 @@ interface LoadResponse {
)
} else {
this.trailers.add(TrailerData(links, subs))
}
}*/
}
/*
fun LoadResponse.addTrailer(newTrailers: List<ExtractorLink>) {
trailers.addAll(newTrailers.map { TrailerData(listOf(it)) })
}
}*/
suspend fun LoadResponse.addTrailer(
trailerUrls: List<String>?,
@ -1008,7 +1013,8 @@ interface LoadResponse {
addRaw: Boolean = false
) {
if (!isTrailersEnabled || trailerUrls == null) return
val trailers = trailerUrls.filter { it.isNotBlank() }.apmap { trailerUrl ->
trailers.addAll(trailerUrls.map { TrailerData(it, referer, addRaw) })
/*val trailers = trailerUrls.filter { it.isNotBlank() }.apmap { trailerUrl ->
val links = arrayListOf<ExtractorLink>()
val subs = arrayListOf<SubtitleFile>()
if (!loadExtractor(
@ -1031,7 +1037,7 @@ interface LoadResponse {
links to subs
}
}.map { (links, subs) -> TrailerData(links, subs) }
this.trailers.addAll(trailers)
this.trailers.addAll(trailers)*/
}
fun LoadResponse.addImdbId(id: String?) {

View file

@ -127,8 +127,8 @@ fun CoroutineScope.launchSafe(
val obj: suspend CoroutineScope.() -> Unit = {
try {
block()
} catch (e: Exception) {
logError(e)
} catch (throwable: Throwable) {
logError(throwable)
}
}

View file

@ -84,8 +84,8 @@ object RepositoryManager {
// Normal parsed function not working?
// return response.parsedSafe()
tryParseJson<Array<SitePlugin>>(response.text)?.toList() ?: emptyList()
} catch (e : Exception) {
logError(e)
} catch (t : Throwable) {
logError(t)
emptyList()
}
}

View file

@ -279,8 +279,8 @@ class SelectSourceController(val view: ImageView, val activity: ControllerActivi
val currentPosition = remoteMediaClient?.approximateStreamPosition
if (currentDuration != null && currentPosition != null)
DataStoreHelper.setViewPos(epData.id, currentPosition, currentDuration)
} catch (e : Exception) {
logError(e)
} catch (t : Throwable) {
logError(t)
}
if (itemCount != null && itemCount - currentIdIndex == 1 && !isLoadingMore) {

View file

@ -148,10 +148,10 @@ class DownloadHeaderAdapter(
),
mbString
)
} catch (e : Exception) {
} catch (t : Throwable) {
// you probably formatted incorrectly
extraInfo.text = "Error"
logError(e)
logError(t)
}

View file

@ -112,9 +112,9 @@ class DownloadViewModel : ViewModel() {
_usedBytes.postValue(localTotalBytes - localBytesAvailable - localDownloadedBytes)
_availableBytes.postValue(localBytesAvailable)
_downloadBytes.postValue(localDownloadedBytes)
} catch (e : Exception) {
} catch (t : Throwable) {
_downloadBytes.postValue(0)
logError(e)
logError(t)
}
_headerCards.postValue(visual)

View file

@ -304,6 +304,11 @@ fun SelectPopup.getOptions(context: Context): List<String> {
}
}
data class ExtractedTrailerData(
var mirros: List<ExtractorLink>,
var subtitles: List<SubtitleFile> = emptyList(),
)
class ResultViewModel2 : ViewModel() {
private var currentResponse: LoadResponse? = null
@ -349,9 +354,9 @@ class ResultViewModel2 : ViewModel() {
MutableLiveData(Some.None)
val episodesCountText: LiveData<Some<UiText>> = _episodesCountText
private val _trailers: MutableLiveData<List<TrailerData>> = MutableLiveData(mutableListOf())
val trailers: LiveData<List<TrailerData>> = _trailers
private val _trailers: MutableLiveData<List<ExtractedTrailerData>> =
MutableLiveData(mutableListOf())
val trailers: LiveData<List<ExtractedTrailerData>> = _trailers
private val _dubSubSelections: MutableLiveData<List<Pair<UiText?, DubStatus>>> =
MutableLiveData(emptyList())
@ -1784,12 +1789,58 @@ class ResultViewModel2 : ViewModel() {
return ResumeWatchingStatus(progress = progress, isMovie = isMovie, result = episode)
}
private fun loadTrailers(loadResponse: LoadResponse) = ioSafe {
_trailers.postValue(getTrailers(loadResponse, 3)) // we dont want to fetch too many trailers
}
private suspend fun getTrailers(
loadResponse: LoadResponse,
limit: Int = 0
): List<ExtractedTrailerData> =
coroutineScope {
var currentCount = 0
return@coroutineScope loadResponse.trailers.apmap { trailerData ->
try {
val links = arrayListOf<ExtractorLink>()
val subs = arrayListOf<SubtitleFile>()
if (!loadExtractor(
trailerData.extractorUrl,
trailerData.referer,
{ subs.add(it) },
{ links.add(it) }) && trailerData.raw
) {
arrayListOf(
ExtractorLink(
"",
"Trailer",
trailerData.extractorUrl,
trailerData.referer ?: "",
Qualities.Unknown.value,
trailerData.extractorUrl.contains(".m3u8")
)
) to arrayListOf()
} else {
links to subs
}.also { (extractor, _) ->
if (extractor.isNotEmpty() && limit != 0) {
currentCount++
if (currentCount >= limit) {
cancel()
}
}
}
} catch (e: Throwable) {
logError(e)
null
}
}.filterNotNull().map { (links, subs) -> ExtractedTrailerData(links, subs) }
}
// this instantly updates the metadata on the page
private fun postPage(loadResponse: LoadResponse, apiRepository: APIRepository) {
_recommendations.postValue(loadResponse.recommendations ?: emptyList())
_page.postValue(Resource.Success(loadResponse.toResultData(apiRepository)))
_trailers.postValue(loadResponse.trailers)
}
fun hasLoaded() = currentResponse != null
@ -1914,6 +1965,7 @@ class ResultViewModel2 : ViewModel() {
)
)
loadTrailers(data.value)
postSuccessful(
data.value,
updateEpisodes = true,

View file

@ -246,8 +246,8 @@ class SyncViewModel : ViewModel() {
if (syncs.containsKey(aniListApi.idPrefix)) {
try { // swap can throw error
Collections.swap(current, current.indexOfFirst { it.first == aniListApi.idPrefix }, 0)
} catch (e : Exception) {
logError(e)
} catch (t : Throwable) {
logError(t)
}
}

View file

@ -136,8 +136,8 @@ object UIHelper {
navigation, arguments
)
}
} catch (e : Exception) {
logError(e)
} catch (t : Throwable) {
logError(t)
}
}

View file

@ -1612,8 +1612,8 @@ object VideoDownloadManager {
.mapIndexed { index, any -> DownloadQueueResumePackage(index, any) }
.toTypedArray()
setKey(KEY_RESUME_QUEUE_PACKAGES, dQueue)
} catch (e : Exception) {
logError(e)
} catch (t : Throwable) {
logError(t)
}
}

View file

@ -53,8 +53,8 @@ class CenterZoomLayoutManager : LinearLayoutManager {
largestTag = tag
}
}
} catch (e : Exception) {
logError(e)
} catch (t : Throwable) {
logError(t)
}
}
}