From 1075afc21283fc86b0cf31553a2e783354176094 Mon Sep 17 00:00:00 2001 From: CodingPF Date: Wed, 8 May 2024 20:15:29 +0200 Subject: [PATCH] add parsevideofromthumbnail --- .../orfon/json/OrfOnEpisodeDeserializer.java | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/src/main/java/mServer/crawler/sender/orfon/json/OrfOnEpisodeDeserializer.java b/src/main/java/mServer/crawler/sender/orfon/json/OrfOnEpisodeDeserializer.java index 16ce043d9..b4358b1ca 100644 --- a/src/main/java/mServer/crawler/sender/orfon/json/OrfOnEpisodeDeserializer.java +++ b/src/main/java/mServer/crawler/sender/orfon/json/OrfOnEpisodeDeserializer.java @@ -45,6 +45,7 @@ public class OrfOnEpisodeDeserializer implements JsonDeserializer parseSubtitleUrls(JsonElement element) { return JsonUtils.getElementValueAsString(element, TAG_SUBTITLE_TTML); } - private Optional> parseUrl(JsonElement jsonElement) { + private Optional> parseVideoFromSegmentPlaylist(JsonElement jsonElement) { Optional videoPath1 = JsonUtils.getElement(jsonElement, TAG_VIDEO_PATH_1); if (videoPath1.isEmpty() || !videoPath1.get().isJsonArray() || videoPath1.get().getAsJsonArray().size() == 0) { return Optional.empty(); @@ -157,10 +158,10 @@ private Optional> parseUrl(JsonElement jsonElement) { } } } - return parseFallbackVideo(jsonElement); + return parseVideoFromSources(jsonElement); } - private Optional> parseFallbackVideo(JsonElement root) { + private Optional> parseVideoFromSources(JsonElement root) { Optional videoSources = JsonUtils.getElement(root, TAG_VIDEO_FALLBACK); if (videoSources.isPresent()) { Map urls = new EnumMap<>(Qualities.class); @@ -177,7 +178,31 @@ private Optional> parseFallbackVideo(JsonElement root) { } } } - return Optional.empty(); + return parseVideoFromThumbnail(root); + } + + private Optional> parseVideoFromThumbnail(JsonElement root) { + Map urls = new EnumMap<>(Qualities.class); + try { + Optional id = JsonUtils.getElement(root, TAG_ID); + Optional thumbnailSources = JsonUtils.getElement(root, VIDEO_THUMBNAIL); + if (id.isPresent() && thumbnailSources.isPresent() && thumbnailSources.get().isJsonArray() && thumbnailSources.get().getAsJsonArray().size() > 0 ) { + Optional thumbnailSrc = JsonUtils.getElement(thumbnailSources.get().getAsJsonArray().get(0), "src"); + if (thumbnailSrc.isPresent()) { + int indexId = thumbnailSrc.get().getAsString().indexOf(id.get().getAsString()); + String fromSecondIdOnwards = thumbnailSrc.get().getAsString().substring(indexId + id.get().getAsString().length() + 1); + String secondId = fromSecondIdOnwards.substring(0, fromSecondIdOnwards.indexOf("_")); + String url = String.format("https://apasfiis.sf.apa.at/ipad/cms-worldwide_episodes/%s_%s_QXA.mp4/playlist.m3u8", id.get().getAsString(), secondId); + urls.put(Qualities.NORMAL, url); + } + } + } catch (Exception e) { + LOG.error("generateFallbackVideo {}", e); + } + if (urls.size() == 0) { + return Optional.empty(); + } + return Optional.of(urls); } private Optional> readVideoForTargetCodec(JsonElement urlArray, String targetCodec) {