Skip to content

Commit

Permalink
Merge pull request #983 from mediathekview/hotfix/981
Browse files Browse the repository at this point in the history
ORF add parsevideofromthumbnail
  • Loading branch information
codingPF authored May 11, 2024
2 parents 41af0de + 4d02c81 commit 3514aed
Showing 1 changed file with 36 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public class OrfOnEpisodeDeserializer implements JsonDeserializer<OrfOnVideoInfo
//
private AbstractCrawler crawler = null;
private static final String[] PREFERED_CODEC = {"hls", "hds", "progressive"};
private static final String[] VIDEO_THUMBNAIL = {"thumbnail_sources","hls"};
//

public OrfOnEpisodeDeserializer(AbstractCrawler crawler) {
this.crawler = crawler;
}
Expand All @@ -84,9 +84,8 @@ public OrfOnVideoInfoDTO deserialize(
parseWebsite(JsonUtils.getElementValueAsString(jsonElement, TAG_SHARE_BODY)),
parseGeoLocations(JsonUtils.getElementValueAsString(jsonElement, TAG_RIGHT)),
parseSubtitleSource(JsonUtils.getElementValueAsString(jsonElement, TAG_SUBTITLE)),
optimizeUrls(parseUrl(jsonElement)),
optimizeUrls(parseVideoFromSegmentPlaylist(jsonElement)),
buildOrResolveSubs(jsonElement)

);
return aFilm;
}
Expand Down Expand Up @@ -166,7 +165,7 @@ private Optional<URL> toURL(String aString) {
return Optional.empty();
}

private Optional<Map<Resolution, FilmUrl>> parseUrl(JsonElement jsonElement) {
private Optional<Map<Resolution, FilmUrl>> parseVideoFromSegmentPlaylist(JsonElement jsonElement) {
Optional<JsonElement> videoPath1 = JsonUtils.getElement(jsonElement, TAG_VIDEO_PATH_1);
if (videoPath1.isEmpty() || !videoPath1.get().isJsonArray() || videoPath1.get().getAsJsonArray().size() == 0) {
return Optional.empty();
Expand All @@ -184,10 +183,10 @@ private Optional<Map<Resolution, FilmUrl>> parseUrl(JsonElement jsonElement) {
}
}
}
return parseFallbackVideo(jsonElement);
return parseVideoFromSources(jsonElement);
}

private Optional<Map<Resolution, FilmUrl>> parseFallbackVideo(JsonElement root) {
private Optional<Map<Resolution, FilmUrl>> parseVideoFromSources(JsonElement root) {
Optional<JsonElement> videoSources = JsonUtils.getElement(root, TAG_VIDEO_FALLBACK);
if (videoSources.isPresent()) {
Map<Resolution, FilmUrl> urls = new EnumMap<>(Resolution.class);
Expand All @@ -208,7 +207,37 @@ private Optional<Map<Resolution, FilmUrl>> parseFallbackVideo(JsonElement root)
}
}
}
return Optional.empty();
return parseVideoFromThumbnail(root);
}



private Optional<Map<Resolution, FilmUrl>> parseVideoFromThumbnail(JsonElement root) {
Map<Resolution, FilmUrl> urls = new EnumMap<>(Resolution.class);
try {
Optional<JsonElement> id = JsonUtils.getElement(root, TAG_ID);
Optional<JsonElement> thumbnailSources = JsonUtils.getElement(root, VIDEO_THUMBNAIL);
if (id.isPresent() && thumbnailSources.isPresent() && thumbnailSources.get().isJsonArray() && thumbnailSources.get().getAsJsonArray().size() > 0 ) {
Optional<JsonElement> 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);
try {
urls.put(Resolution.NORMAL, new FilmUrl(url, 0L));
} catch (MalformedURLException e) {
LOG.error("Malformed video url {} {}", url, e);
}
}
}
} catch (Exception e) {
LOG.error("generateFallbackVideo {}", e);
}
if (urls.size() == 0) {
return Optional.empty();
}
return Optional.of(urls);
}

private Optional<Map<Resolution, FilmUrl>> readVideoForTargetCodec(JsonElement urlArray, String targetCodec) {
Expand Down

0 comments on commit 3514aed

Please sign in to comment.