Yokan / rebuild
Course 1 8624561

ParsedAnimeHttpSource.kt

vendor/yokan-ext/src/androidMain/kotlin/eu/kanade/tachiyomi/animesource/online/ParsedAnimeHttpSource.kt

implementation204 lines
1package eu.kanade.tachiyomi.animesource.online23import eu.kanade.tachiyomi.animesource.model.AnimesPage4import eu.kanade.tachiyomi.animesource.model.SAnime5import eu.kanade.tachiyomi.animesource.model.SEpisode6import eu.kanade.tachiyomi.animesource.model.Video7import eu.kanade.tachiyomi.util.asJsoup8import okhttp3.Response9import org.jsoup.nodes.Document10import org.jsoup.nodes.Element1112/**13 * A simple implementation for sources from a website using Jsoup, an HTML parser.14 */15abstract class ParsedAnimeHttpSource : AnimeHttpSource() {16    /**17     * Parses the response from the site and returns a [AnimesPage] object.18     *19     * @param response the response from the site.20     */21    override fun popularAnimeParse(response: Response): AnimesPage {22        val document = response.asJsoup()2324        val animes =25            document26                .select(popularAnimeSelector())27                .map(::popularAnimeFromElement)2829        val hasNextPage =30            popularAnimeNextPageSelector()31                ?.let(document::selectFirst) != null3233        return AnimesPage(animes, hasNextPage)34    }3536    /**37     * Returns the Jsoup selector that returns a list of [Element] corresponding to each anime.38     */39    protected abstract fun popularAnimeSelector(): String4041    /**42     * Returns a anime from the given [element]. Most sites only show the title and the url, it's43     * totally fine to fill only those two values.44     *45     * @param element an element obtained from [popularAnimeSelector].46     */47    protected abstract fun popularAnimeFromElement(element: Element): SAnime4849    /**50     * Returns the Jsoup selector that returns the <a> tag linking to the next page, or null if51     * there's no next page.52     */53    protected abstract fun popularAnimeNextPageSelector(): String?5455    /**56     * Parses the response from the site and returns a [AnimesPage] object.57     *58     * @param response the response from the site.59     */60    override fun searchAnimeParse(response: Response): AnimesPage {61        val document = response.asJsoup()6263        val animes =64            document65                .select(searchAnimeSelector())66                .map(::searchAnimeFromElement)6768        val hasNextPage =69            searchAnimeNextPageSelector()70                ?.let(document::selectFirst) != null7172        return AnimesPage(animes, hasNextPage)73    }7475    /**76     * Returns the Jsoup selector that returns a list of [Element] corresponding to each anime.77     */78    protected abstract fun searchAnimeSelector(): String7980    /**81     * Returns a anime from the given [element]. Most sites only show the title and the url, it's82     * totally fine to fill only those two values.83     *84     * @param element an element obtained from [searchAnimeSelector].85     */86    protected abstract fun searchAnimeFromElement(element: Element): SAnime8788    /**89     * Returns the Jsoup selector that returns the <a> tag linking to the next page, or null if90     * there's no next page.91     */92    protected abstract fun searchAnimeNextPageSelector(): String?9394    /**95     * Parses the response from the site and returns a [AnimesPage] object.96     *97     * @param response the response from the site.98     */99    override fun latestUpdatesParse(response: Response): AnimesPage {100        val document = response.asJsoup()101102        val animes =103            document104                .select(latestUpdatesSelector())105                .map(::latestUpdatesFromElement)106107        val hasNextPage =108            latestUpdatesNextPageSelector()109                ?.let(document::selectFirst) != null110111        return AnimesPage(animes, hasNextPage)112    }113114    /**115     * Returns the Jsoup selector that returns a list of [Element] corresponding to each anime.116     */117    protected abstract fun latestUpdatesSelector(): String118119    /**120     * Returns a anime from the given [element]. Most sites only show the title and the url, it's121     * totally fine to fill only those two values.122     *123     * @param element an element obtained from [latestUpdatesSelector].124     */125    protected abstract fun latestUpdatesFromElement(element: Element): SAnime126127    /**128     * Returns the Jsoup selector that returns the <a> tag linking to the next page, or null if129     * there's no next page.130     */131    protected abstract fun latestUpdatesNextPageSelector(): String?132133    /**134     * Parses the response from the site and returns the details of a anime.135     *136     * @param response the response from the site.137     */138    override fun animeDetailsParse(response: Response): SAnime = animeDetailsParse(response.asJsoup())139140    /**141     * Returns the details of the anime from the given [document].142     *143     * @param document the parsed document.144     */145    protected abstract fun animeDetailsParse(document: Document): SAnime146147    /**148     * Parses the response from the site and returns a list of episodes.149     *150     * @param response the response from the site.151     */152    override fun episodeListParse(response: Response): List<SEpisode> {153        val document = response.asJsoup()154        return document.select(episodeListSelector()).map(::episodeFromElement)155    }156157    /**158     * Returns the Jsoup selector that returns a list of [Element] corresponding to each episode.159     */160    protected abstract fun episodeListSelector(): String161162    /**163     * Returns a episode from the given element.164     *165     * @param element an element obtained from [episodeListSelector].166     */167    protected abstract fun episodeFromElement(element: Element): SEpisode168169    /**170     * Parses the response from the site and returns the page list.171     *172     * @param response the response from the site.173     */174    override fun videoListParse(response: Response): List<Video> {175        val document = response.asJsoup()176        return document.select(videoListSelector()).map(::videoFromElement)177    }178179    /**180     * Returns the Jsoup selector that returns a list of [Element] corresponding to each video.181     */182    protected abstract fun videoListSelector(): String183184    /**185     * Returns a video from the given element.186     *187     * @param element an element obtained from [videoListSelector].188     */189    protected abstract fun videoFromElement(element: Element): Video190191    /**192     * Parse the response from the site and returns the absolute url to the source video.193     *194     * @param response the response from the site.195     */196    override fun videoUrlParse(response: Response): String = videoUrlParse(response.asJsoup())197198    /**199     * Returns the absolute url to the source image from the document.200     *201     * @param document the parsed document.202     */203    protected abstract fun videoUrlParse(document: Document): String204}205

Search chapters, reference and source filenames.