2022-08-06 15:48:00 +00:00
|
|
|
package com.lagradost.cloudstream3.plugins
|
2022-08-04 10:51:11 +00:00
|
|
|
|
2022-08-06 15:48:00 +00:00
|
|
|
import android.content.Context
|
|
|
|
import android.content.res.Resources
|
|
|
|
import kotlin.Throws
|
2022-08-09 08:33:16 +00:00
|
|
|
import com.lagradost.cloudstream3.MainAPI
|
|
|
|
import com.lagradost.cloudstream3.APIHolder
|
|
|
|
import com.lagradost.cloudstream3.utils.ExtractorApi
|
|
|
|
import com.lagradost.cloudstream3.utils.extractorApis
|
|
|
|
import android.util.Log
|
2022-08-09 15:19:26 +00:00
|
|
|
import com.fasterxml.jackson.annotation.JsonProperty
|
2022-08-09 08:33:16 +00:00
|
|
|
|
|
|
|
const val PLUGIN_TAG = "PluginInstance"
|
2022-08-04 10:51:11 +00:00
|
|
|
|
2022-08-06 15:48:00 +00:00
|
|
|
abstract class Plugin {
|
2022-08-04 10:51:11 +00:00
|
|
|
/**
|
|
|
|
* Called when your Plugin is loaded
|
|
|
|
* @param context Context
|
|
|
|
*/
|
2022-08-06 15:48:00 +00:00
|
|
|
@Throws(Throwable::class)
|
2022-08-07 23:03:54 +00:00
|
|
|
open fun load(context: Context) {
|
2022-08-04 10:51:11 +00:00
|
|
|
}
|
|
|
|
|
2022-08-09 08:33:16 +00:00
|
|
|
/**
|
|
|
|
* Called when your Plugin is being unloaded
|
|
|
|
*/
|
|
|
|
@Throws(Throwable::class)
|
|
|
|
open fun beforeUnload() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to register providers instances of MainAPI
|
|
|
|
* @param element MainAPI provider you want to register
|
|
|
|
*/
|
|
|
|
fun registerMainAPI(element: MainAPI) {
|
|
|
|
Log.i(PLUGIN_TAG, "Adding ${element.name} (${element.mainUrl}) MainAPI")
|
2022-08-09 15:19:26 +00:00
|
|
|
element.sourcePlugin = this.__filename
|
2022-08-14 21:34:47 +00:00
|
|
|
// Race condition causing which would case duplicates if not for distinctBy
|
2022-08-09 08:33:16 +00:00
|
|
|
APIHolder.allProviders.add(element)
|
2022-08-09 13:44:32 +00:00
|
|
|
APIHolder.addPluginMapping(element)
|
2022-08-09 08:33:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to register extractor instances of ExtractorApi
|
|
|
|
* @param element ExtractorApi provider you want to register
|
|
|
|
*/
|
|
|
|
fun registerExtractorAPI(element: ExtractorApi) {
|
|
|
|
Log.i(PLUGIN_TAG, "Adding ${element.name} (${element.mainUrl}) ExtractorApi")
|
2022-08-09 15:19:26 +00:00
|
|
|
element.sourcePlugin = this.__filename
|
2022-08-09 08:33:16 +00:00
|
|
|
extractorApis.add(element)
|
|
|
|
}
|
|
|
|
|
2022-08-06 15:48:00 +00:00
|
|
|
class Manifest {
|
2022-08-09 15:19:26 +00:00
|
|
|
@JsonProperty("name") var name: String? = null
|
|
|
|
@JsonProperty("pluginClassName") var pluginClassName: String? = null
|
|
|
|
@JsonProperty("version") var version: Int? = null
|
2022-08-09 16:14:36 +00:00
|
|
|
@JsonProperty("requiresResources") var requiresResources: Boolean = false
|
2022-08-06 15:48:00 +00:00
|
|
|
}
|
2022-08-04 10:51:11 +00:00
|
|
|
|
2022-08-11 08:49:20 +00:00
|
|
|
/**
|
|
|
|
* This will contain your resources if you specified requiresResources in gradle
|
|
|
|
*/
|
2022-08-06 15:48:00 +00:00
|
|
|
var resources: Resources? = null
|
|
|
|
var __filename: String? = null
|
2022-08-11 08:49:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This will add a button in the settings allowing you to add custom settings
|
|
|
|
*/
|
2022-08-11 09:05:47 +00:00
|
|
|
var openSettings: ((context: Context) -> Unit)? = null
|
2022-08-04 10:51:11 +00:00
|
|
|
}
|