From 262f8449b4369fde42cbd15d2a768e54461e84af Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 12 Nov 2022 09:54:24 -0500 Subject: [PATCH] Resolve proper chapter URL for ComicInfo "Web" field Requires extensions to be updated to lib 1.4 to have proper URLs for some of them, which will happen soon in the future. --- .../eu/kanade/domain/manga/model/ComicInfo.kt | 4 ++-- .../tachiyomi/data/download/Downloader.kt | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/kanade/domain/manga/model/ComicInfo.kt b/app/src/main/java/eu/kanade/domain/manga/model/ComicInfo.kt index 4f039b1368..163d9a3efe 100644 --- a/app/src/main/java/eu/kanade/domain/manga/model/ComicInfo.kt +++ b/app/src/main/java/eu/kanade/domain/manga/model/ComicInfo.kt @@ -12,11 +12,11 @@ const val COMIC_INFO_FILE = "ComicInfo.xml" /** * Creates a ComicInfo instance based on the manga and chapter metadata. */ -fun getComicInfo(manga: Manga, chapter: Chapter): ComicInfo { +fun getComicInfo(manga: Manga, chapter: Chapter, chapterUrl: String): ComicInfo { return ComicInfo( title = ComicInfo.Title(chapter.name), series = ComicInfo.Series(manga.title), - web = ComicInfo.Web(manga.url), + web = ComicInfo.Web(chapterUrl), summary = manga.description?.let { ComicInfo.Summary(it) }, writer = manga.author?.let { ComicInfo.Writer(it) }, penciller = manga.artist?.let { ComicInfo.Penciller(it) }, diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt index 9fc1046ef3..cbaaf52739 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/Downloader.kt @@ -537,7 +537,14 @@ class Downloader( cache.addChapter(dirname, mangaDir, download.manga) DiskUtil.createNoMediaFile(tmpDir, context) - createComicInfoFile(mangaDir, download.manga, download.chapter.toDomainChapter()!!) + + val chapterUrl = download.source.getChapterUrl(download.chapter) + createComicInfoFile( + mangaDir, + download.manga, + download.chapter.toDomainChapter()!!, + chapterUrl, + ) Download.State.DOWNLOADED } else { @@ -583,19 +590,21 @@ class Downloader( * Creates a ComicInfo.xml file inside the given directory. * * @param dir the directory in which the ComicInfo file will be generated. - * @param manga the manga of the chapter to download. - * @param chapter the chapter to download + * @param manga the manga. + * @param chapter the chapter. + * @param chapterUrl the resolved URL for the chapter. */ private fun createComicInfoFile( dir: UniFile, manga: Manga, chapter: Chapter, + chapterUrl: String, ) { File("${dir.filePath}/$COMIC_INFO_FILE").outputStream().also { // Force overwrite old file (it as? FileOutputStream)?.channel?.truncate(0) }.use { - val comicInfo = getComicInfo(manga, chapter) + val comicInfo = getComicInfo(manga, chapter, chapterUrl) it.write(xml.encodeToString(ComicInfo.serializer(), comicInfo).toByteArray()) } }