use switch case in getAuthHeader and change default account

This commit is contained in:
Eddy 2022-10-23 12:02:57 +02:00
parent fdee7dfc20
commit 9fef2e58f4
3 changed files with 68 additions and 63 deletions

View file

@ -12,17 +12,17 @@ import me.xdrop.fuzzywuzzy.FuzzySearch
class MacIPTVProvider(override var lang: String) : MainAPI() { class MacIPTVProvider(override var lang: String) : MainAPI() {
private val defaulmac_adresse = private val defaulmac_adresse =
"mac=00:1a:79:ae:2a:30" "mac=00:1A:79:aa:53:65"
private val defaultmainUrl = private val defaultmainUrl =
"http://ultra-box.club/c/" "http://ky-iptv.com:25461/portalstb"
var defaultname = "BoxIPTV-MatrixOTT |${lang.uppercase()}|" var defaultname = "ky-iptv |${lang.uppercase()}|"
override var name = "Box Iptv |${lang.uppercase()}|" override var name = "Box Iptv |${lang.uppercase()}|"
override val hasQuickSearch = false override val hasQuickSearch = false
override val hasMainPage = true override val hasMainPage = true
override val supportedTypes = override val supportedTypes =
setOf(TvType.Live) // live setOf(TvType.Live) // live
private var init = false private var firstInitDone = false
private var key: String? = "" private var key: String? = ""
companion object { companion object {
@ -31,53 +31,61 @@ class MacIPTVProvider(override var lang: String) : MainAPI() {
var overrideUrl: String? = null var overrideUrl: String? = null
} }
private fun accountInfoNotGood(url: String, mac: String?): Boolean {
return url.uppercase().trim() == "NONE" || url.isBlank() || mac?.uppercase()
?.trim() == "NONE" || mac.isNullOrBlank()
}
private suspend fun getAuthHeader(): Map<String, String> { private suspend fun getAuthHeader(): Map<String, String> {
mainUrl = overrideUrl.toString() mainUrl = overrideUrl.toString()
val main = mainUrl.uppercase().trim() name = (companionName ?: name) + " |${lang.uppercase()}|"
val localCredentials = loginMac val localCredentials = loginMac
val mac = localCredentials?.uppercase()?.trim() when (true) {
accountInfoNotGood(mainUrl, localCredentials) -> {
if (main == "NONE" || main.isBlank() || mac == "NONE" || mac.isNullOrBlank()) {
mainUrl = defaultmainUrl mainUrl = defaultmainUrl
name = defaultname name = defaultname
if (!firstInitDone) {
val url_key =
"$mainUrl/portal.php?type=stb&action=handshake&JsHttpRequest=1-xml"
val reponseGetkey = app.get(
url_key, headers = mapOf(
"Cookie" to defaulmac_adresse,
"User-Agent" to "Mozilla/5.0 (QtEmbedded; U; Linux; C) AppleWebKit/533.3 (KHTML, like Gecko) MAG200 stbapp ver: 2 rev: 250 Safari/533.3",
)
)
val keyJson = reponseGetkey.parsed<Getkey>()
key = keyJson.js?.token
}
firstInitDone = true
return mapOf(
"Cookie" to defaulmac_adresse,
"User-Agent" to "Mozilla/5.0 (QtEmbedded; U; Linux; C) AppleWebKit/533.3 (KHTML, like Gecko) MAG200 stbapp ver: 2 rev: 250 Safari/533.3",
"Authorization" to "Bearer $key",
)
}
else -> {
if (!firstInitDone) {
val url_key =
"$mainUrl/portal.php?type=stb&action=handshake&JsHttpRequest=1-xml"
val reponseGetkey = app.get(
url_key, headers = mapOf(
"Cookie" to "mac=$localCredentials",
"User-Agent" to "Mozilla/5.0 (QtEmbedded; U; Linux; C) AppleWebKit/533.3 (KHTML, like Gecko) MAG200 stbapp ver: 2 rev: 250 Safari/533.3",
)
)
val keyJson = reponseGetkey.parsed<Getkey>()
key = keyJson.js?.token
}
firstInitDone = true
return mapOf(
"Cookie" to "mac=$localCredentials",
"User-Agent" to "Mozilla/5.0 (QtEmbedded; U; Linux; C) AppleWebKit/533.3 (KHTML, like Gecko) MAG200 stbapp ver: 2 rev: 250 Safari/533.3",
"Authorization" to "Bearer $key",
)
}
}
if (!init) {
val url_key = "$mainUrl/portal.php?type=stb&action=handshake&JsHttpRequest=1-xml"
val reponseGetkey = app.get(
url_key, headers = mapOf(
"Cookie" to defaulmac_adresse,
"User-Agent" to "Mozilla/5.0 (QtEmbedded; U; Linux; C) AppleWebKit/533.3 (KHTML, like Gecko) MAG200 stbapp ver: 2 rev: 250 Safari/533.3",
)
)
val keyJson = reponseGetkey.parsed<Getkey>()
key = keyJson.js?.token
}
init = true
return mapOf(
"Cookie" to defaulmac_adresse,
"User-Agent" to "Mozilla/5.0 (QtEmbedded; U; Linux; C) AppleWebKit/533.3 (KHTML, like Gecko) MAG200 stbapp ver: 2 rev: 250 Safari/533.3",
"Authorization" to "Bearer $key",
)
}
name = (companionName ?: name) + " |${lang.uppercase()}|"
if (!init) {
val url_key = "$mainUrl/portal.php?type=stb&action=handshake&JsHttpRequest=1-xml"
val reponseGetkey = app.get(
url_key, headers = mapOf(
"Cookie" to "mac=$localCredentials",
"User-Agent" to "Mozilla/5.0 (QtEmbedded; U; Linux; C) AppleWebKit/533.3 (KHTML, like Gecko) MAG200 stbapp ver: 2 rev: 250 Safari/533.3",
)
)
val keyJson = reponseGetkey.parsed<Getkey>()
key = keyJson.js?.token
}
init = true
return mapOf(
"Cookie" to "mac=$localCredentials",
"User-Agent" to "Mozilla/5.0 (QtEmbedded; U; Linux; C) AppleWebKit/533.3 (KHTML, like Gecko) MAG200 stbapp ver: 2 rev: 250 Safari/533.3",
"Authorization" to "Bearer $key",
)
} }
@ -169,18 +177,18 @@ class MacIPTVProvider(override var lang: String) : MainAPI() {
override suspend fun load(url: String): LoadResponse { override suspend fun load(url: String): LoadResponse {
var link = "" var link = url
var title = "" var title = "Your channel"
var posterUrl = "" var posterUrl = ""
var description = "" var description = "The program for this channel was not found"
val header = getAuthHeader()
val allresultshome: MutableList<SearchResponse> = mutableListOf() val allresultshome: MutableList<SearchResponse> = mutableListOf()
val headerIPTV = getAuthHeader()
for (media in arraymediaPlaylist) { for (media in arraymediaPlaylist) {
val keyId = "/-${media.id}-" val keyId = "/-${media.id}-"
if (url.contains(keyId) || url == media.url) { if (url.contains(keyId) || url == media.url) {
val epg_url = val epg_url =
"$mainUrl/portal.php?type=itv&action=get_short_epg&ch_id=${media.ch_id}&size=10&JsHttpRequest=1-xml" // descriptif "$mainUrl/portal.php?type=itv&action=get_short_epg&ch_id=${media.ch_id}&size=10&JsHttpRequest=1-xml" // plot
val response = app.get(epg_url, headers = header) val response = app.get(epg_url, headers = headerIPTV)
description = getEpg(response.text) description = getEpg(response.text)
link = media.url link = media.url
title = media.title title = media.title
@ -284,8 +292,8 @@ class MacIPTVProvider(override var lang: String) : MainAPI() {
var link: String var link: String
var lien: String var lien: String
runBlocking { runBlocking {
val header = getAuthHeader() val headerIPTV = getAuthHeader()
val getTokenLink = app.get(TokenLink, headers = header).text val getTokenLink = app.get(TokenLink, headers = headerIPTV).text
val regexGetLink = Regex("""(http.*)\"\},""") val regexGetLink = Regex("""(http.*)\"\},""")
link = regexGetLink.find(getTokenLink)?.groupValues?.get(1).toString() link = regexGetLink.find(getTokenLink)?.groupValues?.get(1).toString()
.replace( .replace(
@ -323,11 +331,10 @@ class MacIPTVProvider(override var lang: String) : MainAPI() {
subtitleCallback: (SubtitleFile) -> Unit, subtitleCallback: (SubtitleFile) -> Unit,
callback: (ExtractorLink) -> Unit, callback: (ExtractorLink) -> Unit,
): Boolean { ): Boolean {
val headerIPTV = getAuthHeader()
val header = getAuthHeader()
val TokenLink = val TokenLink =
"$mainUrl/portal.php?type=itv&action=create_link&cmd=ffmpeg%20$data&series=&forced_storage=0&disable_ad=0&download=0&force_ch_link_check=0&JsHttpRequest=1-xml" "$mainUrl/portal.php?type=itv&action=create_link&cmd=ffmpeg%20$data&series=&forced_storage=0&disable_ad=0&download=0&force_ch_link_check=0&JsHttpRequest=1-xml"
val getTokenLink = app.get(TokenLink, headers = header).text val getTokenLink = app.get(TokenLink, headers = headerIPTV).text
val regexGetLink = Regex("""(http.*)\"\},""") val regexGetLink = Regex("""(http.*)\"\},""")
val link = val link =
regexGetLink.find(getTokenLink)?.groupValues?.get(1).toString().replace("""\""", "") regexGetLink.find(getTokenLink)?.groupValues?.get(1).toString().replace("""\""", "")
@ -354,7 +361,7 @@ class MacIPTVProvider(override var lang: String) : MainAPI() {
lien = redirectlink lien = redirectlink
} }
} }
val isM3u8 = false// lien.contains("extension=ts") val isM3u8 = false
callback.invoke( callback.invoke(
ExtractorLink( ExtractorLink(
name, name,
@ -590,10 +597,8 @@ class MacIPTVProvider(override var lang: String) : MainAPI() {
val rgxcodeCountry = findKeyWord(codeCountry) val rgxcodeCountry = findKeyWord(codeCountry)
val arrayHomepage = arrayListOf<HomePageList>() val arrayHomepage = arrayListOf<HomePageList>()
override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse { override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse {
if (!firstInitDone) {
val headerIPTV = getAuthHeader()
if (!init) {
val header = getAuthHeader()
val url_info = val url_info =
"$mainUrl/portal.php?type=account_info&action=get_main_info&JsHttpRequest=1-xml" "$mainUrl/portal.php?type=account_info&action=get_main_info&JsHttpRequest=1-xml"
val urlGetGenre = val urlGetGenre =
@ -609,7 +614,7 @@ class MacIPTVProvider(override var lang: String) : MainAPI() {
urlGetGenre, urlGetGenre,
urlGetallchannels urlGetallchannels
).apmap { url -> ).apmap { url ->
val response = app.get(url, headers = header) val response = app.get(url, headers = headerIPTV)
when (true) { when (true) {
url.contains("action=get_main_info") -> { url.contains("action=get_main_info") -> {
reponseGetInfo = response reponseGetInfo = response
@ -743,3 +748,4 @@ class MacIPTVProvider(override var lang: String) : MainAPI() {
}) })
} }
} }

View file

@ -3,7 +3,6 @@ package com.lagradost
import com.lagradost.cloudstream3.AcraApplication.Companion.getKey import com.lagradost.cloudstream3.AcraApplication.Companion.getKey
import com.lagradost.cloudstream3.AcraApplication.Companion.setKey import com.lagradost.cloudstream3.AcraApplication.Companion.setKey
import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.syncproviders.AccountManager
import com.lagradost.cloudstream3.syncproviders.AuthAPI import com.lagradost.cloudstream3.syncproviders.AuthAPI
import com.lagradost.cloudstream3.syncproviders.InAppAuthAPI import com.lagradost.cloudstream3.syncproviders.InAppAuthAPI
import com.lagradost.cloudstream3.syncproviders.InAppAuthAPIManager import com.lagradost.cloudstream3.syncproviders.InAppAuthAPIManager
@ -36,7 +35,7 @@ class MacIptvAPI(index: Int) : InAppAuthAPIManager(index) {
setKey(accountId, IPTVBOX_USER_KEY, data) setKey(accountId, IPTVBOX_USER_KEY, data)
registerAccount() registerAccount()
initialize() initialize()
AccountManager.inAppAuths inAppAuths
return true return true
} }

View file

@ -54,7 +54,7 @@ class MacIptvSettingsFragment(private val plugin: Plugin, val maciptvAPI: MacIpt
val infoSubTextView = view.findView<TextView>("info_sub_text") val infoSubTextView = view.findView<TextView>("info_sub_text")
val infoImageView = view.findView<ImageView>("nginx_info_imageview") val infoImageView = view.findView<ImageView>("nginx_info_imageview")
infoTextView.text = getString("nginx_info_title") ?: "Nginx" infoTextView.text = getString("nginx_info_title") ?: "MacIPTV"
infoSubTextView.text = getString("nginx_info_summary") ?: "" infoSubTextView.text = getString("nginx_info_summary") ?: ""
infoImageView.setImageDrawable(getDrawable("nginx_question")) infoImageView.setImageDrawable(getDrawable("nginx_question"))
infoImageView.imageTintList = infoImageView.imageTintList =