2022-08-04 11:30:09 +00:00
package com.lagradost.cloudstream3.gradle
2022-08-04 07:19:27 +00:00
import org.gradle.api.Project
import org.gradle.api.plugins.ExtensionContainer
import org.gradle.api.provider.Property
2022-08-06 16:47:25 +00:00
import org.gradle.api.provider.ListProperty
2022-08-04 07:19:27 +00:00
import javax.inject.Inject
abstract class CloudstreamExtension @Inject constructor ( project : Project ) {
val userCache = project . gradle . gradleUserHomeDir . resolve ( " caches " ) . resolve ( " cloudstream " )
2022-08-08 10:35:17 +00:00
val apiVersion = 1
2022-08-04 11:30:09 +00:00
var apkinfo : ApkInfo ? = null
2022-08-04 07:52:23 +00:00
internal set
2022-08-08 09:54:17 +00:00
var repository : Repo ? = null
internal set
2022-10-16 08:15:02 +00:00
2022-08-31 08:26:20 +00:00
var buildBranch : String = " builds "
2022-08-08 09:54:17 +00:00
2022-08-06 10:00:02 +00:00
fun overrideUrlPrefix ( url : String ) {
2022-08-06 16:47:25 +00:00
if ( apkinfo == null ) {
apkinfo = ApkInfo ( this , " pre-release " )
}
2022-08-06 10:00:02 +00:00
apkinfo !! . urlPrefix = url
2022-08-04 09:06:07 +00:00
}
2022-08-25 15:59:34 +00:00
fun setRepo ( user : String , repo : String , url : String , rawLinkFormat : String ) {
repository = Repo ( user , repo , url , rawLinkFormat )
2022-08-08 09:54:17 +00:00
}
2022-08-25 15:59:34 +00:00
fun setRepo ( user : String , repo : String , type : String ) {
when {
type == " github " -> setRepo ( user , repo , " https://github.com/ ${user} / ${repo} " , " https://raw.githubusercontent.com/ ${user} / ${repo} /%branch%/%filename% " )
type == " gitlab " -> setRepo ( user , repo , " https://gitlab.com/ ${user} / ${repo} " , " https://gitlab.com/ ${user} / ${repo} /-/raw/%branch%/%filename% " )
2023-07-07 06:39:12 +00:00
type == " codeberg " -> setRepo ( user , repo , " https://codeberg.org/ ${user} / ${repo} " , " https://codeberg.org/ ${user} / ${repo} /raw/branch/%branch%/%filename% " )
2022-08-25 15:59:34 +00:00
type . startsWith ( " gitlab- " ) -> {
val domain = type . removePrefix ( " gitlab- " )
setRepo ( user , repo , " https:// ${domain} / ${user} / ${repo} " , " https:// ${domain} / ${user} / ${repo} /-/raw/%branch%/%filename% " )
}
type . startsWith ( " gitea- " ) -> {
val domain = type . removePrefix ( " gitea- " )
setRepo ( user , repo , " https:// ${domain} / ${user} / ${repo} " , " https:// ${domain} / ${user} / ${repo} /raw/branch/%branch%/%filename% " )
}
else -> throw IllegalArgumentException ( " Unknown type ${type} . Use github, gitlab, gitlab-<domain> or gitea-<domain> or set repository via setRepo(user, repo, url, rawLinkFormat) " )
}
}
fun setRepo ( url : String ) {
2022-08-31 08:26:20 +00:00
var type : String ? = null
2022-10-16 08:15:02 +00:00
2022-08-31 08:26:20 +00:00
var split = when {
url . startsWith ( " https://github.com " ) -> {
type = " github "
url
2022-08-25 15:59:34 +00:00
. removePrefix ( " https:// " )
. removePrefix ( " github.com " )
}
url . startsWith ( " https://gitlab.com " ) -> {
2022-08-31 08:26:20 +00:00
type = " gitlab "
url
2022-08-25 15:59:34 +00:00
. removePrefix ( " https:// " )
. removePrefix ( " gitlab.com " )
}
2023-07-07 06:39:12 +00:00
url . startsWith ( " https://codeberg.org " ) -> {
type = " codeberg "
url
. removePrefix ( " https:// " )
. removePrefix ( " codeberg.org " )
}
2022-08-31 08:02:30 +00:00
! url . startsWith ( " https:// " ) -> { // assume default as github
2022-08-31 08:26:20 +00:00
type = " github "
url
2022-08-31 08:02:30 +00:00
}
2022-08-25 15:59:34 +00:00
else -> throw IllegalArgumentException ( " Unknown domain, please set repository via setRepo(user, repo, type) " )
}
2022-08-31 08:26:20 +00:00
. removePrefix ( " / " )
. removeSuffix ( " / " )
. split ( " / " )
2022-10-16 08:15:02 +00:00
2022-08-31 08:26:20 +00:00
setRepo ( split [ 0 ] , split [ 1 ] , type )
2022-08-08 10:08:53 +00:00
}
2022-08-08 09:54:17 +00:00
2022-08-04 07:52:23 +00:00
internal var pluginClassName : String ? = null
2022-08-19 08:12:39 +00:00
internal var fileSize : Long ? = null
2022-08-06 16:47:25 +00:00
2022-08-09 16:04:41 +00:00
var requiresResources = false
2022-08-08 14:59:23 +00:00
var description : String ? = null
var authors = listOf < String > ( )
var status = 3
2022-08-11 08:54:32 +00:00
var language : String ? = null
2022-08-14 12:50:52 +00:00
var tvTypes : List < String > ? = null
2022-08-11 08:54:32 +00:00
var iconUrl : String ? = null
2022-08-04 07:19:27 +00:00
}
2022-08-04 11:30:09 +00:00
class ApkInfo ( extension : CloudstreamExtension , release : String ) {
2022-08-04 07:19:27 +00:00
val cache = extension . userCache . resolve ( " cloudstream " )
2022-08-06 10:00:02 +00:00
var urlPrefix = " https://github.com/recloudstream/cloudstream/releases/download/ ${release} "
2022-08-04 09:06:07 +00:00
val jarFile = cache . resolve ( " cloudstream.jar " )
2022-08-04 07:19:27 +00:00
}
2022-08-25 15:59:34 +00:00
class Repo ( val user : String , val repo : String , val url : String , val rawLinkFormat : String ) {
2022-08-08 09:54:17 +00:00
fun getRawLink ( filename : String , branch : String ) : String {
2022-08-25 15:59:34 +00:00
return rawLinkFormat
. replace ( " %filename% " , filename )
. replace ( " %branch% " , branch )
2022-08-08 09:54:17 +00:00
}
}
2022-08-04 07:19:27 +00:00
fun ExtensionContainer . getCloudstream ( ) : CloudstreamExtension {
return getByName ( " cloudstream " ) as CloudstreamExtension
2022-08-04 07:52:23 +00:00
}
fun ExtensionContainer . findCloudstream ( ) : CloudstreamExtension ? {
return findByName ( " cloudstream " ) as CloudstreamExtension ?
2023-07-07 06:39:12 +00:00
}