Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add old id detection on DisneyPlusPlatform.kt #524

Merged
merged 1 commit into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/main/kotlin/fr/shikkanime/jobs/FetchEpisodesJob.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,17 @@ class FetchEpisodesJob : AbstractJob {

if (!isInitialized) {
val variants = episodeVariantService.findAllTypeIdentifier()
identifiers.addAll(variants.map { it[7] as String }.toSet())
val elements = variants.map { it[7] as String }.toSet()
identifiers.addAll(elements)

Constant.abstractPlatforms.forEach {
it.hashCache.addAll(
variants.filter { variant -> (variant[2] as Platform) == it.getPlatform() }
.map { variant ->
".{2}-.{4}-(.*)-.{2}-.{2}".toRegex().find(variant[7] as String)!!.groupValues[1]
}
)
}

// COMPARE COUNTRY, ANIME, PLATFORM, EPISODE TYPE, SEASON, NUMBER, AND LANG TYPE
variants.forEach { typeIdentifiers.add(getTypeIdentifier(it)) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ abstract class AbstractPlatform<C : PlatformConfiguration<*>, K : Any, V> {
val logger = LoggerFactory.getLogger(javaClass)
var configuration: C? = null
private val apiCache = mutableMapOf<Pair<K, ZonedDateTime>, V>()
val hashCache = mutableSetOf<String>()

abstract fun getPlatform(): Platform
abstract fun getConfigurationClass(): Class<C>
Expand Down
8 changes: 8 additions & 0 deletions src/main/kotlin/fr/shikkanime/platforms/DisneyPlusPlatform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ class DisneyPlusPlatform :

val season = requireNotNull(visualsObject.getAsInt("seasonNumber")) { "Season is null" }
val number = visualsObject.getAsInt("episodeNumber") ?: -1
val oldId = jsonObject.getAsJsonArray("actions")[0].asJsonObject
.getAsJsonObject("legacyPartnerFeed").getAsString("dmcContentId") ?: throw Exception("Old id is null")
val id = jsonObject.getAsString("id") ?: throw Exception("Id is null")
val title = visualsObject.getAsString("episodeTitle")?.ifBlank { null }
val url = "https://www.disneyplus.com/${countryCode.locale.lowercase()}/play/$id"
Expand All @@ -130,6 +132,12 @@ class DisneyPlusPlatform :
zonedDateTime.withUTC().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + "T${simulcast.releaseTime}Z"
val releaseDateTime = ZonedDateTime.parse(releaseDateTimeUTC)

if (hashCache.contains(oldId) || hashCache.contains(id)) {
throw AnimeException("Episode already exists")
}

hashCache.addAll(mutableListOf(oldId, id))

return Episode(
countryCode = countryCode,
anime = animeName,
Expand Down