diff --git a/src/pt/bakai/AndroidManifest.xml b/src/pt/bakai/AndroidManifest.xml new file mode 100644 index 000000000..bbd136b36 --- /dev/null +++ b/src/pt/bakai/AndroidManifest.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + diff --git a/src/pt/bakai/build.gradle b/src/pt/bakai/build.gradle new file mode 100644 index 000000000..7d94eb97a --- /dev/null +++ b/src/pt/bakai/build.gradle @@ -0,0 +1,12 @@ +apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' + +ext { + extName = 'Bakai' + pkgNameSuffix = 'pt.bakai' + extClass = '.Bakai' + extVersionCode = 1 + isNsfw = true +} + +apply from: "$rootDir/common.gradle" diff --git a/src/pt/bakai/res/mipmap-hdpi/ic_launcher.png b/src/pt/bakai/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 000000000..c837ccb9f Binary files /dev/null and b/src/pt/bakai/res/mipmap-hdpi/ic_launcher.png differ diff --git a/src/pt/bakai/res/mipmap-mdpi/ic_launcher.png b/src/pt/bakai/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 000000000..dbf4f7191 Binary files /dev/null and b/src/pt/bakai/res/mipmap-mdpi/ic_launcher.png differ diff --git a/src/pt/bakai/res/mipmap-xhdpi/ic_launcher.png b/src/pt/bakai/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 000000000..37af9a17a Binary files /dev/null and b/src/pt/bakai/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/src/pt/bakai/res/mipmap-xxhdpi/ic_launcher.png b/src/pt/bakai/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 000000000..475f77355 Binary files /dev/null and b/src/pt/bakai/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/src/pt/bakai/res/mipmap-xxxhdpi/ic_launcher.png b/src/pt/bakai/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 000000000..533a6e19a Binary files /dev/null and b/src/pt/bakai/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/src/pt/bakai/src/eu/kanade/tachiyomi/extension/pt/bakai/Bakai.kt b/src/pt/bakai/src/eu/kanade/tachiyomi/extension/pt/bakai/Bakai.kt new file mode 100644 index 000000000..b37ed49a1 --- /dev/null +++ b/src/pt/bakai/src/eu/kanade/tachiyomi/extension/pt/bakai/Bakai.kt @@ -0,0 +1,160 @@ +package eu.kanade.tachiyomi.extension.pt.bakai + +import eu.kanade.tachiyomi.network.GET +import eu.kanade.tachiyomi.network.asObservableSuccess +import eu.kanade.tachiyomi.network.interceptor.rateLimitHost +import eu.kanade.tachiyomi.source.model.FilterList +import eu.kanade.tachiyomi.source.model.MangasPage +import eu.kanade.tachiyomi.source.model.Page +import eu.kanade.tachiyomi.source.model.SChapter +import eu.kanade.tachiyomi.source.model.SManga +import eu.kanade.tachiyomi.source.model.UpdateStrategy +import eu.kanade.tachiyomi.source.online.ParsedHttpSource +import eu.kanade.tachiyomi.util.asJsoup +import okhttp3.HttpUrl.Companion.toHttpUrl +import okhttp3.Request +import okhttp3.Response +import org.jsoup.nodes.Document +import org.jsoup.nodes.Element +import rx.Observable +import java.util.concurrent.TimeUnit + +class Bakai : ParsedHttpSource() { + + override val name = "Bakai" + + override val baseUrl = "https://bakai.org" + + override val lang = "pt-BR" + + override val supportsLatest = false + + override val client by lazy { + network.client.newBuilder() + .rateLimitHost(baseUrl.toHttpUrl(), 1, 2, TimeUnit.SECONDS) + .build() + } + + // ============================== Popular =============================== + override fun popularMangaRequest(page: Int) = GET("$baseUrl/home1/page/$page/") + + override fun popularMangaSelector() = "#elCmsPageWrap ul > li > article" + + override fun popularMangaFromElement(element: Element) = SManga.create().apply { + thumbnail_url = element.selectFirst("img")?.absUrl("src") + with(element.selectFirst("h2.ipsType_pageTitle a")!!) { + title = text() + setUrlWithoutDomain(attr("href")) + } + } + + override fun popularMangaNextPageSelector() = "li.ipsPagination_next:not(.ipsPagination_inactive) > a[rel=next]" + + // =============================== Latest =============================== + override fun latestUpdatesRequest(page: Int): Request { + throw UnsupportedOperationException("Not used.") + } + + override fun latestUpdatesSelector(): String { + throw UnsupportedOperationException("Not used.") + } + + override fun latestUpdatesFromElement(element: Element): SManga { + throw UnsupportedOperationException("Not used.") + } + + override fun latestUpdatesNextPageSelector(): String? { + throw UnsupportedOperationException("Not used.") + } + + // =============================== Search =============================== + override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable { + return if (query.startsWith(PREFIX_SEARCH)) { // URL intent handler + val id = query.removePrefix(PREFIX_SEARCH) + client.newCall(GET("$baseUrl/hentai/$id")) + .asObservableSuccess() + .map(::searchMangaByIdParse) + } else { + super.fetchSearchManga(page, query, filters) + } + } + + private fun searchMangaByIdParse(response: Response): MangasPage { + val details = mangaDetailsParse(response.use { it.asJsoup() }) + return MangasPage(listOf(details), false) + } + + override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { + val url = "$baseUrl/search1/".toHttpUrl().newBuilder() + .addQueryParameter("q", query) + .addQueryParameter("type", "cms_records1") + .addQueryParameter("page", page.toString()) + .addQueryParameter("sortby", "relevancy") + .addQueryParameter("search_and_or", "or") + .build() + + return GET(url, headers) + } + + override fun searchMangaSelector() = "ol > li > div" + + override fun searchMangaFromElement(element: Element) = SManga.create().apply { + thumbnail_url = element.selectFirst(".ipsThumb img")?.absUrl("src") + + with(element.selectFirst("h2.ipsStreamItem_title a")!!) { + title = text() + setUrlWithoutDomain(attr("href")) + } + } + + override fun searchMangaNextPageSelector() = popularMangaNextPageSelector() + + // =========================== Manga Details ============================ + override fun mangaDetailsParse(document: Document) = SManga.create().apply { + title = document.selectFirst("h1.ipsType_pageTitle")?.text() ?: "Hentai" + thumbnail_url = document.selectFirst("div.cCmsRecord_image img")?.absUrl("src") + artist = document.selectFirst("span.mangaInfo:contains(Artist:) + a")?.text() + genre = document.selectFirst("span.mangaInfo:contains(Tags:) + span")?.text() + description = document.selectFirst("h2.ipsFieldRow_desc")?.let { + // Alternative titles + "Títulos alternativos: ${it.text()}" + } + status = SManga.COMPLETED + update_strategy = UpdateStrategy.ONLY_FETCH_ONCE + } + + // ============================== Chapters ============================== + override fun fetchChapterList(manga: SManga): Observable> { + val chapter = SChapter.create().apply { + name = "Hentai" + chapter_number = 1F + url = manga.url + } + + return Observable.just(listOf(chapter)) + } + + override fun chapterListSelector(): String { + throw UnsupportedOperationException("Not used.") + } + + override fun chapterFromElement(element: Element): SChapter { + throw UnsupportedOperationException("Not used.") + } + + // =============================== Pages ================================ + override fun pageListParse(document: Document): List { + return document.select("div.ipsGrid div.ipsType_center > img") + .mapIndexed { index, item -> + Page(index, "", item.absUrl("data-src")) + } + } + + override fun imageUrlParse(document: Document): String { + throw UnsupportedOperationException("Not used.") + } + + companion object { + const val PREFIX_SEARCH = "id:" + } +} diff --git a/src/pt/bakai/src/eu/kanade/tachiyomi/extension/pt/bakai/BakaiUrlActivity.kt b/src/pt/bakai/src/eu/kanade/tachiyomi/extension/pt/bakai/BakaiUrlActivity.kt new file mode 100644 index 000000000..c83529341 --- /dev/null +++ b/src/pt/bakai/src/eu/kanade/tachiyomi/extension/pt/bakai/BakaiUrlActivity.kt @@ -0,0 +1,41 @@ +package eu.kanade.tachiyomi.extension.pt.bakai + +import android.app.Activity +import android.content.ActivityNotFoundException +import android.content.Intent +import android.os.Bundle +import android.util.Log +import kotlin.system.exitProcess + +/** + * Springboard that accepts https://bakai.org/hentai/ intents + * and redirects them to the main Tachiyomi process. + */ +class BakaiUrlActivity : Activity() { + + private val tag = javaClass.simpleName + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + val pathSegments = intent?.data?.pathSegments + if (pathSegments != null && pathSegments.size > 1) { + val item = pathSegments[1] + val mainIntent = Intent().apply { + action = "eu.kanade.tachiyomi.SEARCH" + putExtra("query", "${Bakai.PREFIX_SEARCH}$item") + putExtra("filter", packageName) + } + + try { + startActivity(mainIntent) + } catch (e: ActivityNotFoundException) { + Log.e(tag, e.toString()) + } + } else { + Log.e(tag, "could not parse uri from intent $intent") + } + + finish() + exitProcess(0) + } +}