Fix many build warnings/deprecations (#1478)

This commit is contained in:
Luna712
2025-01-26 13:25:39 -07:00
committed by GitHub
parent 642004db5a
commit 679f3651f8
18 changed files with 265 additions and 138 deletions

View File

@ -14,7 +14,8 @@ actual fun getContext(): Any? {
}
actual fun setContext(context: WeakReference<Any>) {
if (context.get() is Context) {
ctx = context as? WeakReference<Context>
val actualContext = context.get() as? Context
if (actualContext != null) {
ctx = WeakReference(actualContext)
}
}

View File

@ -382,37 +382,37 @@ fun mainPageOf(vararg elements: Pair<String, String>): List<MainPageData> {
return elements.map { (url, name) -> MainPageData(name = name, data = url) }
}
@Suppress("DEPRECATION")
fun newHomePageResponse(
name: String,
list: List<SearchResponse>,
hasNext: Boolean? = null,
): HomePageResponse {
@Suppress("DEPRECATION")
return HomePageResponse(
listOf(HomePageList(name, list)),
hasNext = hasNext ?: list.isNotEmpty()
)
}
@Suppress("DEPRECATION")
fun newHomePageResponse(
data: MainPageRequest,
list: List<SearchResponse>,
hasNext: Boolean? = null,
): HomePageResponse {
@Suppress("DEPRECATION")
return HomePageResponse(
listOf(HomePageList(data.name, list, data.horizontalImages)),
hasNext = hasNext ?: list.isNotEmpty()
)
}
@Suppress("DEPRECATION")
fun newHomePageResponse(list: HomePageList, hasNext: Boolean? = null): HomePageResponse {
@Suppress("DEPRECATION")
return HomePageResponse(listOf(list), hasNext = hasNext ?: list.list.isNotEmpty())
}
@Suppress("DEPRECATION")
fun newHomePageResponse(list: List<HomePageList>, hasNext: Boolean? = null): HomePageResponse {
@Suppress("DEPRECATION")
return HomePageResponse(list, hasNext = hasNext ?: list.any { it.list.isNotEmpty() })
}
@ -508,7 +508,6 @@ abstract class MainAPI {
open val mainPage = listOf(MainPageData("", "", false))
// @WorkerThread
@Suppress("DEPRECATION")
open suspend fun getMainPage(
page: Int,
request: MainPageRequest,
@ -817,8 +816,9 @@ data class SubtitleFile(val lang: String, val url: String)
* @property items List of [HomePageList] items.
* @property hasNext if there is a next page or not.
* */
data class HomePageResponse
@Deprecated("Use newHomePageResponse method", level = DeprecationLevel.WARNING)
data class HomePageResponse(
constructor(
val items: List<HomePageList>,
val hasNext: Boolean = false
)
@ -952,7 +952,6 @@ interface SearchResponse {
var quality: SearchQuality?
}
@Suppress("DEPRECATION")
fun MainAPI.newTorrentSearchResponse(
name: String,
url: String,
@ -960,6 +959,7 @@ fun MainAPI.newTorrentSearchResponse(
fix: Boolean = true,
initializer: TorrentSearchResponse.() -> Unit = { },
): TorrentSearchResponse {
@Suppress("DEPRECATION")
val builder = TorrentSearchResponse(
name = name,
url = if (fix) fixUrl(url) else url,
@ -972,7 +972,6 @@ fun MainAPI.newTorrentSearchResponse(
return builder
}
@Suppress("DEPRECATION")
fun MainAPI.newMovieSearchResponse(
name: String,
url: String,
@ -980,13 +979,13 @@ fun MainAPI.newMovieSearchResponse(
fix: Boolean = true,
initializer: MovieSearchResponse.() -> Unit = { },
): MovieSearchResponse {
@Suppress("DEPRECATION")
val builder = MovieSearchResponse(name, if (fix) fixUrl(url) else url, this.name, type)
builder.initializer()
return builder
}
@Suppress("DEPRECATION")
fun MainAPI.newLiveSearchResponse(
name: String,
url: String,
@ -994,6 +993,7 @@ fun MainAPI.newLiveSearchResponse(
fix: Boolean = true,
initializer: LiveSearchResponse.() -> Unit = { },
): LiveSearchResponse {
@Suppress("DEPRECATION")
val builder = LiveSearchResponse(
name = name,
url = if (fix) fixUrl(url) else url,
@ -1004,7 +1004,6 @@ fun MainAPI.newLiveSearchResponse(
return builder
}
@Suppress("DEPRECATION")
fun MainAPI.newTvSeriesSearchResponse(
name: String,
url: String,
@ -1012,13 +1011,13 @@ fun MainAPI.newTvSeriesSearchResponse(
fix: Boolean = true,
initializer: TvSeriesSearchResponse.() -> Unit = { },
): TvSeriesSearchResponse {
@Suppress("DEPRECATION")
val builder = TvSeriesSearchResponse(name, if (fix) fixUrl(url) else url, this.name, type)
builder.initializer()
return builder
}
@Suppress("DEPRECATION")
fun MainAPI.newAnimeSearchResponse(
name: String,
url: String,
@ -1026,6 +1025,7 @@ fun MainAPI.newAnimeSearchResponse(
fix: Boolean = true,
initializer: AnimeSearchResponse.() -> Unit = { },
): AnimeSearchResponse {
@Suppress("DEPRECATION")
val builder = AnimeSearchResponse(name, if (fix) fixUrl(url) else url, this.name, type)
builder.initializer()
@ -1089,8 +1089,9 @@ data class ActorData(
/** Data class of [SearchResponse] interface for Anime.
* @see newAnimeSearchResponse
* */
data class AnimeSearchResponse
@Deprecated("Use newAnimeSearchResponse", level = DeprecationLevel.WARNING)
data class AnimeSearchResponse(
constructor(
override val name: String,
override val url: String,
override val apiName: String,
@ -1108,7 +1109,6 @@ data class AnimeSearchResponse(
override var posterHeaders: Map<String, String>? = null,
) : SearchResponse
@Suppress("DEPRECATION")
fun AnimeSearchResponse.addDubStatus(status: DubStatus, episodes: Int? = null) {
this.dubStatus = dubStatus?.also { it.add(status) } ?: EnumSet.of(status)
if (this.type?.isMovieType() != true)
@ -1116,24 +1116,20 @@ fun AnimeSearchResponse.addDubStatus(status: DubStatus, episodes: Int? = null) {
this.episodes[status] = episodes
}
@Suppress("DEPRECATION")
fun AnimeSearchResponse.addDubStatus(isDub: Boolean, episodes: Int? = null) {
addDubStatus(if (isDub) DubStatus.Dubbed else DubStatus.Subbed, episodes)
}
@Suppress("DEPRECATION")
fun AnimeSearchResponse.addDub(episodes: Int?) {
if (episodes == null || episodes <= 0) return
addDubStatus(DubStatus.Dubbed, episodes)
}
@Suppress("DEPRECATION")
fun AnimeSearchResponse.addSub(episodes: Int?) {
if (episodes == null || episodes <= 0) return
addDubStatus(DubStatus.Subbed, episodes)
}
@Suppress("DEPRECATION")
fun AnimeSearchResponse.addDubStatus(
dubExist: Boolean,
subExist: Boolean,
@ -1147,7 +1143,6 @@ fun AnimeSearchResponse.addDubStatus(
addDubStatus(DubStatus.Subbed, subEpisodes)
}
@Suppress("DEPRECATION")
fun AnimeSearchResponse.addDubStatus(status: String, episodes: Int? = null) {
if (status.contains("(dub)", ignoreCase = true)) {
addDubStatus(DubStatus.Dubbed, episodes)
@ -1159,8 +1154,9 @@ fun AnimeSearchResponse.addDubStatus(status: String, episodes: Int? = null) {
/** Data class of [SearchResponse] interface for Torrent.
* @see newTorrentSearchResponse
* */
data class TorrentSearchResponse
@Deprecated("Use newTorrentSearchResponse", level = DeprecationLevel.WARNING)
data class TorrentSearchResponse(
constructor(
override val name: String,
override val url: String,
override val apiName: String,
@ -1175,8 +1171,9 @@ data class TorrentSearchResponse(
/** Data class of [SearchResponse] interface for Movies.
* @see newMovieSearchResponse
* */
data class MovieSearchResponse
@Deprecated("Use newMovieSearchResponse", level = DeprecationLevel.WARNING)
data class MovieSearchResponse(
constructor(
override val name: String,
override val url: String,
override val apiName: String,
@ -1186,14 +1183,15 @@ data class MovieSearchResponse(
var year: Int? = null,
override var id: Int? = null,
override var quality: SearchQuality? = null,
override var posterHeaders: Map<String, String>? = null,
override var posterHeaders: Map<String, String>? = null
) : SearchResponse
/** Data class of [SearchResponse] interface for Live streams.
* @see newLiveSearchResponse
* */
data class LiveSearchResponse
@Deprecated("Use newLiveSearchResponse", level = DeprecationLevel.WARNING)
data class LiveSearchResponse(
constructor(
override val name: String,
override val url: String,
override val apiName: String,
@ -1209,8 +1207,9 @@ data class LiveSearchResponse(
/** Data class of [SearchResponse] interface for Tv series.
* @see newTvSeriesSearchResponse
* */
data class TvSeriesSearchResponse
@Deprecated("Use newTvSeriesSearchResponse", level = DeprecationLevel.WARNING)
data class TvSeriesSearchResponse(
constructor(
override val name: String,
override val url: String,
override val apiName: String,
@ -1238,24 +1237,24 @@ data class TrailerData(
)
/** Abstract interface of LoadResponse responses
* @param name Title of the media, appears on result page.
* @param url Url of the media.
* @param apiName Plugin name, appears on result page.
* @param type [TvType] of the media .
* @param posterUrl Url of the media poster, appears on Top of result page.
* @param year Year of the media, appears on result page.
* @param plot Plot of the media, appears on result page.
* @param rating Rating of the media, appears on result page (0-10000).
* @param tags Tags of the media, appears on result page.
* @param duration duration of the media, appears on result page.
* @param trailers list of the media [TrailerData], used to load trailers.
* @param recommendations list of the [SearchResponse] related to media, appears on result page.
* @param actors list of the [ActorData] casted in the media, appears on result page.
* @param comingSoon determines if the media is released or coming soon.
* @param syncData Online sync services compatible with the media.
* @param posterHeaders headers map used by network request to get the poster.
* @param backgroundPosterUrl Url of the media background poster.
* @param contentRating content rating of the media, appears on result page.
* @property name Title of the media, appears on result page.
* @property url Url of the media.
* @property apiName Plugin name, appears on result page.
* @property type [TvType] of the media .
* @property posterUrl Url of the media poster, appears on Top of result page.
* @property year Year of the media, appears on result page.
* @property plot Plot of the media, appears on result page.
* @property rating Rating of the media, appears on result page (0-10000).
* @property tags Tags of the media, appears on result page.
* @property duration duration of the media, appears on result page.
* @property trailers list of the media [TrailerData], used to load trailers.
* @property recommendations list of the [SearchResponse] related to media, appears on result page.
* @property actors list of the [ActorData] casted in the media, appears on result page.
* @property comingSoon determines if the media is released or coming soon.
* @property syncData Online sync services compatible with the media.
* @property posterHeaders headers map used by network request to get the poster.
* @property backgroundPosterUrl Url of the media background poster.
* @property contentRating content rating of the media, appears on result page.
* */
interface LoadResponse {
var name: String
@ -1298,7 +1297,6 @@ interface LoadResponse {
return tryParseJson(idString) ?: return emptyMap()
}
@Suppress("DEPRECATION")
fun LoadResponse.isMovie(): Boolean {
return this.type.isMovieType() || this is MovieLoadResponse
}
@ -1665,8 +1663,9 @@ fun EpisodeResponse.addSeasonNames(names: List<SeasonData>) {
/** Data class of [LoadResponse] interface for Torrent.
* @see newTorrentLoadResponse
*/
data class TorrentLoadResponse
@Deprecated("Use newTorrentLoadResponse method", level = DeprecationLevel.WARNING)
data class TorrentLoadResponse(
constructor(
override var name: String,
override var url: String,
override var apiName: String,
@ -1692,6 +1691,8 @@ data class TorrentLoadResponse(
* Secondary constructor for backwards compatibility without contentRating.
* Remove this constructor after there is a new stable release and extensions are updated to support contentRating.
*/
@Suppress("DEPRECATION")
@Deprecated("Use newTorrentLoadResponse method with contentRating included", level = DeprecationLevel.WARNING)
constructor(
name: String,
url: String,
@ -1736,7 +1737,6 @@ data class TorrentLoadResponse(
)
}
@Suppress("DEPRECATION")
suspend fun MainAPI.newTorrentLoadResponse(
name: String,
url: String,
@ -1744,6 +1744,7 @@ suspend fun MainAPI.newTorrentLoadResponse(
torrent: String? = null,
initializer: suspend TorrentLoadResponse.() -> Unit = { }
): TorrentLoadResponse {
@Suppress("DEPRECATION")
val builder = TorrentLoadResponse(
name = name,
url = url,
@ -1761,9 +1762,9 @@ suspend fun MainAPI.newTorrentLoadResponse(
/** Data class of [LoadResponse] interface for Anime.
* @see newAnimeLoadResponse
* */
@Suppress("DEPRECATION")
data class AnimeLoadResponse
@Deprecated("Use newAnimeLoadResponse method", level = DeprecationLevel.WARNING)
data class AnimeLoadResponse(
constructor(
var engName: String? = null,
var japName: String? = null,
override var name: String,
@ -1823,6 +1824,8 @@ data class AnimeLoadResponse(
* Secondary constructor for backwards compatibility without contentRating.
* Remove this constructor after there is a new stable release and extensions are updated to support contentRating.
*/
@Suppress("DEPRECATION")
@Deprecated("Use newAnimeLoadResponse method with contentRating included", level = DeprecationLevel.WARNING)
constructor(
engName: String? = null,
japName: String? = null,
@ -1880,13 +1883,11 @@ data class AnimeLoadResponse(
/**
* If episodes already exist appends the list.
* */
@Suppress("DEPRECATION")
fun AnimeLoadResponse.addEpisodes(status: DubStatus, episodes: List<Episode>?) {
if (episodes.isNullOrEmpty()) return
this.episodes[status] = (this.episodes[status] ?: emptyList()) + episodes
}
@Suppress("DEPRECATION")
suspend fun MainAPI.newAnimeLoadResponse(
name: String,
url: String,
@ -1894,6 +1895,7 @@ suspend fun MainAPI.newAnimeLoadResponse(
comingSoonIfNone: Boolean = true,
initializer: suspend AnimeLoadResponse.() -> Unit = { },
): AnimeLoadResponse {
@Suppress("DEPRECATION")
val builder = AnimeLoadResponse(name = name, url = url, apiName = this.name, type = type)
builder.initializer()
if (comingSoonIfNone) {
@ -1910,8 +1912,9 @@ suspend fun MainAPI.newAnimeLoadResponse(
/** Data class of [LoadResponse] interface for Live streams.
* @see newLiveStreamLoadResponse
* */
data class LiveStreamLoadResponse
@Deprecated("Use newLiveStreamLoadResponse method", level = DeprecationLevel.WARNING)
data class LiveStreamLoadResponse(
constructor(
override var name: String,
override var url: String,
override var apiName: String,
@ -1938,6 +1941,8 @@ data class LiveStreamLoadResponse(
* Secondary constructor for backwards compatibility without contentRating.
* Remove this constructor after there is a new stable release and extensions are updated to support contentRating.
*/
@Suppress("DEPRECATION")
@Deprecated("Use newLiveStreamLoadResponse method with contentRating included", level = DeprecationLevel.WARNING)
constructor(
name: String,
url: String,
@ -1963,13 +1968,13 @@ data class LiveStreamLoadResponse(
)
}
@Suppress("DEPRECATION")
suspend fun MainAPI.newLiveStreamLoadResponse(
name: String,
url: String,
dataUrl: String,
initializer: suspend LiveStreamLoadResponse.() -> Unit = { }
): LiveStreamLoadResponse {
@Suppress("DEPRECATION")
val builder = LiveStreamLoadResponse(
name = name,
url = url,
@ -1984,8 +1989,9 @@ suspend fun MainAPI.newLiveStreamLoadResponse(
/** Data class of [LoadResponse] interface for Movies.
* @see newMovieLoadResponse
* */
data class MovieLoadResponse
@Deprecated("Use newMovieLoadResponse method", level = DeprecationLevel.WARNING)
data class MovieLoadResponse(
constructor(
override var name: String,
override var url: String,
override var apiName: String,
@ -2012,6 +2018,8 @@ data class MovieLoadResponse(
* Secondary constructor for backwards compatibility without contentRating.
* Remove this constructor after there is a new stable release and extensions are updated to support contentRating.
*/
@Suppress("DEPRECATION")
@Deprecated("Use newMovieLoadResponse method with contentRating included", level = DeprecationLevel.WARNING)
constructor(
name: String,
url: String,
@ -2037,7 +2045,6 @@ data class MovieLoadResponse(
)
}
@Suppress("DEPRECATION")
suspend fun <T> MainAPI.newMovieLoadResponse(
name: String,
url: String,
@ -2054,6 +2061,7 @@ suspend fun <T> MainAPI.newMovieLoadResponse(
initializer = initializer
)
val dataUrl = data?.toJson() ?: ""
@Suppress("DEPRECATION")
val builder = MovieLoadResponse(
name = name,
url = url,
@ -2066,7 +2074,6 @@ suspend fun <T> MainAPI.newMovieLoadResponse(
return builder
}
@Suppress("DEPRECATION")
suspend fun MainAPI.newMovieLoadResponse(
name: String,
url: String,
@ -2074,6 +2081,7 @@ suspend fun MainAPI.newMovieLoadResponse(
dataUrl: String,
initializer: suspend MovieLoadResponse.() -> Unit = { }
): MovieLoadResponse {
@Suppress("DEPRECATION")
val builder = MovieLoadResponse(
name = name,
url = url,
@ -2097,8 +2105,9 @@ suspend fun MainAPI.newMovieLoadResponse(
* @property runTime Episode runtime in seconds.
* @see newEpisode
* */
data class Episode
@Deprecated("Use newEpisode", level = DeprecationLevel.WARNING)
data class Episode(
constructor(
var data: String,
var name: String? = null,
var season: Int? = null,
@ -2113,6 +2122,8 @@ data class Episode(
* Secondary constructor for backwards compatibility without runTime.
* TODO Remove this constructor after there is a new stable release and extensions are updated to support runTime.
*/
@Suppress("DEPRECATION")
@Deprecated("Use newEpisode with runTime included", level = DeprecationLevel.WARNING)
constructor(
data: String,
name: String? = null,
@ -2127,26 +2138,24 @@ data class Episode(
)
}
@Suppress("DEPRECATION")
fun Episode.addDate(date: String?, format: String = "yyyy-MM-dd") {
try {
this.date = SimpleDateFormat(format)?.parse(date ?: return)?.time
this.date = SimpleDateFormat(format).parse(date ?: return)?.time
} catch (e: Exception) {
logError(e)
}
}
@Suppress("DEPRECATION")
fun Episode.addDate(date: Date?) {
this.date = date?.time
}
@Suppress("DEPRECATION")
fun MainAPI.newEpisode(
url: String,
initializer: Episode.() -> Unit = { },
fix: Boolean = true,
): Episode {
@Suppress("DEPRECATION")
val builder = Episode(
data = if (fix) fixUrl(url) else url
)
@ -2154,7 +2163,6 @@ fun MainAPI.newEpisode(
return builder
}
@Suppress("DEPRECATION")
fun <T> MainAPI.newEpisode(
data: T,
initializer: Episode.() -> Unit = { }
@ -2164,6 +2172,7 @@ fun <T> MainAPI.newEpisode(
initializer = initializer
) // just in case java is wack
@Suppress("DEPRECATION")
val builder = Episode(
data = data?.toJson() ?: throw ErrorLoadingException("invalid newEpisode")
)
@ -2196,9 +2205,9 @@ enum class SimklSyncServices(val originalName: String) {
/** Data class of [LoadResponse] interface for Tv series.
* @see newTvSeriesLoadResponse
* */
@Suppress("DEPRECATION")
data class TvSeriesLoadResponse
@Deprecated("Use newTvSeriesLoadResponse method", level = DeprecationLevel.WARNING)
data class TvSeriesLoadResponse(
constructor(
override var name: String,
override var url: String,
override var apiName: String,
@ -2250,6 +2259,8 @@ data class TvSeriesLoadResponse(
* Secondary constructor for backwards compatibility without contentRating.
* Remove this constructor after there is a new stable release and extensions are updated to support contentRating.
*/
@Suppress("DEPRECATION")
@Deprecated("Use newTvSeriesLoadResponse method with contentRating included", level = DeprecationLevel.WARNING)
constructor(
name: String,
url: String,
@ -2298,7 +2309,6 @@ data class TvSeriesLoadResponse(
)
}
@Suppress("DEPRECATION")
suspend fun MainAPI.newTvSeriesLoadResponse(
name: String,
url: String,
@ -2306,6 +2316,7 @@ suspend fun MainAPI.newTvSeriesLoadResponse(
episodes: List<Episode>,
initializer: suspend TvSeriesLoadResponse.() -> Unit = { }
): TvSeriesLoadResponse {
@Suppress("DEPRECATION")
val builder = TvSeriesLoadResponse(
name = name,
url = url,

View File

@ -26,25 +26,25 @@ class JsUnpacker(packedJS: String?) {
* @return the javascript unpacked or null.
*/
fun unpack(): String? {
val js = packedJS
val js = packedJS ?: return null
try {
var p =
Pattern.compile("""\}\s*\('(.*)',\s*(.*?),\s*(\d+),\s*'(.*?)'\.split\('\|'\)""", Pattern.DOTALL)
var m = p.matcher(js)
if (m.find() && m.groupCount() == 4) {
val payload = m.group(1).replace("\\'", "'")
val payload = m.group(1)?.replace("\\'", "'") ?: ""
val radixStr = m.group(2)
val countStr = m.group(3)
val symtab = m.group(4).split("\\|".toRegex()).toTypedArray()
val symtab = (m.group(4)?.split("\\|".toRegex()) ?: emptyList()).toTypedArray()
var radix = 36
var count = 0
try {
radix = radixStr.toInt()
} catch (e: Exception) {
radix = radixStr?.toIntOrNull() ?: radix
} catch (_: Exception) {
}
try {
count = countStr.toInt()
} catch (e: Exception) {
count = countStr?.toIntOrNull() ?: 0
} catch (_: Exception) {
}
if (symtab.size != count) {
throw Exception("Unknown p.a.c.k.e.r. encoding")
@ -56,12 +56,12 @@ class JsUnpacker(packedJS: String?) {
var replaceOffset = 0
while (m.find()) {
val word = m.group(0)
val x = unbase.unbase(word)
val x = if (word == null) 0 else unbase.unbase(word)
var value: String? = null
if (x < symtab.size && x >= 0) {
value = symtab[x]
}
if (value != null && value.isNotEmpty()) {
if (!value.isNullOrEmpty() && !word.isNullOrEmpty()) {
decoded.replace(m.start() + replaceOffset, m.end() + replaceOffset, value)
replaceOffset += value.length - word.length
}
@ -118,7 +118,7 @@ class JsUnpacker(packedJS: String?) {
}
/**
* @param packedJS javascript P.A.C.K.E.R. coded.
* @param packedJS javascript P.A.C.K.E.R. coded.
*/
init {
this.packedJS = packedJS