mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-11-04 08:08:55 +01:00 
			
		
		
		
	Remove 1.x source models (#7781)
This commit is contained in:
		@@ -9,10 +9,6 @@ import eu.kanade.tachiyomi.source.model.FilterList
 | 
			
		||||
import eu.kanade.tachiyomi.source.model.MangasPage
 | 
			
		||||
import eu.kanade.tachiyomi.source.model.SChapter
 | 
			
		||||
import eu.kanade.tachiyomi.source.model.SManga
 | 
			
		||||
import eu.kanade.tachiyomi.source.model.toChapterInfo
 | 
			
		||||
import eu.kanade.tachiyomi.source.model.toMangaInfo
 | 
			
		||||
import eu.kanade.tachiyomi.source.model.toSChapter
 | 
			
		||||
import eu.kanade.tachiyomi.source.model.toSManga
 | 
			
		||||
import eu.kanade.tachiyomi.util.chapter.ChapterRecognition
 | 
			
		||||
import eu.kanade.tachiyomi.util.lang.compareToCaseInsensitiveNaturalOrder
 | 
			
		||||
import eu.kanade.tachiyomi.util.storage.DiskUtil
 | 
			
		||||
@@ -20,17 +16,11 @@ import eu.kanade.tachiyomi.util.storage.EpubFile
 | 
			
		||||
import eu.kanade.tachiyomi.util.system.ImageUtil
 | 
			
		||||
import eu.kanade.tachiyomi.util.system.logcat
 | 
			
		||||
import kotlinx.coroutines.runBlocking
 | 
			
		||||
import kotlinx.serialization.Serializable
 | 
			
		||||
import kotlinx.serialization.json.Json
 | 
			
		||||
import kotlinx.serialization.json.JsonObject
 | 
			
		||||
import kotlinx.serialization.json.contentOrNull
 | 
			
		||||
import kotlinx.serialization.json.decodeFromStream
 | 
			
		||||
import kotlinx.serialization.json.intOrNull
 | 
			
		||||
import kotlinx.serialization.json.jsonArray
 | 
			
		||||
import kotlinx.serialization.json.jsonPrimitive
 | 
			
		||||
import logcat.LogPriority
 | 
			
		||||
import rx.Observable
 | 
			
		||||
import tachiyomi.source.model.ChapterInfo
 | 
			
		||||
import tachiyomi.source.model.MangaInfo
 | 
			
		||||
import uy.kohesive.injekt.injectLazy
 | 
			
		||||
import java.io.File
 | 
			
		||||
import java.io.FileInputStream
 | 
			
		||||
@@ -120,11 +110,10 @@ class LocalSource(
 | 
			
		||||
 | 
			
		||||
        // Fetch chapters of all the manga
 | 
			
		||||
        mangas.forEach { manga ->
 | 
			
		||||
            val mangaInfo = manga.toMangaInfo()
 | 
			
		||||
            runBlocking {
 | 
			
		||||
                val chapters = getChapterList(mangaInfo)
 | 
			
		||||
                val chapters = getChapterList(manga)
 | 
			
		||||
                if (chapters.isNotEmpty()) {
 | 
			
		||||
                    val chapter = chapters.last().toSChapter()
 | 
			
		||||
                    val chapter = chapters.last()
 | 
			
		||||
                    val format = getFormat(chapter)
 | 
			
		||||
 | 
			
		||||
                    if (format is Format.Epub) {
 | 
			
		||||
@@ -145,47 +134,48 @@ class LocalSource(
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Manga details related
 | 
			
		||||
    override suspend fun getMangaDetails(manga: MangaInfo): MangaInfo {
 | 
			
		||||
        var mangaInfo = manga
 | 
			
		||||
 | 
			
		||||
    override suspend fun getMangaDetails(manga: SManga): SManga {
 | 
			
		||||
        val baseDirsFile = getBaseDirectoriesFiles(context)
 | 
			
		||||
 | 
			
		||||
        val coverFile = getCoverFile(manga.key, baseDirsFile)
 | 
			
		||||
 | 
			
		||||
        coverFile?.let {
 | 
			
		||||
            mangaInfo = mangaInfo.copy(cover = it.absolutePath)
 | 
			
		||||
        getCoverFile(manga.url, baseDirsFile)?.let {
 | 
			
		||||
            manga.thumbnail_url = it.absolutePath
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        val localDetails = getMangaDirsFiles(manga.key, baseDirsFile)
 | 
			
		||||
        getMangaDirsFiles(manga.url, baseDirsFile)
 | 
			
		||||
            .firstOrNull { it.extension.equals("json", ignoreCase = true) }
 | 
			
		||||
            ?.let { file ->
 | 
			
		||||
                json.decodeFromStream<MangaDetails>(file.inputStream()).run {
 | 
			
		||||
                    title?.let { manga.title = it }
 | 
			
		||||
                    author?.let { manga.author = it }
 | 
			
		||||
                    artist?.let { manga.artist = it }
 | 
			
		||||
                    description?.let { manga.description = it }
 | 
			
		||||
                    genre?.let { manga.genre = it.joinToString() }
 | 
			
		||||
                    status?.let { manga.status = it }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        if (localDetails != null) {
 | 
			
		||||
            val obj = json.decodeFromStream<JsonObject>(localDetails.inputStream())
 | 
			
		||||
 | 
			
		||||
            mangaInfo = mangaInfo.copy(
 | 
			
		||||
                title = obj["title"]?.jsonPrimitive?.contentOrNull ?: mangaInfo.title,
 | 
			
		||||
                author = obj["author"]?.jsonPrimitive?.contentOrNull ?: mangaInfo.author,
 | 
			
		||||
                artist = obj["artist"]?.jsonPrimitive?.contentOrNull ?: mangaInfo.artist,
 | 
			
		||||
                description = obj["description"]?.jsonPrimitive?.contentOrNull ?: mangaInfo.description,
 | 
			
		||||
                genres = obj["genre"]?.jsonArray?.map { it.jsonPrimitive.content } ?: mangaInfo.genres,
 | 
			
		||||
                status = obj["status"]?.jsonPrimitive?.intOrNull ?: mangaInfo.status,
 | 
			
		||||
            )
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return mangaInfo
 | 
			
		||||
        return manga
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Chapters
 | 
			
		||||
    override suspend fun getChapterList(manga: MangaInfo): List<ChapterInfo> {
 | 
			
		||||
        val sManga = manga.toSManga()
 | 
			
		||||
    @Serializable
 | 
			
		||||
    class MangaDetails(
 | 
			
		||||
        val title: String? = null,
 | 
			
		||||
        val author: String? = null,
 | 
			
		||||
        val artist: String? = null,
 | 
			
		||||
        val description: String? = null,
 | 
			
		||||
        val genre: List<String>? = null,
 | 
			
		||||
        val status: Int? = null,
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    // Chapters
 | 
			
		||||
    override suspend fun getChapterList(manga: SManga): List<SChapter> {
 | 
			
		||||
        val baseDirsFile = getBaseDirectoriesFiles(context)
 | 
			
		||||
        return getMangaDirsFiles(manga.key, baseDirsFile)
 | 
			
		||||
        return getMangaDirsFiles(manga.url, baseDirsFile)
 | 
			
		||||
            // Only keep supported formats
 | 
			
		||||
            .filter { it.isDirectory || isSupportedFile(it.extension) }
 | 
			
		||||
            .map { chapterFile ->
 | 
			
		||||
                SChapter.create().apply {
 | 
			
		||||
                    url = "${manga.key}/${chapterFile.name}"
 | 
			
		||||
                    url = "${manga.url}/${chapterFile.name}"
 | 
			
		||||
                    name = if (chapterFile.isDirectory) {
 | 
			
		||||
                        chapterFile.name
 | 
			
		||||
                    } else {
 | 
			
		||||
@@ -193,7 +183,7 @@ class LocalSource(
 | 
			
		||||
                    }
 | 
			
		||||
                    date_upload = chapterFile.lastModified()
 | 
			
		||||
 | 
			
		||||
                    chapter_number = ChapterRecognition.parseChapterNumber(sManga.title, this.name, this.chapter_number)
 | 
			
		||||
                    chapter_number = ChapterRecognition.parseChapterNumber(manga.title, this.name, this.chapter_number)
 | 
			
		||||
 | 
			
		||||
                    val format = getFormat(chapterFile)
 | 
			
		||||
                    if (format is Format.Epub) {
 | 
			
		||||
@@ -203,9 +193,8 @@ class LocalSource(
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            .map { it.toChapterInfo() }
 | 
			
		||||
            .sortedWith { c1, c2 ->
 | 
			
		||||
                val c = c2.number.compareTo(c1.number)
 | 
			
		||||
                val c = c2.chapter_number.compareTo(c1.chapter_number)
 | 
			
		||||
                if (c == 0) c2.name.compareToCaseInsensitiveNaturalOrder(c1.name) else c
 | 
			
		||||
            }
 | 
			
		||||
            .toList()
 | 
			
		||||
@@ -224,7 +213,7 @@ class LocalSource(
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    // Unused stuff
 | 
			
		||||
    override suspend fun getPageList(chapter: ChapterInfo) = throw UnsupportedOperationException("Unused")
 | 
			
		||||
    override suspend fun getPageList(chapter: SChapter) = throw UnsupportedOperationException("Unused")
 | 
			
		||||
 | 
			
		||||
    // Miscellaneous
 | 
			
		||||
    private fun isSupportedFile(extension: String): Boolean {
 | 
			
		||||
 
 | 
			
		||||
@@ -7,34 +7,27 @@ import eu.kanade.tachiyomi.extension.ExtensionManager
 | 
			
		||||
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.toChapterInfo
 | 
			
		||||
import eu.kanade.tachiyomi.source.model.toMangaInfo
 | 
			
		||||
import eu.kanade.tachiyomi.source.model.toPageUrl
 | 
			
		||||
import eu.kanade.tachiyomi.source.model.toSChapter
 | 
			
		||||
import eu.kanade.tachiyomi.source.model.toSManga
 | 
			
		||||
import eu.kanade.tachiyomi.util.lang.awaitSingle
 | 
			
		||||
import rx.Observable
 | 
			
		||||
import tachiyomi.source.model.ChapterInfo
 | 
			
		||||
import tachiyomi.source.model.MangaInfo
 | 
			
		||||
import uy.kohesive.injekt.Injekt
 | 
			
		||||
import uy.kohesive.injekt.api.get
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * A basic interface for creating a source. It could be an online source, a local source, etc...
 | 
			
		||||
 */
 | 
			
		||||
interface Source : tachiyomi.source.Source {
 | 
			
		||||
interface Source {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Id for the source. Must be unique.
 | 
			
		||||
     */
 | 
			
		||||
    override val id: Long
 | 
			
		||||
    val id: Long
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Name of the source.
 | 
			
		||||
     */
 | 
			
		||||
    override val name: String
 | 
			
		||||
    val name: String
 | 
			
		||||
 | 
			
		||||
    override val lang: String
 | 
			
		||||
    val lang: String
 | 
			
		||||
        get() = ""
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -75,29 +68,24 @@ interface Source : tachiyomi.source.Source {
 | 
			
		||||
     * [1.x API] Get the updated details for a manga.
 | 
			
		||||
     */
 | 
			
		||||
    @Suppress("DEPRECATION")
 | 
			
		||||
    override suspend fun getMangaDetails(manga: MangaInfo): MangaInfo {
 | 
			
		||||
        val sManga = manga.toSManga()
 | 
			
		||||
        val networkManga = fetchMangaDetails(sManga).awaitSingle()
 | 
			
		||||
        sManga.copyFrom(networkManga)
 | 
			
		||||
        return sManga.toMangaInfo()
 | 
			
		||||
    suspend fun getMangaDetails(manga: SManga): SManga {
 | 
			
		||||
        return fetchMangaDetails(manga).awaitSingle()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * [1.x API] Get all the available chapters for a manga.
 | 
			
		||||
     */
 | 
			
		||||
    @Suppress("DEPRECATION")
 | 
			
		||||
    override suspend fun getChapterList(manga: MangaInfo): List<ChapterInfo> {
 | 
			
		||||
        return fetchChapterList(manga.toSManga()).awaitSingle()
 | 
			
		||||
            .map { it.toChapterInfo() }
 | 
			
		||||
    suspend fun getChapterList(manga: SManga): List<SChapter> {
 | 
			
		||||
        return fetchChapterList(manga).awaitSingle()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * [1.x API] Get the list of pages a chapter has.
 | 
			
		||||
     */
 | 
			
		||||
    @Suppress("DEPRECATION")
 | 
			
		||||
    override suspend fun getPageList(chapter: ChapterInfo): List<tachiyomi.source.model.Page> {
 | 
			
		||||
        return fetchPageList(chapter.toSChapter()).awaitSingle()
 | 
			
		||||
            .map { it.toPageUrl() }
 | 
			
		||||
    suspend fun getPageList(chapter: SChapter): List<Page> {
 | 
			
		||||
        return fetchPageList(chapter).awaitSingle()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -19,8 +19,6 @@ import kotlinx.coroutines.flow.map
 | 
			
		||||
import kotlinx.coroutines.launch
 | 
			
		||||
import kotlinx.coroutines.runBlocking
 | 
			
		||||
import rx.Observable
 | 
			
		||||
import tachiyomi.source.model.ChapterInfo
 | 
			
		||||
import tachiyomi.source.model.MangaInfo
 | 
			
		||||
 | 
			
		||||
class SourceManager(
 | 
			
		||||
    private val context: Context,
 | 
			
		||||
@@ -115,7 +113,7 @@ class SourceManager(
 | 
			
		||||
 | 
			
		||||
        override val lang: String = sourceData.lang
 | 
			
		||||
 | 
			
		||||
        override suspend fun getMangaDetails(manga: MangaInfo): MangaInfo {
 | 
			
		||||
        override suspend fun getMangaDetails(manga: SManga): SManga {
 | 
			
		||||
            throw getSourceNotInstalledException()
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -123,7 +121,7 @@ class SourceManager(
 | 
			
		||||
            return Observable.error(getSourceNotInstalledException())
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        override suspend fun getChapterList(manga: MangaInfo): List<ChapterInfo> {
 | 
			
		||||
        override suspend fun getChapterList(manga: SManga): List<SChapter> {
 | 
			
		||||
            throw getSourceNotInstalledException()
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -131,7 +129,7 @@ class SourceManager(
 | 
			
		||||
            return Observable.error(getSourceNotInstalledException())
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        override suspend fun getPageList(chapter: ChapterInfo): List<tachiyomi.source.model.Page> {
 | 
			
		||||
        override suspend fun getPageList(chapter: SChapter): List<Page> {
 | 
			
		||||
            throw getSourceNotInstalledException()
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -5,7 +5,6 @@ import eu.kanade.tachiyomi.network.ProgressListener
 | 
			
		||||
import kotlinx.serialization.Serializable
 | 
			
		||||
import kotlinx.serialization.Transient
 | 
			
		||||
import rx.subjects.Subject
 | 
			
		||||
import tachiyomi.source.model.PageUrl
 | 
			
		||||
 | 
			
		||||
@Serializable
 | 
			
		||||
open class Page(
 | 
			
		||||
@@ -65,16 +64,3 @@ open class Page(
 | 
			
		||||
        const val ERROR = 4
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fun Page.toPageUrl(): PageUrl {
 | 
			
		||||
    return PageUrl(
 | 
			
		||||
        url = this.imageUrl ?: this.url,
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fun PageUrl.toPage(index: Int): Page {
 | 
			
		||||
    return Page(
 | 
			
		||||
        index = index,
 | 
			
		||||
        imageUrl = this.url,
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,6 @@
 | 
			
		||||
package eu.kanade.tachiyomi.source.model
 | 
			
		||||
 | 
			
		||||
import data.Chapters
 | 
			
		||||
import tachiyomi.source.model.ChapterInfo
 | 
			
		||||
import java.io.Serializable
 | 
			
		||||
 | 
			
		||||
interface SChapter : Serializable {
 | 
			
		||||
@@ -38,24 +37,3 @@ interface SChapter : Serializable {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fun SChapter.toChapterInfo(): ChapterInfo {
 | 
			
		||||
    return ChapterInfo(
 | 
			
		||||
        dateUpload = this.date_upload,
 | 
			
		||||
        key = this.url,
 | 
			
		||||
        name = this.name,
 | 
			
		||||
        number = this.chapter_number,
 | 
			
		||||
        scanlator = this.scanlator ?: "",
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fun ChapterInfo.toSChapter(): SChapter {
 | 
			
		||||
    val chapter = this
 | 
			
		||||
    return SChapter.create().apply {
 | 
			
		||||
        url = chapter.key
 | 
			
		||||
        name = chapter.name
 | 
			
		||||
        date_upload = chapter.dateUpload
 | 
			
		||||
        chapter_number = chapter.number
 | 
			
		||||
        scanlator = chapter.scanlator
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,6 @@
 | 
			
		||||
package eu.kanade.tachiyomi.source.model
 | 
			
		||||
 | 
			
		||||
import data.Mangas
 | 
			
		||||
import tachiyomi.source.model.MangaInfo
 | 
			
		||||
import java.io.Serializable
 | 
			
		||||
 | 
			
		||||
interface SManga : Serializable {
 | 
			
		||||
@@ -85,6 +84,18 @@ interface SManga : Serializable {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fun copy() = create().also {
 | 
			
		||||
        it.url = url
 | 
			
		||||
        it.title = title
 | 
			
		||||
        it.artist = artist
 | 
			
		||||
        it.author = author
 | 
			
		||||
        it.description = description
 | 
			
		||||
        it.genre = genre
 | 
			
		||||
        it.status = status
 | 
			
		||||
        it.thumbnail_url = thumbnail_url
 | 
			
		||||
        it.initialized = initialized
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    companion object {
 | 
			
		||||
        const val UNKNOWN = 0
 | 
			
		||||
        const val ONGOING = 1
 | 
			
		||||
@@ -99,30 +110,3 @@ interface SManga : Serializable {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fun SManga.toMangaInfo(): MangaInfo {
 | 
			
		||||
    return MangaInfo(
 | 
			
		||||
        key = this.url,
 | 
			
		||||
        title = this.title,
 | 
			
		||||
        artist = this.artist ?: "",
 | 
			
		||||
        author = this.author ?: "",
 | 
			
		||||
        description = this.description ?: "",
 | 
			
		||||
        genres = this.getGenres() ?: emptyList(),
 | 
			
		||||
        status = this.status,
 | 
			
		||||
        cover = this.thumbnail_url ?: "",
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fun MangaInfo.toSManga(): SManga {
 | 
			
		||||
    val mangaInfo = this
 | 
			
		||||
    return SManga.create().apply {
 | 
			
		||||
        url = mangaInfo.key
 | 
			
		||||
        title = mangaInfo.title
 | 
			
		||||
        artist = mangaInfo.artist
 | 
			
		||||
        author = mangaInfo.author
 | 
			
		||||
        description = mangaInfo.description
 | 
			
		||||
        genre = mangaInfo.genres.joinToString(", ")
 | 
			
		||||
        status = mangaInfo.status
 | 
			
		||||
        thumbnail_url = mangaInfo.cover
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user