From 17997e15c02432986c0a05312549f91144227a03 Mon Sep 17 00:00:00 2001 From: Cloudburst <18114966+C10udburst@users.noreply.github.com> Date: Thu, 25 Aug 2022 17:59:34 +0200 Subject: [PATCH 1/3] start adding support for hosters other than github --- .../gradle/CloudstreamExtension.kt | 55 ++++++++++++++----- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/com/lagradost/cloudstream3/gradle/CloudstreamExtension.kt b/src/main/kotlin/com/lagradost/cloudstream3/gradle/CloudstreamExtension.kt index 7607891..ba441e5 100644 --- a/src/main/kotlin/com/lagradost/cloudstream3/gradle/CloudstreamExtension.kt +++ b/src/main/kotlin/com/lagradost/cloudstream3/gradle/CloudstreamExtension.kt @@ -24,16 +24,44 @@ abstract class CloudstreamExtension @Inject constructor(project: Project) { apkinfo!!.urlPrefix = url } - fun setRepo(user: String, repo: String) { - repository = Repo(user, repo) + fun setRepo(user: String, repo: String, url: String, rawLinkFormat: String) { + repository = Repo(user, repo, url, rawLinkFormat) } - fun setRepo(identifier: String) { - val split = identifier - .removePrefix("https://") - .removePrefix("github.com") - .removeSurrounding("/") - .split("/") - repository = Repo(split[0], split[1]) + 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%") + 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- or gitea- or set repository via setRepo(user, repo, url, rawLinkFormat)") + } + } + fun setRepo(url: String) { + when { + url.startsWith("https://github.com") -> { + val split = url + .removePrefix("https://") + .removePrefix("github.com") + .removeSurrounding("/") + .split("/") + setRepo(split[0], split[1], "github") + } + url.startsWith("https://gitlab.com") -> { + val split = url + .removePrefix("https://") + .removePrefix("gitlab.com") + .removeSurrounding("/") + .split("/") + setRepo(split[0], split[1], "gitlab") + } + else -> throw IllegalArgumentException("Unknown domain, please set repository via setRepo(user, repo, type)") + } } internal var pluginClassName: String? = null @@ -55,12 +83,11 @@ class ApkInfo(extension: CloudstreamExtension, release: String) { val jarFile = cache.resolve("cloudstream.jar") } -class Repo(val user: String, val repo: String) { - val url: String - get() = "https://github.com/${user}/${repo}" - +class Repo(val user: String, val repo: String, val url: String, val rawLinkFormat: String) { fun getRawLink(filename: String, branch: String): String { - return "https://raw.githubusercontent.com/${user}/${repo}/${branch}/${filename}" + return rawLinkFormat + .replace("%filename%", filename) + .replace("%branch%", branch) } } From 2448a204dfe43bfde8d5e80867a54515a4e8143d Mon Sep 17 00:00:00 2001 From: Cloudburst <18114966+C10udburst@users.noreply.github.com> Date: Wed, 31 Aug 2022 10:02:30 +0200 Subject: [PATCH 2/3] assume github as default --- .../lagradost/cloudstream3/gradle/CloudstreamExtension.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/kotlin/com/lagradost/cloudstream3/gradle/CloudstreamExtension.kt b/src/main/kotlin/com/lagradost/cloudstream3/gradle/CloudstreamExtension.kt index ba441e5..a0ff01b 100644 --- a/src/main/kotlin/com/lagradost/cloudstream3/gradle/CloudstreamExtension.kt +++ b/src/main/kotlin/com/lagradost/cloudstream3/gradle/CloudstreamExtension.kt @@ -60,6 +60,12 @@ abstract class CloudstreamExtension @Inject constructor(project: Project) { .split("/") setRepo(split[0], split[1], "gitlab") } + !url.startsWith("https://") -> { // assume default as github + val split = url + .removeSurrounding("/") + .split("/") + setRepo(split[0], split[1], "github") + } else -> throw IllegalArgumentException("Unknown domain, please set repository via setRepo(user, repo, type)") } } From a52375b3461bbb03435a47f7c69434689855852e Mon Sep 17 00:00:00 2001 From: Cloudburst <18114966+C10udburst@users.noreply.github.com> Date: Wed, 31 Aug 2022 10:26:20 +0200 Subject: [PATCH 3/3] fix url stuff --- .../gradle/CloudstreamExtension.kt | 31 ++++++++++--------- .../lagradost/cloudstream3/gradle/Utils.kt | 2 +- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/main/kotlin/com/lagradost/cloudstream3/gradle/CloudstreamExtension.kt b/src/main/kotlin/com/lagradost/cloudstream3/gradle/CloudstreamExtension.kt index a0ff01b..dc65362 100644 --- a/src/main/kotlin/com/lagradost/cloudstream3/gradle/CloudstreamExtension.kt +++ b/src/main/kotlin/com/lagradost/cloudstream3/gradle/CloudstreamExtension.kt @@ -16,6 +16,8 @@ abstract class CloudstreamExtension @Inject constructor(project: Project) { var repository: Repo? = null internal set + + var buildBranch: String = "builds" fun overrideUrlPrefix(url: String) { if (apkinfo == null) { @@ -43,31 +45,32 @@ abstract class CloudstreamExtension @Inject constructor(project: Project) { } } fun setRepo(url: String) { - when { - url.startsWith("https://github.com") -> { - val split = url + var type: String? = null + + var split = when { + url.startsWith("https://github.com") -> { + type = "github" + url .removePrefix("https://") .removePrefix("github.com") - .removeSurrounding("/") - .split("/") - setRepo(split[0], split[1], "github") } url.startsWith("https://gitlab.com") -> { - val split = url + type = "gitlab" + url .removePrefix("https://") .removePrefix("gitlab.com") - .removeSurrounding("/") - .split("/") - setRepo(split[0], split[1], "gitlab") } !url.startsWith("https://") -> { // assume default as github - val split = url - .removeSurrounding("/") - .split("/") - setRepo(split[0], split[1], "github") + type = "github" + url } else -> throw IllegalArgumentException("Unknown domain, please set repository via setRepo(user, repo, type)") } + .removePrefix("/") + .removeSuffix("/") + .split("/") + + setRepo(split[0], split[1], type) } internal var pluginClassName: String? = null diff --git a/src/main/kotlin/com/lagradost/cloudstream3/gradle/Utils.kt b/src/main/kotlin/com/lagradost/cloudstream3/gradle/Utils.kt index 30829e1..f4ed1b2 100644 --- a/src/main/kotlin/com/lagradost/cloudstream3/gradle/Utils.kt +++ b/src/main/kotlin/com/lagradost/cloudstream3/gradle/Utils.kt @@ -36,7 +36,7 @@ fun Project.makePluginEntry(): PluginEntry { val repo = extension.repository return PluginEntry( - url = (if (repo == null) "" else repo.getRawLink("${this.name}.cs3", "builds")), + url = (if (repo == null) "" else repo.getRawLink("${this.name}.cs3", extension.buildBranch)), status = extension.status, version = version ?: -1, name = this.name,