@@ -147,16 +147,37 @@ class AnimeSailProvider : MainAPI() {
147147 val tracker = APIHolder .getTracker(listOf (title), TrackerType .getTypes(type), year, true )
148148 val malId = tracker?.malId
149149
150- var animeMetaData: MetaAnimeData ? = null
151150 var tmdbid: Int? = null
152151 var kitsuid: String? = null
153152
154153 if (malId != null ) {
155154 try {
156- val syncMetaData = app.get(" https://api.ani.zip/mappings?mal_id=$malId " ).text
157- animeMetaData = parseAnimeData(syncMetaData)
158- tmdbid = animeMetaData?.mappings?.themoviedbId
159- kitsuid = animeMetaData?.mappings?.kitsuId
155+ val kitsuRes = app.get(" https://kitsu.io/api/edge/mappings?filter[externalSite]=myanimelist/anime&filter[externalId]=$malId " ).text
156+ val kitsuJson = mapper.readTree(kitsuRes)
157+
158+ val extractedKitsuId = kitsuJson.path(" data" ).get(0 )
159+ ?.path(" relationships" )
160+ ?.path(" item" )
161+ ?.path(" data" )
162+ ?.path(" id" )?.asText()
163+
164+ if (! extractedKitsuId.isNullOrBlank()) {
165+ kitsuid = extractedKitsuId
166+
167+ val mappingRes = app.get(" https://kitsu.io/api/edge/anime/$kitsuid /mappings" ).text
168+ val mappingJson = mapper.readTree(mappingRes)
169+
170+ val dataArray = mappingJson.path(" data" )
171+ if (dataArray.isArray) {
172+ for (node in dataArray) {
173+ val site = node.path(" attributes" ).path(" externalSite" ).asText()
174+ if (site.contains(" themoviedb" , ignoreCase = true )) {
175+ tmdbid = node.path(" attributes" ).path(" externalId" ).asText().toIntOrNull()
176+ break
177+ }
178+ }
179+ }
180+ }
160181 } catch (e: Exception ) {
161182 }
162183 }
@@ -169,7 +190,7 @@ class AnimeSailProvider : MainAPI() {
169190 appLangCode = " en"
170191 )
171192
172- val backgroundposter = animeMetaData?.images?.find { it.coverType == " Fanart " }?.url ? : tracker?.cover
193+ val backgroundposter = tracker?.cover
173194
174195 val episodes = document.select(" ul.daftar > li" ).amap {
175196 val link = fixUrl(it.select(" a" ).attr(" href" ))
@@ -181,52 +202,24 @@ class AnimeSailProvider : MainAPI() {
181202 episodeNum = 1
182203 }
183204
184- val episodeKey = episodeNum?.toString()
185- val metaEp = if (episodeKey != null ) animeMetaData?.episodes?.get(episodeKey) else null
186-
187- val epOverview = metaEp?.overview
188- val finalOverview = if (! epOverview.isNullOrBlank()) {
189- epOverview
190- } else {
191- " Synopsis not yet available."
192- }
193-
194205 newEpisode(link) {
195- this .name = if (type == TvType .AnimeMovie ) {
196- animeMetaData?.titles?.get(" en" ) ? : animeMetaData?.titles?.get(" ja" ) ? : title
197- } else {
198- metaEp?.title?.get(" en" ) ? : metaEp?.title?.get(" ja" ) ? : name
199- }
200-
206+ this .name = name
201207 this .episode = episodeNum
202- this .score = Score .from10(metaEp?.rating)
203- this .posterUrl = metaEp?.image ? : animeMetaData?.images?.firstOrNull()?.url ? : " "
204- this .description = finalOverview
205- this .addDate(metaEp?.airDateUtc)
206- this .runTime = metaEp?.runtime
208+ this .description = " Synopsis not yet available."
207209 }
208210 }.reversed()
209211
210- val apiDescription = animeMetaData?.description?.replace(Regex (" <.*?>" ), " " )
211- val rawPlot = apiDescription ? : animeMetaData?.episodes?.get(" 1" )?.overview
212-
213- val finalPlot = if (! rawPlot.isNullOrBlank()) {
214- rawPlot
215- } else {
216- plotText
217- }
218-
219212 return newAnimeLoadResponse(title, url, TvType .Anime ) {
220- this .engName = animeMetaData?.titles?.get( " en " ) ? : title
221- this .japName = animeMetaData?.titles?.get( " ja " ) ? : animeMetaData?.titles?.get( " x-jat " )
213+ this .engName = title
214+ this .japName = title
222215 this .posterUrl = tracker?.image ? : poster
223216 this .backgroundPosterUrl = backgroundposter
224217 try { this .logoUrl = logoUrl } catch (_: Throwable ) {}
225218 this .year = year
226219 this .duration = getDurationFromString(durationText)
227220 addEpisodes(DubStatus .Subbed , episodes)
228221 this .showStatus = getStatus(statusText)
229- this .plot = finalPlot
222+ this .plot = plotText
230223 this .tags = tagsList
231224 addMalId(malId)
232225 addAniListId(tracker?.aniId?.toIntOrNull())
@@ -378,47 +371,6 @@ class AnimeSailProvider : MainAPI() {
378371 return Regex (" (\\ d{3,4})[pP]" ).find(str)?.groupValues?.getOrNull(1 )?.toIntOrNull()
379372 ? : Qualities .Unknown .value
380373 }
381-
382- @JsonIgnoreProperties(ignoreUnknown = true )
383- data class MetaImage (
384- @JsonProperty(" coverType" ) val coverType : String? ,
385- @JsonProperty(" url" ) val url : String?
386- )
387-
388- @JsonIgnoreProperties(ignoreUnknown = true )
389- data class MetaEpisode (
390- @JsonProperty(" episode" ) val episode : String? ,
391- @JsonProperty(" airDateUtc" ) val airDateUtc : String? ,
392- @JsonProperty(" runtime" ) val runtime : Int? ,
393- @JsonProperty(" image" ) val image : String? ,
394- @JsonProperty(" title" ) val title : Map <String , String >? ,
395- @JsonProperty(" overview" ) val overview : String? ,
396- @JsonProperty(" rating" ) val rating : String? ,
397- @JsonProperty(" finaleType" ) val finaleType : String?
398- )
399-
400- @JsonIgnoreProperties(ignoreUnknown = true )
401- data class MetaAnimeData (
402- @JsonProperty(" titles" ) val titles : Map <String , String >? ,
403- @JsonProperty(" description" ) val description : String? ,
404- @JsonProperty(" images" ) val images : List <MetaImage >? ,
405- @JsonProperty(" episodes" ) val episodes : Map <String , MetaEpisode >? ,
406- @JsonProperty(" mappings" ) val mappings : MetaMappings ? = null
407- )
408-
409- @JsonIgnoreProperties(ignoreUnknown = true )
410- data class MetaMappings (
411- @JsonProperty(" themoviedb_id" ) val themoviedbId : Int? = null ,
412- @JsonProperty(" kitsu_id" ) val kitsuId : String? = null
413- )
414-
415- private fun parseAnimeData (jsonString : String ): MetaAnimeData ? {
416- return try {
417- mapper.readValue(jsonString, MetaAnimeData ::class .java)
418- } catch (_: Exception ) {
419- null
420- }
421- }
422374}
423375
424376suspend fun fetchTmdbLogoUrl (
0 commit comments