Skip to content

Commit

Permalink
Merge pull request #524 from Shikkanime/dev
Browse files Browse the repository at this point in the history
Add old id detection on DisneyPlusPlatform.kt
  • Loading branch information
Ziedelth authored Jun 23, 2024
2 parents 2adeebc + ee81298 commit 37149fe
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
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

0 comments on commit 37149fe

Please sign in to comment.