Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ORF add parsevideofromthumbnail #982

Merged
merged 1 commit into from
May 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class OrfOnEpisodeDeserializer implements JsonDeserializer<OrfOnVideoInfo
private static final String[] TAG_SUBTITLE_SECTION = {"_embedded", "subtitle"};
private static final String TAG_SUBTITLE_TTML = "ttml_url";
private static final String[] PREFERED_CODEC = {"hls", "hds", "progressive"};
private static final String[] VIDEO_THUMBNAIL = {"thumbnail_sources","hls"};
//
private final OrfHttpClient connection;
//
Expand Down Expand Up @@ -91,7 +92,7 @@ public OrfOnVideoInfoDTO deserialize(
parseDuration(JsonUtils.getElementValueAsString(jsonElement, TAG_DURATION)),
JsonUtils.getElementValueAsString(jsonElement, TAG_DESCRIPTION),
parseWebsite(JsonUtils.getElementValueAsString(jsonElement, TAG_SHARE_BODY)),
optimizeUrls(parseUrl(jsonElement)),
optimizeUrls(parseVideoFromSegmentPlaylist(jsonElement)),
buildOrResolveSubs(jsonElement)

);
Expand Down Expand Up @@ -139,7 +140,7 @@ private Optional<String> parseSubtitleUrls(JsonElement element) {
return JsonUtils.getElementValueAsString(element, TAG_SUBTITLE_TTML);
}

private Optional<Map<Qualities, String>> parseUrl(JsonElement jsonElement) {
private Optional<Map<Qualities, String>> 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 @@ -157,10 +158,10 @@ private Optional<Map<Qualities, String>> parseUrl(JsonElement jsonElement) {
}
}
}
return parseFallbackVideo(jsonElement);
return parseVideoFromSources(jsonElement);
}

private Optional<Map<Qualities, String>> parseFallbackVideo(JsonElement root) {
private Optional<Map<Qualities, String>> parseVideoFromSources(JsonElement root) {
Optional<JsonElement> videoSources = JsonUtils.getElement(root, TAG_VIDEO_FALLBACK);
if (videoSources.isPresent()) {
Map<Qualities, String> urls = new EnumMap<>(Qualities.class);
Expand All @@ -177,7 +178,31 @@ private Optional<Map<Qualities, String>> parseFallbackVideo(JsonElement root) {
}
}
}
return Optional.empty();
return parseVideoFromThumbnail(root);
}

private Optional<Map<Qualities, String>> parseVideoFromThumbnail(JsonElement root) {
Map<Qualities, String> urls = new EnumMap<>(Qualities.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);
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<Map<Qualities, String>> readVideoForTargetCodec(JsonElement urlArray, String targetCodec) {
Expand Down
Loading