Add preference to toggle chapter URL hash for downloads (#1533)

This commit is contained in:
NGB-Was-Taken
2025-12-26 03:32:56 +05:45
committed by GitHub
parent ad5a76741a
commit 0ffc798e9a
4 changed files with 30 additions and 1 deletions
@@ -89,6 +89,7 @@ import tachiyomi.core.common.util.lang.withUIContext
import tachiyomi.core.common.util.system.ImageUtil
import tachiyomi.core.common.util.system.logcat
import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId
import tachiyomi.domain.download.service.DownloadPreferences
import tachiyomi.domain.library.service.LibraryPreferences
import tachiyomi.domain.manga.interactor.GetAllManga
import tachiyomi.domain.manga.interactor.ResetViewerFlags
@@ -117,6 +118,7 @@ object SettingsAdvancedScreen : SearchableSettings {
val basePreferences = remember { Injekt.get<BasePreferences>() }
val networkPreferences = remember { Injekt.get<NetworkPreferences>() }
val libraryPreferences = remember { Injekt.get<LibraryPreferences>() }
val downloadPreferences = remember { Injekt.get<DownloadPreferences>() }
return listOf(
Preference.PreferenceItem.TextPreference(
@@ -167,6 +169,7 @@ object SettingsAdvancedScreen : SearchableSettings {
getDataGroup(),
getNetworkGroup(networkPreferences = networkPreferences),
getLibraryGroup(libraryPreferences = libraryPreferences),
getDownloadsGroup(downloadPreferences = downloadPreferences),
getReaderGroup(basePreferences = basePreferences),
getExtensionsGroup(basePreferences = basePreferences),
// SY -->
@@ -378,6 +381,24 @@ object SettingsAdvancedScreen : SearchableSettings {
)
}
// SY ->
@Composable
private fun getDownloadsGroup(
downloadPreferences: DownloadPreferences,
): Preference.PreferenceGroup {
return Preference.PreferenceGroup(
title = stringResource(MR.strings.pref_category_downloads),
preferenceItems = persistentListOf(
Preference.PreferenceItem.SwitchPreference(
preference = downloadPreferences.includeChapterUrlHash(),
title = stringResource(SYMR.strings.pref_include_chapter_url_hash),
subtitle = stringResource(SYMR.strings.pref_include_chapter_url_hash_desc),
),
),
)
}
// <- SY
@Composable
private fun getReaderGroup(
basePreferences: BasePreferences,
@@ -10,6 +10,7 @@ import tachiyomi.core.common.i18n.stringResource
import tachiyomi.core.common.storage.displayablePath
import tachiyomi.core.common.util.system.logcat
import tachiyomi.domain.chapter.model.Chapter
import tachiyomi.domain.download.service.DownloadPreferences
import tachiyomi.domain.library.service.LibraryPreferences
import tachiyomi.domain.manga.model.Manga
import tachiyomi.domain.storage.service.StorageManager
@@ -28,6 +29,7 @@ class DownloadProvider(
private val context: Context,
private val storageManager: StorageManager = Injekt.get(),
private val libraryPreferences: LibraryPreferences = Injekt.get(),
private val downloadPreferences: DownloadPreferences = Injekt.get(),
) {
private val downloadsDir: UniFile?
@@ -190,6 +192,7 @@ class DownloadProvider(
chapterScanlator: String?,
chapterUrl: String,
disallowNonAsciiFilenames: Boolean = libraryPreferences.disallowNonAsciiFilenames().get(),
includeChapterUrlHash: Boolean = downloadPreferences.includeChapterUrlHash().get(),
): String {
var dirName = sanitizeChapterName(chapterName)
if (!chapterScanlator.isNullOrBlank()) {
@@ -197,7 +200,7 @@ class DownloadProvider(
}
// Subtract 7 bytes for hash and underscore, 4 bytes for .cbz
dirName = DiskUtil.buildValidFilename(dirName, DiskUtil.MAX_FILE_NAME_BYTES - 11, disallowNonAsciiFilenames)
dirName += "_" + md5(chapterUrl).take(6)
if (includeChapterUrlHash) dirName += "_" + md5(chapterUrl).take(6)
return dirName
}
@@ -233,6 +236,7 @@ class DownloadProvider(
chapterScanlator,
chapterUrl,
!libraryPreferences.disallowNonAsciiFilenames().get(),
!downloadPreferences.includeChapterUrlHash().get(),
)
return buildList(2) {
@@ -41,6 +41,8 @@ class DownloadPreferences(
fun parallelPageLimit() = preferenceStore.getInt("download_parallel_page_limit", 5)
fun includeChapterUrlHash() = preferenceStore.getBoolean("download_include_chapter_url_hash", true)
companion object {
private const val REMOVE_EXCLUDE_CATEGORIES_PREF_KEY = "remove_exclude_categories"
private const val DOWNLOAD_NEW_CATEGORIES_PREF_KEY = "download_new_categories"
@@ -153,6 +153,8 @@
<string name="bandwidth_data_saver_server">Bandwidth Hero Proxy Server</string>
<string name="data_saver_server_summary">Put Bandwidth Hero Proxy server url here</string>
<string name="clear_db_exclude_read">Keep entries with read chapters</string>
<string name="pref_include_chapter_url_hash">Include chapter URL hash</string>
<string name="pref_include_chapter_url_hash_desc">Append the first six characters of the chapter URL's MD5 hash to the chapter file folder name.</string>
<!-- Log Level -->
<string name="log_minimal">Minimal</string>