Added support for gallery unregistered in hitomi
This commit is contained in:
24
libpupil/src/main/java/xyz/quaver/Code.kt
Normal file
24
libpupil/src/main/java/xyz/quaver/Code.kt
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2020 tom5079
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package xyz.quaver
|
||||
|
||||
|
||||
enum class Code {
|
||||
HITOMI,
|
||||
HIYOBI,
|
||||
SORALA
|
||||
}
|
||||
@@ -18,6 +18,7 @@ package xyz.quaver.hitomi
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import org.jsoup.Jsoup
|
||||
import xyz.quaver.Code
|
||||
import java.net.URL
|
||||
import java.net.URLDecoder
|
||||
import java.nio.ByteBuffer
|
||||
@@ -67,6 +68,7 @@ fun fetchNozomi(area: String? = null, tag: String = "index", language: String =
|
||||
|
||||
@Serializable
|
||||
data class GalleryBlock(
|
||||
val code: Code,
|
||||
val id: Int,
|
||||
val galleryUrl: String,
|
||||
val thumbnails: List<String>,
|
||||
@@ -102,7 +104,7 @@ fun getGalleryBlock(galleryID: Int) : GalleryBlock? {
|
||||
href.slice(5 until href.indexOf("-all"))
|
||||
}
|
||||
|
||||
return GalleryBlock(galleryID, galleryUrl, thumbnails, title, artists, series, type, language, relatedTags)
|
||||
return GalleryBlock(Code.HITOMI, galleryID, galleryUrl, thumbnails, title, artists, series, type, language, relatedTags)
|
||||
} catch (e: Exception) {
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package xyz.quaver.hitomi
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import org.jsoup.Jsoup
|
||||
import xyz.quaver.Code
|
||||
|
||||
fun getReferer(galleryID: Int) = "https://hitomi.la/reader/$galleryID.html"
|
||||
|
||||
@@ -31,13 +32,7 @@ data class GalleryInfo(
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Reader(val code: Code, val title: String, val galleryInfo: List<GalleryInfo>) {
|
||||
enum class Code {
|
||||
HITOMI,
|
||||
HIYOBI,
|
||||
SORALA
|
||||
}
|
||||
}
|
||||
data class Reader(val code: Code, val title: String, val galleryInfo: List<GalleryInfo>)
|
||||
|
||||
//Set header `Referer` to reader url to avoid 403 error
|
||||
fun getReader(galleryID: Int) : Reader {
|
||||
@@ -45,5 +40,5 @@ fun getReader(galleryID: Int) : Reader {
|
||||
|
||||
val doc = Jsoup.connect(readerUrl).get()
|
||||
|
||||
return Reader(Reader.Code.HITOMI, doc.title(), getGalleryInfo(galleryID))
|
||||
return Reader(Code.HITOMI, doc.title(), getGalleryInfo(galleryID))
|
||||
}
|
||||
49
libpupil/src/main/java/xyz/quaver/hiyobi/galleryblock.kt
Normal file
49
libpupil/src/main/java/xyz/quaver/hiyobi/galleryblock.kt
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright 2020 tom5079
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package xyz.quaver.hiyobi
|
||||
|
||||
import org.jsoup.Jsoup
|
||||
import xyz.quaver.Code
|
||||
import xyz.quaver.hitomi.GalleryBlock
|
||||
import xyz.quaver.hitomi.protocol
|
||||
|
||||
fun getGalleryBlock(galleryID: Int) : GalleryBlock? {
|
||||
val url = "$protocol//$hiyobi/search/$galleryID"
|
||||
|
||||
try {
|
||||
val doc = Jsoup.connect(url).get()
|
||||
|
||||
val galleryBlock = doc.selectFirst(".gallery-content")
|
||||
|
||||
val galleryUrl = galleryBlock.selectFirst("a").attr("href")
|
||||
|
||||
val thumbnails = listOf(galleryBlock.selectFirst("img").attr("abs:src"))
|
||||
|
||||
val title = galleryBlock.selectFirst("b").text()
|
||||
val artists = galleryBlock.select("tr:matches(작가) a[href~=artist]").map { it.text() }
|
||||
val series = galleryBlock.select("tr:matches(원작) a").map { it.attr("href").substringAfter("series:").replace('_', ' ') }
|
||||
val type = galleryBlock.selectFirst("tr:matches(종류) a").attr("href").substringAfter("type:").replace('_', ' ')
|
||||
|
||||
val language = "korean"
|
||||
|
||||
val relatedTags = galleryBlock.select("tr:matches(태그) a").map { it.attr("href").substringAfterLast('/').replace('_', ' ') }
|
||||
|
||||
return GalleryBlock(Code.HIYOBI, galleryID, galleryUrl, thumbnails, title, artists, series, type, language, relatedTags)
|
||||
} catch (e: Exception) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ package xyz.quaver.hiyobi
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.list
|
||||
import org.jsoup.Jsoup
|
||||
import xyz.quaver.Code
|
||||
import xyz.quaver.hitomi.GalleryInfo
|
||||
import xyz.quaver.hitomi.Reader
|
||||
import xyz.quaver.hitomi.protocol
|
||||
@@ -76,7 +77,7 @@ fun getReader(galleryID: Int) : Reader {
|
||||
}
|
||||
)
|
||||
|
||||
return Reader(Reader.Code.HIYOBI, title, galleryInfo)
|
||||
return Reader(Code.HIYOBI, title, galleryInfo)
|
||||
}
|
||||
|
||||
fun createImgList(galleryID: Int, reader: Reader, lowQuality: Boolean = false) =
|
||||
|
||||
@@ -102,4 +102,11 @@ class UnitTest {
|
||||
|
||||
print(result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun test_hiyobi_galleryBlock() {
|
||||
val galleryBlock = xyz.quaver.hiyobi.getGalleryBlock(10000027)
|
||||
|
||||
print(galleryBlock)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user