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 #983

Merged
merged 1 commit into from
May 11, 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 @@ -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
Loading