diff --git a/src/ru/anibe/build.gradle b/src/ru/anibe/build.gradle new file mode 100644 index 000000000..2bbbaff68 --- /dev/null +++ b/src/ru/anibe/build.gradle @@ -0,0 +1,17 @@ +apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' + +ext { + appName = 'Tachiyomi: Anibe' + pkgNameSuffix = 'ru.anibe' + extClass = '.Anibe' + extVersionCode = 1 + libVersion = '1.2' +} + +dependencies { + compileOnly 'com.google.code.gson:gson:2.8.2' + compileOnly 'com.github.salomonbrys.kotson:kotson:2.5.0' +} + +apply from: "$rootDir/common.gradle" diff --git a/src/ru/anibe/res/mipmap-hdpi/ic_launcher.png b/src/ru/anibe/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 000000000..469a389bc Binary files /dev/null and b/src/ru/anibe/res/mipmap-hdpi/ic_launcher.png differ diff --git a/src/ru/anibe/res/mipmap-mdpi/ic_launcher.png b/src/ru/anibe/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 000000000..ed1dc818b Binary files /dev/null and b/src/ru/anibe/res/mipmap-mdpi/ic_launcher.png differ diff --git a/src/ru/anibe/res/mipmap-xhdpi/ic_launcher.png b/src/ru/anibe/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 000000000..8fae2938e Binary files /dev/null and b/src/ru/anibe/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/src/ru/anibe/res/mipmap-xxhdpi/ic_launcher.png b/src/ru/anibe/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 000000000..e78835507 Binary files /dev/null and b/src/ru/anibe/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/src/ru/anibe/res/mipmap-xxxhdpi/ic_launcher.png b/src/ru/anibe/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 000000000..2bc343640 Binary files /dev/null and b/src/ru/anibe/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/src/ru/anibe/res/web_hi_res_512.png b/src/ru/anibe/res/web_hi_res_512.png new file mode 100644 index 000000000..a74ea441a Binary files /dev/null and b/src/ru/anibe/res/web_hi_res_512.png differ diff --git a/src/ru/anibe/src/eu/kanade/tachiyomi/extension/ru/anibe/Anibe.kt b/src/ru/anibe/src/eu/kanade/tachiyomi/extension/ru/anibe/Anibe.kt new file mode 100644 index 000000000..55f823311 --- /dev/null +++ b/src/ru/anibe/src/eu/kanade/tachiyomi/extension/ru/anibe/Anibe.kt @@ -0,0 +1,164 @@ +package eu.kanade.tachiyomi.extension.ru.anibe + +import eu.kanade.tachiyomi.network.GET +import eu.kanade.tachiyomi.source.model.* +import eu.kanade.tachiyomi.source.online.ParsedHttpSource +import okhttp3.OkHttpClient +import okhttp3.Request +import org.jsoup.nodes.Document +import org.jsoup.nodes.Element +import com.google.gson.Gson +import com.github.salomonbrys.kotson.* +import okhttp3.Response +import com.google.gson.JsonObject + +class Anibe : ParsedHttpSource() { + + override val name = "Anibe" + + override val baseUrl = "https://api.anibe.ru" + + override val lang = "ru" + + override val supportsLatest = true + + override val client: OkHttpClient = network.cloudflareClient + + private val gson = Gson() + + // Popular Manga + + override fun popularMangaRequest(page: Int): Request { + return GET("$baseUrl/posts?sort=-rating") + } + + override fun popularMangaParse(response: Response): MangasPage { + val allManga = mutableListOf() + val jsonManga = gson.fromJson(response.body()!!.string())["rows"].asJsonArray + + for (i in 0 until jsonManga.size()) { + val manga = SManga.create() + manga.url = "/posts/" + jsonManga[i]["id"].asString + manga.title = jsonManga[i]["name"].asString + manga.thumbnail_url = jsonManga[i]["cover"].asString + allManga.add(manga) + } + + return MangasPage(allManga, false) + } + + override fun popularMangaSelector() = "Unneeded" + + override fun popularMangaFromElement(element: Element): SManga = throw UnsupportedOperationException("Not used") + + override fun popularMangaNextPageSelector() = "Unneeded" + + // Latest Manga + + override fun latestUpdatesRequest(page: Int): Request { + return GET("$baseUrl/posts?sort=-latest") + } + + override fun latestUpdatesParse(response: Response): MangasPage = popularMangaParse(response) + + override fun latestUpdatesSelector() = popularMangaSelector() + + override fun latestUpdatesFromElement(element: Element): SManga = popularMangaFromElement(element) + + override fun latestUpdatesNextPageSelector() = popularMangaNextPageSelector() + + // Search Manga + + override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { + return GET("$baseUrl/posts?q=$query") + } + + override fun searchMangaParse(response: Response): MangasPage = popularMangaParse(response) + + override fun searchMangaSelector() = "Unneeded" + + override fun searchMangaFromElement(element: Element) = popularMangaFromElement(element) + + override fun searchMangaNextPageSelector() = popularMangaNextPageSelector() + + // Manga details + + override fun mangaDetailsParse(response: Response): SManga { + val jsonManga = gson.fromJson(response.body()!!.string()) + + val manga = SManga.create() + manga.title = jsonManga["name"].asString + manga.author = jsonManga["author"].asString + val status = jsonManga["status"].asString + manga.status = parseStatus(status) + manga.genre = jsonManga["genre"].toString().substringAfter("[").substringBefore("]").replace("\"" ,"").replace("," ," ") + manga.description = jsonManga["description"].asString + manga.thumbnail_url = jsonManga["cover"].asString + return manga + } + + override fun mangaDetailsParse(document: Document): SManga = throw UnsupportedOperationException("Not used") + + private fun parseStatus(status: String?) = when { + status == null -> SManga.UNKNOWN + status.contains("Продолжается") -> SManga.ONGOING + status.contains("Завершен") -> SManga.COMPLETED + else -> SManga.UNKNOWN + } + + // Chapter parsing + + /* Technically we would get the same response for chapter.url with or without the ?$i below + However, if all the chapters for a manga have the same URL, every chapter will have the same pages + So, add an "unnecessary" incremented tag that doesn't break the URL but still adds uniqueness */ + override fun chapterListParse(response: Response): List { + val allChapters = mutableListOf() + val jsonManga = gson.fromJson(response.body()!!.string()) + val jsonChapters = jsonManga["episodes"].asJsonObject.keys().sortedWith(Comparator{ a, b -> + when { + a.substringBefore("_").toInt() < b.substringBefore("_").toInt() -> 1 + a.substringBefore("_").toInt() > b.substringBefore("_").toInt() -> -1 + a.substringAfter("_") < b.substringAfter("_") -> 1 + a.substringAfter("_") > b.substringAfter("_") -> -1 + else -> 0 + } + }) + + for (i in 0 until jsonChapters.size) { + val chapter = SChapter.create() + chapter.name = "Chapter: " + jsonChapters.elementAt(i) // Key for chapter in JSON object + chapter.url = "/posts/" + jsonManga["id"].asString + "?$i" + allChapters.add(chapter) + } + return allChapters + } + + override fun chapterListSelector() = throw UnsupportedOperationException("Not used") + + override fun chapterFromElement(element: Element): SChapter = throw UnsupportedOperationException("Not used") + + // Pages + + private var chNum = "" + override fun pageListRequest(chapter: SChapter): Request { + chNum = chapter.name.substringAfter("Chapter: ") // This is how we get the chapter key for pageListParse + return super.pageListRequest(chapter) + } + + override fun pageListParse(response: Response): List { + val jsonPages = gson.fromJson(response.body()!!.string())["episodes"][chNum].asJsonArray + val pages = mutableListOf() + + for (i in 0 until jsonPages.size()) { + pages.add(Page(i, "", jsonPages[i].asString)) + } + return pages + } + + override fun pageListParse(document: Document): List = throw UnsupportedOperationException("Not used") + + override fun imageUrlParse(document: Document): String = throw UnsupportedOperationException("Not used") + + override fun getFilterList() = FilterList() + +}