You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.0 KiB
Kotlin

package moe.odango.index.scraper.mal
import moe.odango.index.entity.MyAnimeListInfo
import org.jsoup.Jsoup
import java.net.URI
class AnimeListScraper(body: String) {
private val dom = Jsoup.parse(body)
data class MyAnimeListListingItem(val myAnimeListId: Long, val title: String, val type: MyAnimeListInfo.ReleaseType, val episodes: Int?)
fun getItems(): List<MyAnimeListListingItem> {
val arr = dom
.select("[id=content] .list tbody tr")
.toList()
return arr.drop(1).mapNotNull {
val link = it.select("a[id^=sinfo]").first()
val id = link
.attr("href")
.split("/")
.let {
it[it.indexOf("anime") + 1].toLongOrNull()
}
val title = link.text()
val type = it.child(2).text()
val eps = it.child(3).text().toIntOrNull()
id?.let { MyAnimeListListingItem(id, title, MyAnimeListInfo.ReleaseType.valueOf(type), eps) }
}
}
}