diff --git a/src/main/java/de/mediathekview/mserver/crawler/orfon/json/OrfOnEpisodeDeserializer.java b/src/main/java/de/mediathekview/mserver/crawler/orfon/json/OrfOnEpisodeDeserializer.java index a4eaad5fc..f2a89c985 100644 --- a/src/main/java/de/mediathekview/mserver/crawler/orfon/json/OrfOnEpisodeDeserializer.java +++ b/src/main/java/de/mediathekview/mserver/crawler/orfon/json/OrfOnEpisodeDeserializer.java @@ -49,6 +49,9 @@ public class OrfOnEpisodeDeserializer implements JsonDeserializer> parseUrl(JsonElement jsonElement) { if (videoPath1.isEmpty() || !videoPath1.get().isJsonArray() || videoPath1.get().getAsJsonArray().size() == 0) { return Optional.empty(); } + // We need to fallback to episode.sources in case there are many elements in the playlist + if (videoPath1.get().getAsJsonArray().size() > 1) { + return parseFallbackVideo(jsonElement); + } + Optional videoPath2 = JsonUtils.getElement(videoPath1.get().getAsJsonArray().get(0), TAG_VIDEO_PATH_2); if (videoPath2.isEmpty() || !videoPath2.get().isJsonArray()) { return Optional.empty(); @@ -168,13 +176,37 @@ private Optional> parseUrl(JsonElement jsonElement) { return Optional.empty(); } + private Optional> parseFallbackVideo(JsonElement root) { + Optional videoSources = JsonUtils.getElement(root, TAG_VIDEO_FALLBACK); + if (videoSources.isPresent()) { + Map urls = new EnumMap<>(Resolution.class); + for (String key : PREFERED_CODEC) { + Optional codecs = JsonUtils.getElement(videoSources.get(), key); + if (codecs.isPresent() && codecs.get().isJsonArray()) { + for (JsonElement singleVideo : codecs.get().getAsJsonArray()) { + Optional tgtUrl = JsonUtils.getElementValueAsString(singleVideo, TAG_VIDEO_FALLBACK_URL); + if (tgtUrl.isPresent()) { + try { + urls.put(Resolution.NORMAL, new FilmUrl(tgtUrl.get(), 0L)); + } catch (MalformedURLException e) { + LOG.warn("invalid video url {} error {}", tgtUrl, e ); + } + return Optional.of(urls); + } + } + } + } + } + return Optional.empty(); + } + private Optional> readVideoForTargetCodec(JsonElement urlArray, String targetCodec) { Map urls = new EnumMap<>(Resolution.class); for (JsonElement videoElement : urlArray.getAsJsonArray()) { Optional codec = JsonUtils.getElementValueAsString(videoElement, TAG_VIDEO_CODEC); Optional quality = JsonUtils.getElementValueAsString(videoElement, TAG_VIDEO_QUALITY); Optional url = JsonUtils.getElementValueAsString(videoElement, TAG_VIDEO_URL); - if (url.isPresent() && codec.isPresent() && quality.isPresent() && targetCodec.equalsIgnoreCase(codec.get())) { + if (url.isPresent() && codec.isPresent() && quality.isPresent() && targetCodec.equalsIgnoreCase(codec.get()) && OrfOnEpisodeDeserializer.getQuality(quality.get()).isPresent()) { try { long fileSize = crawler.determineFileSizeInKB(url.get()); urls.put( @@ -221,6 +253,7 @@ private Optional> parseGeoLocations(Optional te } return Optional.empty(); } + private Optional parseAiredDate(Optional text) { Optional result = Optional.empty(); if (text.isPresent()) { @@ -264,7 +297,7 @@ private static Optional getQuality(final String aQuality) { case "QXB": case "QXBDRM": case "Q8A": - return Optional.of(Resolution.NORMAL); + return Optional.empty(); default: LOG.debug("ORF: unknown quality: {}", aQuality); } diff --git a/src/test/java/de/mediathekview/mserver/crawler/orfon/OrfOnEpisodeTaskTest.java b/src/test/java/de/mediathekview/mserver/crawler/orfon/OrfOnEpisodeTaskTest.java index d1ab15396..e1f931dbf 100644 --- a/src/test/java/de/mediathekview/mserver/crawler/orfon/OrfOnEpisodeTaskTest.java +++ b/src/test/java/de/mediathekview/mserver/crawler/orfon/OrfOnEpisodeTaskTest.java @@ -1,5 +1,6 @@ package de.mediathekview.mserver.crawler.orfon; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -55,7 +56,7 @@ public void testNormal_1() { ).containsAll(actual.getSubtitles())); assertEquals(Map.of( Resolution.HD, new FilmUrl("https://apasfiis.sf.apa.at/ipad/cms-worldwide/2024-01-04_0707_tl_01_Servus-Kasperl-_____14207792__o__6332192865__s15543049_9__ORF1HD_07081012P_07300711P_Q8C.mp4/playlist.m3u8", 0L), - Resolution.NORMAL, new FilmUrl("https://apasfiis.sf.apa.at/ipad/cms-worldwide/2024-01-04_0707_tl_01_Servus-Kasperl-_____14207792__o__6332192865__s15543049_9__ORF1HD_07081012P_07300711P_QXB.mp4/playlist.m3u8", 0L), + Resolution.NORMAL, new FilmUrl("https://apasfiis.sf.apa.at/ipad/cms-worldwide/2024-01-04_0707_tl_01_Servus-Kasperl-_____14207792__o__6332192865__s15543049_9__ORF1HD_07081012P_07300711P_Q6A.mp4/playlist.m3u8", 0L), Resolution.SMALL, new FilmUrl("https://apasfiis.sf.apa.at/ipad/cms-worldwide/2024-01-04_0707_tl_01_Servus-Kasperl-_____14207792__o__6332192865__s15543049_9__ORF1HD_07081012P_07300711P_Q4A.mp4/playlist.m3u8", 0L), Resolution.VERY_SMALL, new FilmUrl("https://apasfiis.sf.apa.at/ipad/cms-worldwide/2024-01-04_0707_tl_01_Servus-Kasperl-_____14207792__o__6332192865__s15543049_9__ORF1HD_07081012P_07300711P_Q1A.3gp/playlist.m3u8", 0L) ), actual.getUrls()); @@ -88,7 +89,7 @@ public void testNormal_2() { ).containsAll(actual.getSubtitles())); assertEquals(Map.of( Resolution.HD, new FilmUrl("https://apasfiis.sf.apa.at/ipad/cms-austria/2024-01-04_0645_tl_00_ABC-Baer_____14207790__o__4346842346__s15542921_1__KIDS1_06363007P_06500003P_Q8C.mp4/playlist.m3u8", 0L), - Resolution.NORMAL, new FilmUrl("https://apasfiis.sf.apa.at/ipad/cms-austria/2024-01-04_0645_tl_00_ABC-Baer_____14207790__o__4346842346__s15542921_1__KIDS1_06363007P_06500003P_QXB.mp4/playlist.m3u8", 0L), + Resolution.NORMAL, new FilmUrl("https://apasfiis.sf.apa.at/ipad/cms-austria/2024-01-04_0645_tl_00_ABC-Baer_____14207790__o__4346842346__s15542921_1__KIDS1_06363007P_06500003P_Q6A.mp4/playlist.m3u8", 0L), Resolution.SMALL, new FilmUrl("https://apasfiis.sf.apa.at/ipad/cms-austria/2024-01-04_0645_tl_00_ABC-Baer_____14207790__o__4346842346__s15542921_1__KIDS1_06363007P_06500003P_Q4A.mp4/playlist.m3u8", 0L), Resolution.VERY_SMALL, new FilmUrl("https://apasfiis.sf.apa.at/ipad/cms-austria/2024-01-04_0645_tl_00_ABC-Baer_____14207790__o__4346842346__s15542921_1__KIDS1_06363007P_06500003P_Q1A.3gp/playlist.m3u8", 0L) ), actual.getUrls()); @@ -122,7 +123,7 @@ public void testAD() { // [, , , , ] assertEquals(Map.of( Resolution.HD, new FilmUrl("https://apasfiis.sf.apa.at/ipad/cms-austria/2023-12-06_2307_sd_01_AD---Vorstadtwe_____14204417__o__8792736916__s15524266_6__ORF1ADHD_23092909P_23560117P_Q8C.mp4/playlist.m3u8", 0L), - Resolution.NORMAL, new FilmUrl("https://apasfiis.sf.apa.at/ipad/cms-austria/2023-12-06_2307_sd_01_AD---Vorstadtwe_____14204417__o__8792736916__s15524266_6__ORF1ADHD_23092909P_23560117P_QXB.mp4/playlist.m3u8", 0L), + Resolution.NORMAL, new FilmUrl("https://apasfiis.sf.apa.at/ipad/cms-austria/2023-12-06_2307_sd_01_AD---Vorstadtwe_____14204417__o__8792736916__s15524266_6__ORF1ADHD_23092909P_23560117P_Q6A.mp4/playlist.m3u8", 0L), Resolution.SMALL, new FilmUrl("https://apasfiis.sf.apa.at/ipad/cms-austria/2023-12-06_2307_sd_01_AD---Vorstadtwe_____14204417__o__8792736916__s15524266_6__ORF1ADHD_23092909P_23560117P_Q4A.mp4/playlist.m3u8", 0L), Resolution.VERY_SMALL, new FilmUrl("https://apasfiis.sf.apa.at/ipad/cms-austria/2023-12-06_2307_sd_01_AD---Vorstadtwe_____14204417__o__8792736916__s15524266_6__ORF1ADHD_23092909P_23560117P_Q1A.3gp/playlist.m3u8", 0L) ), actual.getUrls()); @@ -156,7 +157,7 @@ public void testArchive() { ).containsAll(actual.getSubtitles())); assertEquals(Map.of( Resolution.HD, new FilmUrl("https://apasfiis.sf.apa.at/ipad/cms-worldwide/2020-03-26_1310_sd_02_ORF-Mitarbeiter_____14046198__o__8302694905__s14668903_3__ORF3HD_13420114P_13453123P_Q8C.mp4/playlist.m3u8", 0L), - Resolution.NORMAL, new FilmUrl("https://apasfiis.sf.apa.at/ipad/cms-worldwide/2020-03-26_1310_sd_02_ORF-Mitarbeiter_____14046198__o__8302694905__s14668903_3__ORF3HD_13420114P_13453123P_QXB.mp4/playlist.m3u8", 0L), + Resolution.NORMAL, new FilmUrl("https://apasfiis.sf.apa.at/ipad/cms-worldwide/2020-03-26_1310_sd_02_ORF-Mitarbeiter_____14046198__o__8302694905__s14668903_3__ORF3HD_13420114P_13453123P_Q6A.mp4/playlist.m3u8", 0L), Resolution.SMALL, new FilmUrl("https://apasfiis.sf.apa.at/ipad/cms-worldwide/2020-03-26_1310_sd_02_ORF-Mitarbeiter_____14046198__o__8302694905__s14668903_3__ORF3HD_13420114P_13453123P_Q4A.mp4/playlist.m3u8", 0L), Resolution.VERY_SMALL, new FilmUrl("https://apasfiis.sf.apa.at/ipad/cms-worldwide/2020-03-26_1310_sd_02_ORF-Mitarbeiter_____14046198__o__8302694905__s14668903_3__ORF3HD_13420114P_13453123P_Q1A.3gp/playlist.m3u8", 0L) ), actual.getUrls());