Fix hitomi browse/latest
This commit is contained in:
parent
28d05b629f
commit
43dc12a0f3
@ -20,6 +20,7 @@ import exh.HITOMI_SOURCE_ID
|
|||||||
import exh.metadata.EMULATED_TAG_NAMESPACE
|
import exh.metadata.EMULATED_TAG_NAMESPACE
|
||||||
import exh.metadata.models.HitomiGalleryMetadata
|
import exh.metadata.models.HitomiGalleryMetadata
|
||||||
import exh.metadata.models.HitomiGalleryMetadata.Companion.BASE_URL
|
import exh.metadata.models.HitomiGalleryMetadata.Companion.BASE_URL
|
||||||
|
import exh.metadata.models.HitomiGalleryMetadata.Companion.LTN_BASE_URL
|
||||||
import exh.metadata.models.HitomiGalleryMetadata.Companion.hlIdFromUrl
|
import exh.metadata.models.HitomiGalleryMetadata.Companion.hlIdFromUrl
|
||||||
import exh.metadata.models.HitomiPage
|
import exh.metadata.models.HitomiPage
|
||||||
import exh.metadata.models.HitomiSkeletonGalleryMetadata
|
import exh.metadata.models.HitomiSkeletonGalleryMetadata
|
||||||
@ -41,6 +42,8 @@ import rx.schedulers.Schedulers
|
|||||||
import rx.subjects.AsyncSubject
|
import rx.subjects.AsyncSubject
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
import java.nio.BufferUnderflowException
|
||||||
|
import java.nio.ByteBuffer
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue
|
import java.util.concurrent.ConcurrentLinkedQueue
|
||||||
@ -268,26 +271,12 @@ class Hitomi(private val context: Context)
|
|||||||
|
|
||||||
private val cacheLocks = arrayOf(ReentrantLock(), ReentrantLock())
|
private val cacheLocks = arrayOf(ReentrantLock(), ReentrantLock())
|
||||||
|
|
||||||
override fun popularMangaRequest(page: Int) = GET("$BASE_URL/popular-all-$page.html")
|
override fun popularMangaRequest(page: Int) = GET("$LTN_BASE_URL/popular-all.nozomi")
|
||||||
|
|
||||||
override fun popularMangaParse(response: Response) = throw UnsupportedOperationException("Unused method called!")
|
override fun popularMangaParse(response: Response) = throw UnsupportedOperationException("Unused method called!")
|
||||||
override fun latestUpdatesParse(response: Response) = throw UnsupportedOperationException("Unused method called!")
|
override fun latestUpdatesParse(response: Response) = throw UnsupportedOperationException("Unused method called!")
|
||||||
|
|
||||||
override fun latestUpdatesRequest(page: Int) = GET("$BASE_URL/index-all-$page.html")
|
override fun latestUpdatesRequest(page: Int) = GET("$LTN_BASE_URL/index-all.nozomi")
|
||||||
|
|
||||||
private fun parsePage(doc: Document): List<HitomiSkeletonGalleryMetadata> {
|
|
||||||
return doc.select(".gallery-content > div").map {
|
|
||||||
HitomiSkeletonGalleryMetadata().apply {
|
|
||||||
it.select("h1 > a").let {
|
|
||||||
url = it.attr("href")
|
|
||||||
|
|
||||||
title = it.text()
|
|
||||||
}
|
|
||||||
|
|
||||||
thumbnailUrl = "https:" + it.select(".dj-img1 > img").attr("src")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readerUrl(hlId: String) = "$BASE_URL/reader/$hlId.html"
|
fun readerUrl(hlId: String) = "$BASE_URL/reader/$hlId.html"
|
||||||
|
|
||||||
@ -457,43 +446,40 @@ class Hitomi(private val context: Context)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fetchAndResolveRequest(request: Request): Observable<MangasPage> {
|
private fun fetchAndResolveRequest(page: Int, request: Request): Observable<MangasPage> {
|
||||||
//Begin pre-loading cache
|
//Begin pre-loading cache
|
||||||
ensureCacheLoaded(false).subscribeOn(Schedulers.computation()).subscribe()
|
ensureCacheLoaded(false).subscribeOn(Schedulers.computation()).subscribe()
|
||||||
|
|
||||||
return client.newCall(request)
|
return client.newCall(request)
|
||||||
.asObservableSuccess()
|
.asObservableSuccess()
|
||||||
.map { response ->
|
.map { response ->
|
||||||
val doc = response.asJsoup()
|
val buffer = ByteBuffer.wrap(response.body()!!.bytes())
|
||||||
|
|
||||||
val res = parsePage(doc)
|
val out = mutableListOf<SManga>()
|
||||||
val sManga = res.map {
|
|
||||||
SManga.create().apply {
|
|
||||||
setUrlWithoutDomain(it.url!!)
|
|
||||||
|
|
||||||
title = it.title!!
|
try {
|
||||||
|
while(true) {
|
||||||
|
out += SManga.create().apply {
|
||||||
|
setUrlWithoutDomain("$BASE_URL/galleries/${buffer.int}.html")
|
||||||
|
|
||||||
it.thumbnailUrl?.let {
|
title = "Loading..."
|
||||||
thumbnail_url = it
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch(e: BufferUnderflowException) {}
|
||||||
val pagingScript = doc.getElementsByTag("script").map { it.html().trim() }.find {
|
|
||||||
it.startsWith("insert_paging")
|
|
||||||
} ?: ""
|
|
||||||
|
|
||||||
val curPage = pagingScript.substringAfterLast("', ").substringBefore(',').toInt()
|
val offset = PAGE_SIZE * (page - 1)
|
||||||
val endPage = pagingScript.substringAfterLast(", ").removeSuffix(");").toInt()
|
val endIndex = Math.min(offset + PAGE_SIZE, out.size)
|
||||||
|
|
||||||
MangasPage(sManga, curPage < endPage)
|
MangasPage(out.subList(offset, endIndex),
|
||||||
|
endIndex < out.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fetchPopularManga(page: Int)
|
override fun fetchPopularManga(page: Int)
|
||||||
= fetchAndResolveRequest(popularMangaRequest(page))
|
= fetchAndResolveRequest(page, popularMangaRequest(page))
|
||||||
override fun fetchLatestUpdates(page: Int)
|
override fun fetchLatestUpdates(page: Int)
|
||||||
= fetchAndResolveRequest(latestUpdatesRequest(page))
|
= fetchAndResolveRequest(page, latestUpdatesRequest(page))
|
||||||
|
|
||||||
private fun shouldRefreshGalleryFiles(): Boolean {
|
private fun shouldRefreshGalleryFiles(): Boolean {
|
||||||
val timeDiff = System.currentTimeMillis() - prefs.eh_hl_lastRefresh().getOrDefault()
|
val timeDiff = System.currentTimeMillis() - prefs.eh_hl_lastRefresh().getOrDefault()
|
||||||
|
@ -26,9 +26,6 @@ class CatalogueGridHolder(private val view: View, private val adapter: FlexibleA
|
|||||||
* @param manga the manga to bind.
|
* @param manga the manga to bind.
|
||||||
*/
|
*/
|
||||||
override fun onSetValues(manga: Manga) {
|
override fun onSetValues(manga: Manga) {
|
||||||
// Set manga title
|
|
||||||
title.text = manga.title
|
|
||||||
|
|
||||||
// Set alpha of thumbnail.
|
// Set alpha of thumbnail.
|
||||||
thumbnail.alpha = if (manga.favorite) 0.3f else 1.0f
|
thumbnail.alpha = if (manga.favorite) 0.3f else 1.0f
|
||||||
|
|
||||||
@ -36,6 +33,9 @@ class CatalogueGridHolder(private val view: View, private val adapter: FlexibleA
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun setImage(manga: Manga) {
|
override fun setImage(manga: Manga) {
|
||||||
|
// Set manga title
|
||||||
|
title.text = manga.title
|
||||||
|
|
||||||
GlideApp.with(view.context).clear(thumbnail)
|
GlideApp.with(view.context).clear(thumbnail)
|
||||||
if (!manga.thumbnail_url.isNullOrEmpty()) {
|
if (!manga.thumbnail_url.isNullOrEmpty()) {
|
||||||
GlideApp.with(view.context)
|
GlideApp.with(view.context)
|
||||||
|
@ -29,13 +29,14 @@ class CatalogueListHolder(private val view: View, adapter: FlexibleAdapter<*>) :
|
|||||||
* @param manga the manga to bind.
|
* @param manga the manga to bind.
|
||||||
*/
|
*/
|
||||||
override fun onSetValues(manga: Manga) {
|
override fun onSetValues(manga: Manga) {
|
||||||
title.text = manga.title
|
|
||||||
title.setTextColor(if (manga.favorite) favoriteColor else unfavoriteColor)
|
title.setTextColor(if (manga.favorite) favoriteColor else unfavoriteColor)
|
||||||
|
|
||||||
setImage(manga)
|
setImage(manga)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setImage(manga: Manga) {
|
override fun setImage(manga: Manga) {
|
||||||
|
title.text = manga.title
|
||||||
|
|
||||||
GlideApp.with(view.context).clear(thumbnail)
|
GlideApp.with(view.context).clear(thumbnail)
|
||||||
if (!manga.thumbnail_url.isNullOrEmpty()) {
|
if (!manga.thumbnail_url.isNullOrEmpty()) {
|
||||||
GlideApp.with(view.context)
|
GlideApp.with(view.context)
|
||||||
|
@ -140,6 +140,7 @@ open class HitomiGalleryMetadata : RealmObject(), SearchableGalleryMetadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
val LTN_BASE_URL = "https://ltn.hitomi.la"
|
||||||
val BASE_URL = "https://hitomi.la"
|
val BASE_URL = "https://hitomi.la"
|
||||||
|
|
||||||
fun hlIdFromUrl(url: String)
|
fun hlIdFromUrl(url: String)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user