mirror of
https://github.com/recloudstream/cloudstream-extensions-multilingual.git
synced 2024-08-15 03:15:14 +00:00
NekosamaProvider working version
This commit is contained in:
parent
b177de518d
commit
50fc87a97b
1 changed files with 48 additions and 48 deletions
|
@ -18,25 +18,41 @@ class NekosamaProvider : MainAPI() {
|
||||||
override var lang = "fr" // fournisseur est en francais
|
override var lang = "fr" // fournisseur est en francais
|
||||||
override val supportedTypes =
|
override val supportedTypes =
|
||||||
setOf(TvType.Anime, TvType.AnimeMovie, TvType.OVA) // animes, animesfilms
|
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
|
|
||||||
|
|
||||||
/**
|
private val nCharQuery = 5 // take the lenght of the query + nCharQuery
|
||||||
Cherche le site pour un titre spécifique
|
private val resultsSearchNbr = 30 // take only n results from search function
|
||||||
|
|
||||||
La recherche retourne une SearchResponse, qui peut être des classes suivants: AnimeSearchResponse, MovieSearchResponse, TorrentSearchResponse, TvSeriesSearchResponse
|
|
||||||
Chaque classes nécessite des données différentes, mais a en commun le nom, le poster et l'url
|
|
||||||
**/
|
|
||||||
|
|
||||||
|
|
||||||
|
data class EpisodeData(
|
||||||
|
@JsonProperty("id") val id: Int,
|
||||||
|
@JsonProperty("title") val title: String?,
|
||||||
|
@JsonProperty("title_english") val title_english: String?,
|
||||||
|
@JsonProperty("title_romanji") val title_romanji: String?,
|
||||||
|
@JsonProperty("title_french") val title_french: String?,
|
||||||
|
@JsonProperty("others") val others: String?,
|
||||||
|
@JsonProperty("type") val type: String?,
|
||||||
|
@JsonProperty("status") val status: String?,
|
||||||
|
@JsonProperty("popularity") val popularity: Int?,
|
||||||
|
@JsonProperty("url") val url: String,
|
||||||
|
@JsonProperty("genre") val genre: Genre?,
|
||||||
|
@JsonProperty("url_image") val url_image: String?,
|
||||||
|
@JsonProperty("score") val score: String?,
|
||||||
|
@JsonProperty("start_date_year") val start_date_year: String?,
|
||||||
|
@JsonProperty("nb_eps") val nb_eps: String?,
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
data class Genre(
|
data class Genre(
|
||||||
@JsonProperty("0") val action: String,
|
@JsonProperty("0") val action: String?,
|
||||||
@JsonProperty("1") val adventure: String,
|
@JsonProperty("1") val adventure: String?,
|
||||||
@JsonProperty("2") val drama: String?,
|
@JsonProperty("2") val drama: String?,
|
||||||
@JsonProperty("3") val fantasy: String?,
|
@JsonProperty("3") val fantasy: String?,
|
||||||
@JsonProperty("4") val military: String?,
|
@JsonProperty("4") val military: String?,
|
||||||
@JsonProperty("5") val shounen: String,
|
@JsonProperty("5") val shounen: String?,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Looking for the best title matching from parsed Episode data
|
||||||
private fun EpisodeData.TitleObtainedBysortByQuery(query: String?): String? {
|
private fun EpisodeData.TitleObtainedBysortByQuery(query: String?): String? {
|
||||||
|
|
||||||
if (query == null) {
|
if (query == null) {
|
||||||
|
@ -69,14 +85,13 @@ class NekosamaProvider : MainAPI() {
|
||||||
// Sorted by the best title matching
|
// Sorted by the best title matching
|
||||||
val titlesSorted = titles.sortedBy { it ->
|
val titlesSorted = titles.sortedBy { it ->
|
||||||
-FuzzySearch.ratio(
|
-FuzzySearch.ratio(
|
||||||
it?.take(query.length) ?: it,
|
it?.take(query.length + nCharQuery) ?: it,
|
||||||
query
|
query
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return titlesSorted.elementAt(0)
|
return titlesSorted.elementAt(0)
|
||||||
|
|
||||||
|
|
||||||
// Looking for the best title matching
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,51 +104,38 @@ class NekosamaProvider : MainAPI() {
|
||||||
this.sortedBy {
|
this.sortedBy {
|
||||||
val bestTitleMatching = it.TitleObtainedBysortByQuery(query)
|
val bestTitleMatching = it.TitleObtainedBysortByQuery(query)
|
||||||
-FuzzySearch.ratio(
|
-FuzzySearch.ratio(
|
||||||
bestTitleMatching?.take(query.length) ?: bestTitleMatching,
|
bestTitleMatching?.take(query.length + nCharQuery) ?: bestTitleMatching,
|
||||||
query
|
query
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This function is done because there is two database (vf and vostfr). So it allows to sort the combine database **/
|
/** This function is done because there is two database (vf and vostfr). So it allows to sort the combined database **/
|
||||||
private fun List<SearchResponse>.sortByname(query: String?): List<SearchResponse> {
|
private fun List<SearchResponse>.sortByname(query: String?): List<SearchResponse> {
|
||||||
return if (query == null) {
|
return if (query == null) {
|
||||||
// Return list to base state if no query
|
// Return list to base state if no query
|
||||||
this.sortedBy { it.name }
|
this.sortedBy { it.name }
|
||||||
} else {
|
} else {
|
||||||
this.sortedBy { -FuzzySearch.ratio(it.name, query) }
|
|
||||||
|
this.sortedBy {
|
||||||
|
val name = it.name
|
||||||
|
-FuzzySearch.ratio(name.take(query.length + nCharQuery), query)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
Cherche le site pour un titre spécifique
|
||||||
|
|
||||||
data class EpisodeData(
|
La recherche retourne une SearchResponse, qui peut être des classes suivants: AnimeSearchResponse, MovieSearchResponse, TorrentSearchResponse, TvSeriesSearchResponse
|
||||||
@JsonProperty("id") val id: Int?,
|
Chaque classes nécessite des données différentes, mais a en commun le nom, le poster et l'url
|
||||||
@JsonProperty("title") val title: String?,
|
**/
|
||||||
@JsonProperty("title_english") val title_english: String?,
|
|
||||||
@JsonProperty("title_romanji") val title_romanji: String?,
|
|
||||||
@JsonProperty("title_french") val title_french: String?,
|
|
||||||
@JsonProperty("others") val others: String?,
|
|
||||||
@JsonProperty("type") val type: String?,
|
|
||||||
@JsonProperty("status") val status: String?,
|
|
||||||
@JsonProperty("popularity") val popularity: Int?,
|
|
||||||
@JsonProperty("url") val url: String?,
|
|
||||||
@JsonProperty("genre") val genre: Genre?,
|
|
||||||
@JsonProperty("url_image") val url_image: String?,
|
|
||||||
@JsonProperty("score") val score: String?,
|
|
||||||
@JsonProperty("start_date_year") val start_date_year: String?,
|
|
||||||
@JsonProperty("nb_eps") val nb_eps: String?,
|
|
||||||
|
|
||||||
)
|
|
||||||
|
|
||||||
override suspend fun search(query: String): List<SearchResponse> {
|
override suspend fun search(query: String): List<SearchResponse> {
|
||||||
val link2 = Pair("$mainUrl/animes-search-vf.json", "(VF) ")
|
val link2 = Pair("$mainUrl/animes-search-vf.json", "(VF) ")
|
||||||
val link = Pair("$mainUrl/animes-search-vostfr.json", "(Vostfr) ")
|
val link = Pair("$mainUrl/animes-search-vostfr.json", "(Vostfr) ")
|
||||||
val links = ArrayList<Pair<String, String>>()
|
val links = ArrayList<Pair<String, String>>()
|
||||||
links.add(link2)
|
links.add(link2)
|
||||||
links.add(link)
|
links.add(link)
|
||||||
val nbrresults = 50 // take only n results
|
|
||||||
var ListResults = ArrayList<SearchResponse>()
|
var ListResults = ArrayList<SearchResponse>()
|
||||||
if (links != null) {
|
if (links != null) {
|
||||||
links.forEach {
|
links.forEach {
|
||||||
|
@ -142,11 +144,10 @@ class NekosamaProvider : MainAPI() {
|
||||||
val reponse = app.get(url).text
|
val reponse = app.get(url).text
|
||||||
val ParsedData = tryParseJson<ArrayList<EpisodeData>>(reponse)
|
val ParsedData = tryParseJson<ArrayList<EpisodeData>>(reponse)
|
||||||
|
|
||||||
ParsedData?.sortByQuery(query)?.take(nbrresults)?.apmap { it ->
|
ParsedData?.sortByQuery(query)?.take(resultsSearchNbr)?.apmap { it ->
|
||||||
val type = it.type
|
val type = it.type
|
||||||
val mediaPoster = it.url_image
|
val mediaPoster = it.url_image
|
||||||
val href = mainUrl + it.url
|
val href = mainUrl + it.url
|
||||||
//val bestTitleMatching = it.StringObtainedBysortByQuery(query)
|
|
||||||
val bestTitleMatching = it.TitleObtainedBysortByQuery(query)
|
val bestTitleMatching = it.TitleObtainedBysortByQuery(query)
|
||||||
val title = version + bestTitleMatching
|
val title = version + bestTitleMatching
|
||||||
|
|
||||||
|
@ -159,7 +160,6 @@ class NekosamaProvider : MainAPI() {
|
||||||
false
|
false
|
||||||
) {
|
) {
|
||||||
this.posterUrl = mediaPoster
|
this.posterUrl = mediaPoster
|
||||||
// this.rating = rating
|
|
||||||
}
|
}
|
||||||
))
|
))
|
||||||
null, "tv", "ova", "" -> (
|
null, "tv", "ova", "" -> (
|
||||||
|
@ -182,7 +182,7 @@ class NekosamaProvider : MainAPI() {
|
||||||
} ?: throw ErrorLoadingException("ParsedData failed")
|
} ?: throw ErrorLoadingException("ParsedData failed")
|
||||||
}
|
}
|
||||||
return ListResults.sortByname(query)
|
return ListResults.sortByname(query)
|
||||||
.take(nbrresults) // Do that to short the vf and vostfr anime together
|
.take(resultsSearchNbr) // Do that to short the vf and vostfr anime together
|
||||||
}
|
}
|
||||||
return ListResults
|
return ListResults
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,7 @@ class NekosamaProvider : MainAPI() {
|
||||||
// url est le lien retourné par la fonction search (la variable href) ou la fonction getMainPage
|
// url est le lien retourné par la fonction search (la variable href) ou la fonction getMainPage
|
||||||
|
|
||||||
val episodes = ArrayList<Episode>()
|
val episodes = ArrayList<Episode>()
|
||||||
var mediaType = TvType.AnimeMovie
|
var mediaType = TvType.Anime
|
||||||
val script =
|
val script =
|
||||||
document.select("div#main > script:first-of-type")
|
document.select("div#main > script:first-of-type")
|
||||||
|
|
||||||
|
@ -244,7 +244,7 @@ class NekosamaProvider : MainAPI() {
|
||||||
val type =
|
val type =
|
||||||
document.selectFirst("div#anime-info-list")?.text()
|
document.selectFirst("div#anime-info-list")?.text()
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
if (type.contains("tv") || type.contains("ova")) mediaType = TvType.Anime
|
if (type.contains(" movie")) mediaType = TvType.AnimeMovie
|
||||||
}
|
}
|
||||||
val description = document.selectFirst("div.synopsis > p")?.text()
|
val description = document.selectFirst("div.synopsis > p")?.text()
|
||||||
val poster = document.select("div.cover > img").attr("src")
|
val poster = document.select("div.cover > img").attr("src")
|
||||||
|
@ -301,9 +301,9 @@ class NekosamaProvider : MainAPI() {
|
||||||
httpsify(playerUrl),
|
httpsify(playerUrl),
|
||||||
playerUrl,
|
playerUrl,
|
||||||
subtitleCallback
|
subtitleCallback
|
||||||
) { link -> // charge un extracteur d'extraire le lien direct .mp4
|
) { link ->
|
||||||
callback.invoke(
|
callback.invoke(
|
||||||
ExtractorLink( // ici je modifie le callback pour ajouter des informations, normalement ce n'est pas nécessaire
|
ExtractorLink(
|
||||||
link.source,
|
link.source,
|
||||||
link.name + "",
|
link.name + "",
|
||||||
link.url,
|
link.url,
|
||||||
|
@ -358,16 +358,16 @@ class NekosamaProvider : MainAPI() {
|
||||||
|
|
||||||
override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse {
|
override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse {
|
||||||
val url: String
|
val url: String
|
||||||
if (page == 1) {
|
url = if (page == 1) {
|
||||||
url = request.data
|
request.data
|
||||||
} else {
|
} else {
|
||||||
url = request.data + page
|
request.data + page
|
||||||
}
|
}
|
||||||
val document = app.get(url).document
|
val document = app.get(url).document
|
||||||
val movies = document.select("div#regular-list-animes > div.anime")
|
val movies = document.select("div#regular-list-animes > div.anime")
|
||||||
|
|
||||||
val home =
|
val home =
|
||||||
movies.mapNotNull { article -> // avec mapnotnull si un élément est null, il sera automatiquement enlevé de la liste
|
movies.apmap { article -> // avec mapnotnull si un élément est null, il sera automatiquement enlevé de la liste
|
||||||
article.toSearchResponse()
|
article.toSearchResponse()
|
||||||
}
|
}
|
||||||
return newHomePageResponse(request.name, home)
|
return newHomePageResponse(request.name, home)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue