package net.pterodactylus.rhynodge.filters.webpages.savoy import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.ObjectMapper import org.jsoup.nodes.Document import java.time.LocalDateTime import java.time.format.DateTimeFormatter class MovieExtractor { fun getMovies(document: Document) = document.select("body script#flebbe-state") .dataNodes().joinToString("").unescape() .let(objectMapper::readTree) .get("G./api/v1/en/config?").get("body").asText() .let(objectMapper::readTree) .get("movie_list") .map { it.extractMovie() } .toSet() private fun String.unescape() = this .replace("&q;", "\"") .replace("&a;", "&") .replace("&s;", "'") .replace("&l;", "<") .replace("&g;", ">") private fun JsonNode.extractMovie() = this@extractMovie.get("performances") .map { performance -> val begin = LocalDateTime.parse(performance.get("begin").asText(), dateFormat) val slug = performance.get("slug").asText() val link = "https://savoy.premiumkino.de/vorstellung/${slug}/${String.format("%tY%