From 4baacbb68907b036d41f396d04ec2b55cac04777 Mon Sep 17 00:00:00 2001
From: Cloudburst <18114966+C10udburst@users.noreply.github.com>
Date: Mon, 22 Aug 2022 14:38:07 +0200
Subject: [PATCH] add Tvpolan
---
TvpolanProvider/build.gradle.kts | 28 +++++++
TvpolanProvider/src/main/AndroidManifest.xml | 2 +
.../kotlin/com/lagradost/TvpolanProvider.kt | 79 +++++++++++++++++++
.../com/lagradost/TvpolanProviderPlugin.kt | 13 +++
4 files changed, 122 insertions(+)
create mode 100644 TvpolanProvider/build.gradle.kts
create mode 100644 TvpolanProvider/src/main/AndroidManifest.xml
create mode 100644 TvpolanProvider/src/main/kotlin/com/lagradost/TvpolanProvider.kt
create mode 100644 TvpolanProvider/src/main/kotlin/com/lagradost/TvpolanProviderPlugin.kt
diff --git a/TvpolanProvider/build.gradle.kts b/TvpolanProvider/build.gradle.kts
new file mode 100644
index 0000000..bea9d21
--- /dev/null
+++ b/TvpolanProvider/build.gradle.kts
@@ -0,0 +1,28 @@
+// use an integer for version numbers
+version = 1
+
+dependencies {
+ implementation("me.xdrop:fuzzywuzzy:1.4.0")
+}
+
+cloudstream {
+ language = "pl"
+ // All of these properties are optional, you can safely remove them
+
+ // description = "Lorem Ipsum"
+ authors = listOf("Cloudburst")
+
+ /**
+ * Status int as the following:
+ * 0: Down
+ * 1: Ok
+ * 2: Slow
+ * 3: Beta only
+ * */
+ status = 1
+ tvTypes = listOf(
+ "Live"
+ )
+
+ iconUrl = "https://www.google.com/s2/favicons?domain=tvpolan.ml&sz=%size%"
+}
diff --git a/TvpolanProvider/src/main/AndroidManifest.xml b/TvpolanProvider/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..29aec9d
--- /dev/null
+++ b/TvpolanProvider/src/main/AndroidManifest.xml
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/TvpolanProvider/src/main/kotlin/com/lagradost/TvpolanProvider.kt b/TvpolanProvider/src/main/kotlin/com/lagradost/TvpolanProvider.kt
new file mode 100644
index 0000000..25eb9bb
--- /dev/null
+++ b/TvpolanProvider/src/main/kotlin/com/lagradost/TvpolanProvider.kt
@@ -0,0 +1,79 @@
+package com.lagradost
+
+import com.lagradost.cloudstream3.*
+import com.lagradost.cloudstream3.utils.ExtractorLink
+import com.lagradost.cloudstream3.utils.Qualities
+import me.xdrop.fuzzywuzzy.FuzzySearch
+
+open class TvpolanProvider : MainAPI() {
+ override var mainUrl = "http://tvpolan.ml/"
+ override var name = "TV Polan"
+ override var lang = "pl"
+ override val hasMainPage = true
+ override val supportedTypes = setOf(
+ TvType.Live
+ )
+
+ override suspend fun getMainPage(page: Int, request : MainPageRequest): HomePageResponse {
+ val document = app.get(mainUrl).document
+ val lists = document.select(".channels ul li a[href]").map { it ->
+ return@map LiveSearchResponse(
+ name = it.attr("title"),
+ url = it.attr("href"),
+ apiName = this.name,
+ type = TvType.Live,
+ posterUrl = it.selectFirst("img[src]")?.attr("src")
+ )
+ }
+ return newHomePageResponse(this.name, lists, false)
+ }
+
+ override suspend fun search(query: String): List {
+ val document = app.get(mainUrl).document
+ val lists = document.select(".channels ul li a[href]").map { it ->
+ return@map LiveSearchResponse(
+ name = it.attr("title"),
+ url = it.attr("href"),
+ apiName = this.name,
+ type = TvType.Live,
+ posterUrl = it.selectFirst("img[src]")?.attr("src")
+ )
+ }
+ return lists.sortedBy { -FuzzySearch.ratio(it.name, query) }
+ }
+
+ override suspend fun load(url: String): LoadResponse? {
+ val document = app.get(url).document
+
+ val name = Regex("http://tvpolen\\.ml/(.+)\\.php").find(url)?.groupValues?.get(1) ?: this.name
+
+ val src = document.selectFirst("video source[src]")?.attr("src") ?: return null
+
+ return LiveStreamLoadResponse(
+ name,
+ url,
+ this.name,
+ src,
+ "http://tvpolen.ml/tv/${name}.png"
+ )
+ }
+
+ override suspend fun loadLinks(
+ data: String,
+ isCasting: Boolean,
+ subtitleCallback: (SubtitleFile) -> Unit,
+ callback: (ExtractorLink) -> Unit
+ ): Boolean {
+ callback.invoke(
+ ExtractorLink(
+ "tvpolen.ml",
+ this.name,
+ data,
+ "",
+ Qualities.Unknown.value,
+ isM3u8 = true
+ )
+ )
+ return true
+ }
+}
\ No newline at end of file
diff --git a/TvpolanProvider/src/main/kotlin/com/lagradost/TvpolanProviderPlugin.kt b/TvpolanProvider/src/main/kotlin/com/lagradost/TvpolanProviderPlugin.kt
new file mode 100644
index 0000000..6234da3
--- /dev/null
+++ b/TvpolanProvider/src/main/kotlin/com/lagradost/TvpolanProviderPlugin.kt
@@ -0,0 +1,13 @@
+
+package com.lagradost
+
+import com.lagradost.cloudstream3.plugins.CloudstreamPlugin
+import com.lagradost.cloudstream3.plugins.Plugin
+import android.content.Context
+
+@CloudstreamPlugin
+class TvpolanProviderPlugin: Plugin() {
+ override fun load(context: Context) {
+ registerMainAPI(TvpolanProvider())
+ }
+}
\ No newline at end of file