mirror of
https://github.com/recloudstream/cloudstream-extensions-multilingual.git
synced 2024-08-15 03:15:14 +00:00
optimized the getMainPage
This commit is contained in:
parent
bcee9decaf
commit
a671011530
1 changed files with 62 additions and 114 deletions
|
@ -1,11 +1,11 @@
|
||||||
package com.lagradost
|
package com.lagradost
|
||||||
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
import com.lagradost.cloudstream3.*
|
import com.lagradost.cloudstream3.*
|
||||||
import com.lagradost.cloudstream3.utils.*
|
import com.lagradost.cloudstream3.utils.*
|
||||||
import com.lagradost.cloudstream3.utils.AppUtils.toJson
|
import com.lagradost.cloudstream3.utils.AppUtils.toJson
|
||||||
import com.lagradost.cloudstream3.utils.AppUtils.tryParseJson
|
import com.lagradost.cloudstream3.utils.AppUtils.tryParseJson
|
||||||
|
import org.jsoup.nodes.Element
|
||||||
|
|
||||||
|
|
||||||
class VostfreeProvider : MainAPI() {
|
class VostfreeProvider : MainAPI() {
|
||||||
|
@ -15,10 +15,8 @@ class VostfreeProvider : MainAPI() {
|
||||||
override val hasQuickSearch = false // recherche rapide (optionel, pas vraimet utile)
|
override val hasQuickSearch = false // recherche rapide (optionel, pas vraimet utile)
|
||||||
override val hasMainPage = true // page d'accueil (optionel mais encoragé)
|
override val hasMainPage = true // page d'accueil (optionel mais encoragé)
|
||||||
override var lang = "fr" // fournisseur est en francais
|
override var lang = "fr" // fournisseur est en francais
|
||||||
|
|
||||||
//override val supportedTypes = setOf(TvType.Movie) // ici on ne supporte que les films
|
|
||||||
override val supportedTypes =
|
override val supportedTypes =
|
||||||
setOf(TvType.Anime, TvType.AnimeMovie, TvType.OVA) // animes, animesfilms et series
|
setOf(TvType.Anime, TvType.AnimeMovie, TvType.OVA) // animes, animesfilms
|
||||||
// liste des types: https://recloudstream.github.io/dokka/app/com.lagradost.cloudstream3/-tv-type/index.html
|
// liste des types: https://recloudstream.github.io/dokka/app/com.lagradost.cloudstream3/-tv-type/index.html
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,22 +26,17 @@ class VostfreeProvider : MainAPI() {
|
||||||
Chaque classes nécessite des données différentes, mais a en commun le nom, le poster et l'url
|
Chaque classes nécessite des données différentes, mais a en commun le nom, le poster et l'url
|
||||||
**/
|
**/
|
||||||
override suspend fun search(query: String): List<SearchResponse> {
|
override suspend fun search(query: String): List<SearchResponse> {
|
||||||
//val link = "$mainUrl/?s=$query"
|
val link =
|
||||||
val link = "$mainUrl/index.php?story=$query&do=search&subaction=search"
|
"$mainUrl/index.php?story=$query&do=search&subaction=search" // L'url pour chercher un anime de dragon sera donc: 'https://vostfree.cx/index.php?story=dragon&do=search&subaction=search'
|
||||||
// L'url pour chercher un anime de dragon sera donc: 'https://vostfree.cx/index.php?story=dragon&do=search&subaction=search'
|
|
||||||
// le $ dans une string permet d'insérer une variable
|
|
||||||
val document =
|
val document =
|
||||||
app.get(link).document // app.get() permet de télécharger la page html avec une requete HTTP (get)
|
app.get(link).document // app.get() permet de télécharger la page html avec une requete HTTP (get)
|
||||||
// on convertit le html en un document
|
|
||||||
return document.select("div.search-result") // on séléctione tous les éléments 'enfant' du type articles
|
return document.select("div.search-result") // on séléctione tous les éléments 'enfant' du type articles
|
||||||
.apmap { div -> // apmap crée une liste des éléments (ici newMovieSearchResponse et newAnimeSearchResponse)
|
.apmap { div -> // apmap crée une liste des éléments (ici newMovieSearchResponse et newAnimeSearchResponse)
|
||||||
//val posterContainer = div.selectFirst("> span.image ") // selectione le premier élément correspondant à ces critères
|
|
||||||
val type =
|
val type =
|
||||||
div?.selectFirst("div.genre")?.text()?.replace("\t", "")?.replace("\n", "")
|
div?.selectFirst("div.genre")?.text()?.replace("\t", "")
|
||||||
// replace enlève tous les '\t' et '\n' du titre
|
?.replace("\n", "") // replace enlève tous les '\t' et '\n' du titre
|
||||||
val mediaPoster = mainUrl + div?.selectFirst("span.image > img")
|
val mediaPoster = mainUrl + div?.selectFirst("span.image > img")
|
||||||
?.attr("src") // récupère le texte de l'attribut src de l'élément
|
?.attr("src") // récupère le texte de l'attribut src de l'élément
|
||||||
|
|
||||||
val href = div?.selectFirst("div.info > div.title > a")?.attr("href")
|
val href = div?.selectFirst("div.info > div.title > a")?.attr("href")
|
||||||
?: throw ErrorLoadingException("invalid link") // renvoie une erreur si il n'y a pas de lien vers le média
|
?: throw ErrorLoadingException("invalid link") // renvoie une erreur si il n'y a pas de lien vers le média
|
||||||
val title = div.selectFirst("> div.info > div.title > a")?.text().toString()
|
val title = div.selectFirst("> div.info > div.title > a")?.text().toString()
|
||||||
|
@ -80,10 +73,6 @@ class VostfreeProvider : MainAPI() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private data class EmbedUrlClass(
|
|
||||||
@JsonProperty("embed_url") val url: String?,
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* charge la page d'informations, il ya toutes les donées, les épisodes, le résumé etc ...
|
* charge la page d'informations, il ya toutes les donées, les épisodes, le résumé etc ...
|
||||||
* Il faut retourner soit: AnimeLoadResponse, MovieLoadResponse, TorrentLoadResponse, TvSeriesLoadResponse.
|
* Il faut retourner soit: AnimeLoadResponse, MovieLoadResponse, TorrentLoadResponse, TvSeriesLoadResponse.
|
||||||
|
@ -105,27 +94,25 @@ class VostfreeProvider : MainAPI() {
|
||||||
var title = ""
|
var title = ""
|
||||||
|
|
||||||
var description: String? = ""// first() selectione le premier élément de la liste
|
var description: String? = ""// first() selectione le premier élément de la liste
|
||||||
|
|
||||||
/////////////////////////////////////////////////
|
|
||||||
val isSaison = document.select("div.new_player_series_count > a")
|
val isSaison = document.select("div.new_player_series_count > a")
|
||||||
var saison00 = -1
|
var saison00 = -1
|
||||||
var i = 0
|
var i = 0
|
||||||
var noSeason = true
|
var noSeason = true
|
||||||
var enterInIseason = false
|
var enterInIseason = false
|
||||||
isSaison.forEach {
|
isSaison.mapNotNull {
|
||||||
var url1 = it.attr("href")
|
var url1 = it.attr("href")
|
||||||
while (noSeason) {
|
while (noSeason) {
|
||||||
it.select("[alt=Saison 0$i]")
|
it.select("[alt=Saison 0$i]")
|
||||||
.forEach { // enter in the block when it match the season
|
.mapNotNull { // enter in the block when it match the season
|
||||||
noSeason = false
|
noSeason = false
|
||||||
}
|
}
|
||||||
it.select("[alt=Saison $i]")
|
it.select("[alt=Saison $i]")
|
||||||
.forEach { // enter in the block when it match the season
|
.mapNotNull { // enter in the block when it match the season
|
||||||
noSeason = false
|
noSeason = false
|
||||||
}
|
}
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
i = i - 1
|
i = i - 1 // take the good number
|
||||||
saison00 = i
|
saison00 = i
|
||||||
i = 0 // reinit i et noSeason for the next page
|
i = 0 // reinit i et noSeason for the next page
|
||||||
noSeason = true
|
noSeason = true
|
||||||
|
@ -142,7 +129,7 @@ class VostfreeProvider : MainAPI() {
|
||||||
description = meta1.select("div.slide-middle > div.slide-desc").first()
|
description = meta1.select("div.slide-middle > div.slide-desc").first()
|
||||||
?.text() // first() selectione le premier élément de la liste
|
?.text() // first() selectione le premier élément de la liste
|
||||||
|
|
||||||
val listEpisode = document.select(" select.new_player_selector > option").forEach {
|
document.select(" select.new_player_selector > option").mapNotNull {
|
||||||
|
|
||||||
if (it.text() != "Film") {
|
if (it.text() != "Film") {
|
||||||
val link =
|
val link =
|
||||||
|
@ -191,7 +178,7 @@ class VostfreeProvider : MainAPI() {
|
||||||
} else {
|
} else {
|
||||||
season = null
|
season = null
|
||||||
}
|
}
|
||||||
val listEpisode = document.select(" select.new_player_selector > option").forEach {
|
document.select(" select.new_player_selector > option").mapNotNull {
|
||||||
|
|
||||||
if (it.text() != "Film") {
|
if (it.text() != "Film") {
|
||||||
val link =
|
val link =
|
||||||
|
@ -260,11 +247,12 @@ class VostfreeProvider : MainAPI() {
|
||||||
} else {
|
} else {
|
||||||
data
|
data
|
||||||
}
|
}
|
||||||
|
val noMovie = "1"
|
||||||
val noEpisode = if (parsedInfo?.episodeNumber != null) {
|
val noEpisode = if (parsedInfo?.episodeNumber != null) {
|
||||||
parsedInfo.episodeNumber
|
parsedInfo.episodeNumber
|
||||||
} else {
|
} else {
|
||||||
"1"
|
noMovie
|
||||||
} // if is not a movie then take the episode number else 1
|
} // if is not a movie then take the episode number else for movie it is 1
|
||||||
|
|
||||||
val document = app.get(url).document
|
val document = app.get(url).document
|
||||||
document.select("div.new_player_bottom")
|
document.select("div.new_player_bottom")
|
||||||
|
@ -286,13 +274,11 @@ class VostfreeProvider : MainAPI() {
|
||||||
?: throw ErrorLoadingException("Player No found") //prend tous les players resultat : "player_2140" et "player_6521"
|
?: throw ErrorLoadingException("Player No found") //prend tous les players resultat : "player_2140" et "player_6521"
|
||||||
val playerName = it.select("div#$player")
|
val playerName = it.select("div#$player")
|
||||||
.text() // prend le nom du player ex : "Uqload" et "Sibnet"
|
.text() // prend le nom du player ex : "Uqload" et "Sibnet"
|
||||||
//for(i in playerName.indices){
|
|
||||||
var codePlayload =
|
var codePlayload =
|
||||||
document.selectFirst("div#content_$player")?.text()
|
document.selectFirst("div#content_$player")?.text()
|
||||||
.toString() // resultat : "325544" ou "https:..." peut être lorsque playerName = VIP ou Upvid DStream
|
.toString() // result : "325544" ou "https:..."
|
||||||
var playerUrl = ""
|
var playerUrl = when (playerName) {
|
||||||
playerUrl = when (playerName) {
|
"VIP", "Upvid", "Dstream", "Streamsb", "Vudeo", "NinjaS" -> codePlayload // case https
|
||||||
"VIP", "Upvid", "Dstream", "Streamsb", "Vudeo", "NinjaS" -> codePlayload
|
|
||||||
"Uqload" -> "https://uqload.com/embed-$codePlayload.html"
|
"Uqload" -> "https://uqload.com/embed-$codePlayload.html"
|
||||||
"Mytv" -> "https://www.myvi.tv/embed/$codePlayload"
|
"Mytv" -> "https://www.myvi.tv/embed/$codePlayload"
|
||||||
"Sibnet" -> "https://video.sibnet.ru/shell.php?videoid=$codePlayload"
|
"Sibnet" -> "https://video.sibnet.ru/shell.php?videoid=$codePlayload"
|
||||||
|
@ -324,95 +310,57 @@ class VostfreeProvider : MainAPI() {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun Element.toSearchResponse(): SearchResponse? {
|
||||||
override suspend fun getMainPage(
|
val poster = select("span.image")
|
||||||
page: Int,
|
val posterUrl = mainUrl + poster.select("> img").attr("src")
|
||||||
request: MainPageRequest
|
val subdub = select("div.quality").text()
|
||||||
): HomePageResponse {
|
val genre = select("div.genre").text()
|
||||||
val list = ArrayList<HomePageList>()
|
val title = select("div.info > div.title").text()
|
||||||
val animeDubStatus = ArrayList<String>(1)
|
val link = select("div.play > a").attr("href")
|
||||||
|
if (genre == "FILM") {
|
||||||
animeDubStatus.add("/animes-vf/")
|
return newMovieSearchResponse(
|
||||||
animeDubStatus.add("/animes-vostfr/")
|
title,
|
||||||
animeDubStatus.add("/films-vf-vostfr/")
|
link,
|
||||||
|
TvType.AnimeMovie,
|
||||||
|
false,
|
||||||
|
) {
|
||||||
|
this.posterUrl = posterUrl
|
||||||
animeDubStatus.forEach {
|
//this.quality = quality
|
||||||
val documentZero = app.get("$mainUrl$it").document
|
|
||||||
val numberOFpage = documentZero.select("div.navigation > div.pages > a").text()
|
|
||||||
var lastpage = if (numberOFpage != "") numberOFpage.substringAfterLast(" ").toString()
|
|
||||||
.toInt() else 1
|
|
||||||
val openPageMax = 2 // prendre uniquement les n pages
|
|
||||||
lastpage = if (lastpage > openPageMax) {
|
|
||||||
openPageMax
|
|
||||||
} else {
|
|
||||||
lastpage
|
|
||||||
}
|
}
|
||||||
var categoryTitle = ""
|
|
||||||
for (i in 1..lastpage) {
|
|
||||||
var page = "/page/$i"
|
|
||||||
val document = app.get("$mainUrl$it$page").document
|
|
||||||
|
|
||||||
val movies = document.select("div#content > div#dle-content > div.movie-poster")
|
|
||||||
categoryTitle =
|
|
||||||
document.select("div#left-movies-block > ul#left-movies-tabs > li").text()
|
|
||||||
.replace("Animes VF", " Animes EN FRANÇAIS (page $i)")
|
|
||||||
.replace("Animes VOSTFR", " Animes VOSTFR (page $i)")
|
|
||||||
.replace("Films VF et VOSTFR", "FILMS EN FRANÇAIS OU EN VOSTFR (page $i)")
|
|
||||||
.replace("Liste", "").replace("La liste des", "")
|
|
||||||
val returnList = movies.mapNotNull { article ->
|
|
||||||
// map est la même chose que apmap (mais apmap est plus rapide)
|
|
||||||
// ici si un élément est null, il sera automatiquement enlevé de la liste
|
|
||||||
val poster = article.select("span.image")
|
|
||||||
val posterUrl = mainUrl + poster.select("> img").attr("src")
|
|
||||||
val subdub = article.select("div.quality").text()
|
|
||||||
|
|
||||||
val genre = article.select("div.genre").text()
|
|
||||||
|
|
||||||
val title = article.select("div.info > div.title").text()
|
|
||||||
val link = article.select("div.play > a").attr("href")
|
|
||||||
if (genre == "FILM") {
|
|
||||||
newMovieSearchResponse(
|
|
||||||
title,
|
|
||||||
link,
|
|
||||||
TvType.AnimeMovie,
|
|
||||||
false,
|
|
||||||
) {
|
|
||||||
this.posterUrl = posterUrl
|
|
||||||
//this.quality = quality
|
|
||||||
}
|
|
||||||
|
|
||||||
} else // a tv serie
|
|
||||||
{
|
|
||||||
newAnimeSearchResponse(
|
|
||||||
title,
|
|
||||||
link,
|
|
||||||
TvType.Anime,
|
|
||||||
false,
|
|
||||||
) {
|
|
||||||
this.posterUrl = posterUrl
|
|
||||||
if (subdub == "VF") DubStatus.Dubbed else DubStatus.Subbed
|
|
||||||
//this.quality = quality
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if (returnList.isEmpty()) throw ErrorLoadingException()
|
|
||||||
list.add(HomePageList(categoryTitle, returnList))
|
|
||||||
|
|
||||||
|
} else // an Anime
|
||||||
|
{
|
||||||
|
return newAnimeSearchResponse(
|
||||||
|
title,
|
||||||
|
link,
|
||||||
|
TvType.Anime,
|
||||||
|
false,
|
||||||
|
) {
|
||||||
|
this.posterUrl = posterUrl
|
||||||
|
if (subdub == "VF") DubStatus.Dubbed else DubStatus.Subbed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (list.isEmpty()) throw ErrorLoadingException()
|
}
|
||||||
return HomePageResponse(
|
|
||||||
list
|
override val mainPage = mainPageOf(
|
||||||
)
|
Pair("$mainUrl/animes-vf/page/", "Animes en version français"),
|
||||||
|
Pair("$mainUrl/animes-vostfr/page/", "Animes sous-titrés en français"),
|
||||||
|
Pair("$mainUrl/films-vf-vostfr/page/", "Films en Fr et Vostfr")
|
||||||
|
)
|
||||||
|
|
||||||
|
override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse {
|
||||||
|
val url = request.data + page
|
||||||
|
val document = app.get(url).document
|
||||||
|
val movies = document.select("div#content > div#dle-content > div.movie-poster")
|
||||||
|
|
||||||
|
val home =
|
||||||
|
movies.mapNotNull { article -> // avec mapnotnull si un élément est null, il sera automatiquement enlevé de la liste
|
||||||
|
article.toSearchResponse()
|
||||||
|
}
|
||||||
|
return newHomePageResponse(request.name, home)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue