Minor improvements to the MangaDex code (#17573)

* Some minor improvements to the MangaDex code.

* Change capitalization of some other tags.
This commit is contained in:
Alessandro Jean 2023-08-19 11:56:14 -03:00 committed by GitHub
parent 3785fe1c02
commit 9579b5f145
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 64 additions and 57 deletions

View File

@ -12,3 +12,8 @@ ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true
ij_kotlin_name_count_to_use_star_import = 2147483647
ij_kotlin_name_count_to_use_star_import_for_members = 2147483647
[*.properties]
charset = utf-8
end_of_line = lf
insert_final_newline = true

View File

@ -26,15 +26,15 @@ filter_original_languages_summary=Only show content that was originally publishe
format=Format
format_adaptation=Adaptation
format_anthology=Anthology
format_award_winning=Award winning
format_award_winning=Award Winning
format_doujinshi=Doujinshi
format_fan_colored=Fan colored
format_full_color=Full color
format_long_strip=Long strip
format_official_colored=Official colored
format_fan_colored=Fan Colored
format_full_color=Full Color
format_long_strip=Long Strip
format_official_colored=Official Colored
format_oneshot=Oneshot
format_user_created=User created
format_web_comic=Web comic
format_user_created=User Created
format_web_comic=Web Comic
format_yonkoma=4-Koma
genre=Genre
genre_action=Action
@ -48,14 +48,14 @@ genre_girls_love=Girl's Love
genre_historical=Historical
genre_horror=Horror
genre_isekai=Isekai
genre_magical_girls=Magical girls
genre_magical_girls=Magical Girls
genre_mecha=Mecha
genre_medical=Medical
genre_mystery=Mystery
genre_philosophical=Philosophical
genre_romance=Romance
genre_sci_fi=Sci-Fi
genre_slice_of_life=Slice of life
genre_slice_of_life=Slice of Life
genre_sports=Sports
genre_superhero=Superhero
genre_thriller=Thriller
@ -116,31 +116,31 @@ theme_incest=Incest
theme_loli=Loli
theme_mafia=Mafia
theme_magic=Magic
theme_martial_arts=Martial arts
theme_martial_arts=Martial Arts
theme_military=Military
theme_monster_girls=Monster girls
theme_monster_girls=Monster Girls
theme_monsters=Monsters
theme_music=Music
theme_ninja=Ninja
theme_office_workers=Office workers
theme_office_workers=Office Workers
theme_police=Police
theme_post_apocalyptic=Post-apocalyptic
theme_post_apocalyptic=Post-Apocalyptic
theme_psychological=Psychological
theme_reincarnation=Reincarnation
theme_reverse_harem=Reverse harem
theme_reverse_harem=Reverse Harem
theme_samurai=Samurai
theme_school_life=School life
theme_school_life=School Life
theme_shota=Shota
theme_supernatural=Supernatural
theme_survival=Survival
theme_time_travel=Time travel
theme_traditional_games=Traditional games
theme_time_travel=Time Travel
theme_traditional_games=Traditional Games
theme_vampires=Vampires
theme_video_games=Video games
theme_video_games=Video Games
theme_villainess=Vilania
theme_virtual_reality=Virtual reality
theme_virtual_reality=Virtual Reality
theme_zombies=Zombies
try_using_first_volume_cover=Attempt to use the first volume cover as cover
try_using_first_volume_cover_summary=May need to manually refresh entries already in library. Otherwise, clear database to have new covers to show up.
unable_to_process_chapter_request=Unable to process Chapter request. HTTP code: %d
uploaded_by=Uploaded by %s
uploaded_by=Uploaded by %s

View File

@ -6,7 +6,7 @@ ext {
extName = 'MangaDex'
pkgNameSuffix = 'all.mangadex'
extClass = '.MangaDexFactory'
extVersionCode = 187
extVersionCode = 188
isNsfw = true
}

View File

@ -96,10 +96,11 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
val firstVolumeCovers = fetchFirstVolumeCovers(mangaListDto.data).orEmpty()
val mangaList = mangaListDto.data.map { mangaDataDto ->
val fileName = firstVolumeCovers[mangaDataDto.id] ?: mangaDataDto.relationships
.filterIsInstance<CoverArtDto>()
.firstOrNull()
?.attributes?.fileName
val fileName = firstVolumeCovers.getOrElse(mangaDataDto.id) {
mangaDataDto.relationships
.firstInstanceOrNull<CoverArtDto>()
?.attributes?.fileName
}
helper.createBasicManga(mangaDataDto, fileName, coverSuffix, dexLang)
}
@ -159,10 +160,11 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
val coverSuffix = preferences.coverQuality
val mangaList = mangaIds.mapNotNull { mangaDtoMap[it] }.map { mangaDataDto ->
val fileName = firstVolumeCovers[mangaDataDto.id] ?: mangaDataDto.relationships
.filterIsInstance<CoverArtDto>()
.firstOrNull()
?.attributes?.fileName
val fileName = firstVolumeCovers.getOrElse(mangaDataDto.id) {
mangaDataDto.relationships
.firstInstanceOrNull<CoverArtDto>()
?.attributes?.fileName
}
helper.createBasicManga(mangaDataDto, fileName, coverSuffix, dexLang)
}
@ -217,8 +219,7 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
}
response.parseAs<ChapterDto>().data!!.relationships
.filterIsInstance<MangaDataDto>()
.firstOrNull()!!.id
.firstInstanceOrNull<MangaDataDto>()!!.id
}
}
@ -342,10 +343,11 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
val coverSuffix = preferences.coverQuality
val mangaList = mangaListDto.data.map { mangaDataDto ->
val fileName = firstVolumeCovers[mangaDataDto.id] ?: mangaDataDto.relationships
.filterIsInstance<CoverArtDto>()
.firstOrNull()
?.attributes?.fileName
val fileName = firstVolumeCovers.getOrElse(mangaDataDto.id) {
mangaDataDto.relationships
.firstInstanceOrNull<CoverArtDto>()
?.attributes?.fileName
}
helper.createBasicManga(mangaDataDto, fileName, coverSuffix, dexLang)
}
@ -448,9 +450,9 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
return null
}
val mangaMap = mangaList.associate { it.id to it.attributes!! }
.filterValues { !it.originalLanguage.isNullOrEmpty() }
val locales = mangaList.mapNotNull { it.attributes!!.originalLanguage }.distinct()
val safeMangaList = mangaList.filterNot { it.attributes?.originalLanguage.isNullOrEmpty() }
val mangaMap = safeMangaList.associate { it.id to it.attributes!! }
val locales = safeMangaList.mapNotNull { it.attributes!!.originalLanguage }.distinct()
val limit = (mangaMap.size * locales.size).coerceAtMost(100)
val apiUrl = "${MDConstants.apiUrl}/cover".toHttpUrl().newBuilder()
@ -468,10 +470,7 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
val covers = result.getOrNull() ?: return null
return covers
.groupBy {
it.relationships.filterIsInstance<MangaDataDto>()
.firstOrNull()!!.id
}
.groupBy { it.relationships.firstInstanceOrNull<MangaDataDto>()!!.id }
.mapValues {
it.value.find { c -> c.attributes?.locale == mangaMap[it.key]?.originalLanguage }
}
@ -512,7 +511,7 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
return emptyList()
}
var chapterListResponse = response.parseAs<ChapterListDto>()
val chapterListResponse = response.parseAs<ChapterListDto>()
val chapterListResults = chapterListResponse.data.toMutableList()
@ -768,6 +767,9 @@ abstract class MangaDex(final override val lang: String, private val dexLang: St
helper.json.decodeFromString(body.string())
}
private inline fun <reified T> List<*>.firstInstanceOrNull(): T? =
firstOrNull { it is T } as? T?
private val SharedPreferences.contentRating
get() = getStringSet(
MDConstants.getContentRatingPrefKey(dexLang),

View File

@ -48,7 +48,6 @@ class MangaDexFactory : SourceFactory {
MangaDexRomanian(),
MangaDexRussian(),
MangaDexSerbian(),
MangaDexSerboCroatian(),
MangaDexSlovak(),
MangaDexSpanishLatinAmerica(),
MangaDexSpanishSpain(),
@ -105,7 +104,6 @@ class MangaDexPortuguesePortugal : MangaDex("pt")
class MangaDexRomanian : MangaDex("ro")
class MangaDexRussian : MangaDex("ru")
class MangaDexSerbian : MangaDex("sr")
class MangaDexSerboCroatian : MangaDex("sh")
class MangaDexSlovak : MangaDex("sk")
class MangaDexSpanishLatinAmerica : MangaDex("es-419", "es-la")
class MangaDexSpanishSpain : MangaDex("es")

View File

@ -359,18 +359,18 @@ class MangaDexHelper(lang: String) {
if (altTitles.isNotEmpty()) {
val altTitlesDesc = altTitles
.joinToString("\n", "${intl["alternative_titles"]}\n") { "$it" }
desc += (if (desc.isNullOrBlank()) "" else "\n\n") + altTitlesDesc.removeEntitiesAndMarkdown()
desc += (if (desc.isBlank()) "" else "\n\n") + altTitlesDesc.removeEntitiesAndMarkdown()
}
}
return createBasicManga(mangaDataDto, coverFileName, coverSuffix, lang).apply {
description = desc
author = authors.joinToString(", ")
artist = artists.joinToString(", ")
author = authors.joinToString()
artist = artists.joinToString()
status = getPublicationStatus(attr, chapters)
genre = genreList
.filter(String::isNotEmpty)
.joinToString(", ")
.joinToString()
}
}

View File

@ -57,15 +57,17 @@ class MdAtHomeReportInterceptor(
// gets stuck, as it tend to happens sometimes.
client.newCall(reportRequest).enqueue(REPORT_CALLBACK)
return if (!response.isSuccessful) {
Log.e("MangaDex", "Error connecting to MD@Home node, fallback to uploads server")
val fallbackUrl = MDConstants.cdnUrl.toHttpUrl().newBuilder()
.addPathSegments(originalRequest.url.pathSegments.joinToString("/"))
.build()
client.newCall(GET(fallbackUrl, headers)).execute()
} else {
response
if (response.isSuccessful) {
return response
}
Log.e("MangaDex", "Error connecting to MD@Home node, fallback to uploads server")
val fallbackUrl = MDConstants.cdnUrl.toHttpUrl().newBuilder()
.addPathSegments(originalRequest.url.pathSegments.joinToString("/"))
.build()
return client.newCall(GET(fallbackUrl, headers)).execute()
}
companion object {