[Ru]Newbiew. Add branches and work with this (#10503)
* [Ru]Newbiew. Add branches and work with this * [RU]Newbie. Remove unused dto Co-authored-by: pavkazzz <me@pavkazzz.ru>
This commit is contained in:
parent
3782a58f30
commit
9feb6a165e
|
@ -6,7 +6,7 @@ ext {
|
||||||
extName = 'Newbie'
|
extName = 'Newbie'
|
||||||
pkgNameSuffix = 'ru.newbie'
|
pkgNameSuffix = 'ru.newbie'
|
||||||
extClass = '.Newbie'
|
extClass = '.Newbie'
|
||||||
extVersionCode = 4
|
extVersionCode = 5
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package eu.kanade.tachiyomi.extension.ru.newbie
|
package eu.kanade.tachiyomi.extension.ru.newbie
|
||||||
|
|
||||||
import BookDto
|
import BookDto
|
||||||
|
import BranchesDto
|
||||||
import LibraryDto
|
import LibraryDto
|
||||||
import MangaDetDto
|
import MangaDetDto
|
||||||
import PageDto
|
import PageDto
|
||||||
|
@ -35,6 +36,7 @@ import java.text.DecimalFormat
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
class Newbie : HttpSource() {
|
class Newbie : HttpSource() {
|
||||||
override val name = "Newbie"
|
override val name = "Newbie"
|
||||||
|
|
||||||
|
@ -44,6 +46,8 @@ class Newbie : HttpSource() {
|
||||||
|
|
||||||
override val supportsLatest = true
|
override val supportsLatest = true
|
||||||
|
|
||||||
|
private var branches = mutableMapOf<String, List<BranchesDto>>()
|
||||||
|
|
||||||
override fun headersBuilder(): Headers.Builder = Headers.Builder()
|
override fun headersBuilder(): Headers.Builder = Headers.Builder()
|
||||||
.add("User-Agent", "Tachiyomi")
|
.add("User-Agent", "Tachiyomi")
|
||||||
.add("Referer", baseUrl)
|
.add("Referer", baseUrl)
|
||||||
|
@ -189,6 +193,7 @@ class Newbie : HttpSource() {
|
||||||
private fun titleDetailsRequest(manga: SManga): Request {
|
private fun titleDetailsRequest(manga: SManga): Request {
|
||||||
return GET(API_URL + "/projects/" + manga.url, headers)
|
return GET(API_URL + "/projects/" + manga.url, headers)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Workaround to allow "Open in browser" use the real URL.
|
// Workaround to allow "Open in browser" use the real URL.
|
||||||
override fun fetchMangaDetails(manga: SManga): Observable<SManga> {
|
override fun fetchMangaDetails(manga: SManga): Observable<SManga> {
|
||||||
return client.newCall(titleDetailsRequest(manga))
|
return client.newCall(titleDetailsRequest(manga))
|
||||||
|
@ -197,12 +202,14 @@ class Newbie : HttpSource() {
|
||||||
mangaDetailsParse(response).apply { initialized = true }
|
mangaDetailsParse(response).apply { initialized = true }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun mangaDetailsRequest(manga: SManga): Request {
|
override fun mangaDetailsRequest(manga: SManga): Request {
|
||||||
return GET(baseUrl + "/p/" + manga.url, headers)
|
return GET(baseUrl + "/p/" + manga.url, headers)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun mangaDetailsParse(response: Response): SManga {
|
override fun mangaDetailsParse(response: Response): SManga {
|
||||||
val series = json.decodeFromString<MangaDetDto>(response.body!!.string())
|
val series = json.decodeFromString<MangaDetDto>(response.body!!.string())
|
||||||
|
branches[series.title.en] = series.branches
|
||||||
return series.toSManga()
|
return series.toSManga()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,9 +222,39 @@ class Newbie : HttpSource() {
|
||||||
return chapterName
|
return chapterName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun mangaBranches(manga: SManga): List<BranchesDto> {
|
||||||
|
val response = client.newCall(titleDetailsRequest(manga)).execute()
|
||||||
|
val series = json.decodeFromString<MangaDetDto>(response.body!!.string())
|
||||||
|
branches[series.title.en] = series.branches
|
||||||
|
return series.branches
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun selector(b: BranchesDto): Boolean = b.is_default
|
||||||
|
override fun fetchChapterList(manga: SManga): Observable<List<SChapter>> {
|
||||||
|
val branch = branches.getOrElse(manga.title) { mangaBranches(manga) }
|
||||||
|
return when {
|
||||||
|
branch.isEmpty() -> {
|
||||||
|
return Observable.just(listOf())
|
||||||
|
}
|
||||||
|
manga.status == SManga.LICENSED -> {
|
||||||
|
Observable.error(Exception("Лицензировано - Нет глав"))
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
val branchId = branch.first { selector(it) }.id
|
||||||
|
client.newCall(chapterListRequest(branchId))
|
||||||
|
.asObservableSuccess()
|
||||||
|
.map { response ->
|
||||||
|
chapterListParse(response)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun chapterListParse(response: Response): List<SChapter> {
|
override fun chapterListParse(response: Response): List<SChapter> {
|
||||||
val chapters = json.decodeFromString<SeriesWrapperDto<List<BookDto>>>(response.body!!.string())
|
val body = response.body!!.string()
|
||||||
return chapters.items.filter { it.is_available == true }.map { chapter ->
|
val chapters = json.decodeFromString<SeriesWrapperDto<List<BookDto>>>(body)
|
||||||
|
|
||||||
|
return chapters.items.filter { it.is_available }.map { chapter ->
|
||||||
SChapter.create().apply {
|
SChapter.create().apply {
|
||||||
chapter_number = chapter.number
|
chapter_number = chapter.number
|
||||||
name = chapterName(chapter)
|
name = chapterName(chapter)
|
||||||
|
@ -227,8 +264,12 @@ class Newbie : HttpSource() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
override fun chapterListRequest(manga: SManga): Request {
|
override fun chapterListRequest(manga: SManga): Request = throw NotImplementedError("Unused")
|
||||||
return GET(API_URL + "/branches/" + manga.url + "/chapters?reverse=true&size=1000000", headers)
|
private fun chapterListRequest(branch: Long): Request {
|
||||||
|
return GET(
|
||||||
|
"$API_URL/branches/$branch/chapters?reverse=true&size=1000000",
|
||||||
|
headers
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.N)
|
@TargetApi(Build.VERSION_CODES.N)
|
||||||
|
@ -247,6 +288,7 @@ class Newbie : HttpSource() {
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun pageListParse(response: Response): List<Page> = throw Exception("Not used")
|
override fun pageListParse(response: Response): List<Page> = throw Exception("Not used")
|
||||||
override fun fetchPageList(chapter: SChapter): Observable<List<Page>> {
|
override fun fetchPageList(chapter: SChapter): Observable<List<Page>> {
|
||||||
return client.newCall(pageListRequest(chapter))
|
return client.newCall(pageListRequest(chapter))
|
||||||
|
@ -255,6 +297,7 @@ class Newbie : HttpSource() {
|
||||||
pageListParse(response, chapter)
|
pageListParse(response, chapter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fetchImageUrl(page: Page): Observable<String> = Observable.just(page.imageUrl!!)
|
override fun fetchImageUrl(page: Page): Observable<String> = Observable.just(page.imageUrl!!)
|
||||||
|
|
||||||
override fun imageUrlRequest(page: Page): Request = throw NotImplementedError("Unused")
|
override fun imageUrlRequest(page: Page): Request = throw NotImplementedError("Unused")
|
||||||
|
@ -352,9 +395,11 @@ class Newbie : HttpSource() {
|
||||||
CheckFilter("юри", "16"),
|
CheckFilter("юри", "16"),
|
||||||
CheckFilter("яой", "32"),
|
CheckFilter("яой", "32"),
|
||||||
)
|
)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val API_URL = "https://api.newmanga.org/v2"
|
private const val API_URL = "https://api.newmanga.org/v2"
|
||||||
private const val IMAGE_URL = "https://storage.newmanga.org"
|
private const val IMAGE_URL = "https://storage.newmanga.org"
|
||||||
}
|
}
|
||||||
|
|
||||||
private val json: Json by injectLazy()
|
private val json: Json by injectLazy()
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,21 +2,21 @@ import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class TagsDto(
|
data class TagsDto(
|
||||||
val id: Int,
|
|
||||||
val title: TitleDto
|
val title: TitleDto
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class BranchesDto(
|
data class BranchesDto(
|
||||||
val id: Long,
|
val id: Long,
|
||||||
val count_chapters: Int
|
val is_default: Boolean
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class ImgsDto(
|
data class ImgsDto(
|
||||||
val large: String,
|
val large: String,
|
||||||
val small: String,
|
val small: String,
|
||||||
val thumbnail: String
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class ImgDto(
|
data class ImgDto(
|
||||||
val srcset: ImgsDto,
|
val srcset: ImgsDto,
|
||||||
|
@ -47,13 +47,13 @@ data class MangaDetDto(
|
||||||
val author: AuthorDto?,
|
val author: AuthorDto?,
|
||||||
val artist: AuthorDto?,
|
val artist: AuthorDto?,
|
||||||
val description: String,
|
val description: String,
|
||||||
val release_date: String,
|
|
||||||
val image: ImgDto,
|
val image: ImgDto,
|
||||||
val genres: List<TagsDto>,
|
val genres: List<TagsDto>,
|
||||||
val type: String,
|
val type: String,
|
||||||
val status: String,
|
val status: String,
|
||||||
val rating: Float,
|
val rating: Float,
|
||||||
val adult: String?
|
val adult: String?,
|
||||||
|
val branches: List<BranchesDto>,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
|
Loading…
Reference in New Issue