Minor improvements to the MangaDex code ()

* 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

@ -12,3 +12,8 @@ ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = 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 = 2147483647
ij_kotlin_name_count_to_use_star_import_for_members = 2147483647 ij_kotlin_name_count_to_use_star_import_for_members = 2147483647
[*.properties]
charset = utf-8
end_of_line = lf
insert_final_newline = true

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

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

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

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

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

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