diff --git a/src/main/kotlin/fr/shikkanime/platforms/AnimationDigitalNetworkPlatform.kt b/src/main/kotlin/fr/shikkanime/platforms/AnimationDigitalNetworkPlatform.kt index 7b77c634..a63bb18a 100644 --- a/src/main/kotlin/fr/shikkanime/platforms/AnimationDigitalNetworkPlatform.kt +++ b/src/main/kotlin/fr/shikkanime/platforms/AnimationDigitalNetworkPlatform.kt @@ -15,6 +15,7 @@ import fr.shikkanime.utils.ObjectParser.getAsBoolean import fr.shikkanime.utils.ObjectParser.getAsInt import fr.shikkanime.utils.ObjectParser.getAsLong import fr.shikkanime.utils.ObjectParser.getAsString +import fr.shikkanime.utils.StringUtils import fr.shikkanime.wrappers.AnimationDigitalNetworkWrapper import java.io.File import java.time.ZonedDateTime @@ -71,7 +72,7 @@ class AnimationDigitalNetworkPlatform : if ((genres.isEmpty || !genres.any { it.asString.startsWith("Animation ", true) }) && !contains) throw Exception("Anime is not an animation") var isSimulcasted = show.getAsBoolean("simulcast") == true || - show.getAsString("firstReleaseYear")!! in (0..1).map { (zonedDateTime.year - it).toString() } || + show.getAsString("firstReleaseYear") in (0..1).map { (zonedDateTime.year - it).toString() } || contains val descriptionLowercase = animeDescription.lowercase() @@ -124,6 +125,7 @@ class AnimationDigitalNetworkPlatform : image = animeImage, banner = animeBanner, description = animeDescription, + slug = StringUtils.toSlug(StringUtils.getShortName(animeName)), ), episodeType = episodeType, langType = langType, diff --git a/src/main/kotlin/fr/shikkanime/platforms/CrunchyrollPlatform.kt b/src/main/kotlin/fr/shikkanime/platforms/CrunchyrollPlatform.kt index 92da15e2..dbcc9c06 100644 --- a/src/main/kotlin/fr/shikkanime/platforms/CrunchyrollPlatform.kt +++ b/src/main/kotlin/fr/shikkanime/platforms/CrunchyrollPlatform.kt @@ -15,6 +15,7 @@ import fr.shikkanime.utils.ObjectParser import fr.shikkanime.utils.ObjectParser.getAsInt import fr.shikkanime.utils.ObjectParser.getAsLong import fr.shikkanime.utils.ObjectParser.getAsString +import fr.shikkanime.utils.StringUtils import fr.shikkanime.wrappers.CrunchyrollWrapper import io.ktor.client.statement.* import io.ktor.http.* @@ -269,7 +270,7 @@ class CrunchyrollPlatform : AbstractPlatform() + val configService = Constant.injector.getInstance(ConfigService::class.java) + configService.findByName(ConfigPropertyKey.USE_CRUNCHYROLL_API.key)?.let { + configService.delete(it) + } + + configService.save(Config(propertyKey = ConfigPropertyKey.USE_CRUNCHYROLL_API.key, propertyValue = "true")) val episodeService = Constant.injector.getInstance(EpisodeService::class.java) val adnPlatform = Constant.injector.getInstance(AnimationDigitalNetworkPlatform::class.java) + val crunchyrollPlatform = Constant.injector.getInstance(CrunchyrollPlatform::class.java) + +// dates.forEach { date -> +// runBlocking { adnPlatform.fetchApiContent(CountryCode.FR, date) }.forEach { episodeJson -> +// try { +// episodes.addAll(adnPlatform.convertEpisode( +// CountryCode.FR, +// episodeJson.asJsonObject, +// date +// )) +// } catch (e: Exception) { +// e.printStackTrace() +// } +// } +// } + + val minDate = dates.minOrNull()!! + val maxDate = dates.maxOrNull()!! + val accessToken = runBlocking { CrunchyrollWrapper.getAnonymousAccessToken() } + var page = 1 + val fetch = 1000 + + val series = simulcasts.flatMap { simulcastId -> + runBlocking { + CrunchyrollWrapper.getBrowse( + CountryCode.FR.locale, + accessToken, + sortBy = CrunchyrollWrapper.SortType.POPULARITY, + type = CrunchyrollWrapper.MediaType.SERIES, + 100, + simulcast = simulcastId + ) + } + }.map { jsonObject -> jsonObject.getAsString("title")!!.lowercase() }.toSet() + println("Simulcasts: $series") + + crunchyrollPlatform.simulcasts[CountryCode.FR] = series - dates.forEach { date -> - runBlocking { adnPlatform.fetchApiContent(CountryCode.FR, date) }.forEach { episodeJson -> + while (true) { + val fetchApi = runBlocking { CrunchyrollWrapper.getBrowse(CountryCode.FR.locale, accessToken, size = fetch, start = (page - 1) * fetch) }.toMutableList() + + val episodeDates = fetchApi + .map { episodeJson -> + val episodeMetadata = episodeJson.getAsJsonObject("episode_metadata") + episodeJson to requireNotNull(episodeMetadata.getAsString("premium_available_date")?.let { ZonedDateTime.parse(it) }) { "Release date is null" } + }.toMutableList() + + val lastDate = episodeDates.maxByOrNull { it.second }!!.second + val firstDate = episodeDates.minByOrNull { it.second }!!.second + episodeDates.removeIf { it.second !in minDate..maxDate } + + episodeDates.forEach { (episodeJson, _) -> try { - adnPlatform.convertEpisode( + episodes.add(crunchyrollPlatform.convertJsonEpisode( CountryCode.FR, - episodeJson.asJsonObject, - date - ).forEach { - episodeService.save(it) - } - } catch (e: Exception) { - e.printStackTrace() + episodeJson + )) + } catch (_: Exception) { + } } + + if (lastDate.isBefore(minDate) || firstDate.isAfter(maxDate)) { + break + } + + page++ } httpRequest.close() + episodes.forEach { episode -> + episodeService.save(episode) + } + println("Take ${(System.currentTimeMillis() - start) / 1000}s to check ${dates.size} dates") } \ No newline at end of file