Skip to content

Commit

Permalink
partner filter
Browse files Browse the repository at this point in the history
  • Loading branch information
codingPF committed May 8, 2024
1 parent 67be16c commit aeb33aa
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package de.mediathekview.mserver.crawler.ard;

import java.util.HashMap;
import java.util.Map;

import de.mediathekview.mlib.daten.Sender;

public class ArdConstants {

public static final String API_URL = "https://api.ardmediathek.de";
Expand Down Expand Up @@ -38,6 +43,28 @@ public class ArdConstants {
"arte"
};

public static final Map<String, Sender> PARTNER_TO_SENDER = new HashMap<>();

static {
PARTNER_TO_SENDER.put("rbb", Sender.RBB);
PARTNER_TO_SENDER.put("swr", Sender.SWR);
PARTNER_TO_SENDER.put("mdr", Sender.MDR);
PARTNER_TO_SENDER.put("ndr", Sender.NDR);
PARTNER_TO_SENDER.put("wdr", Sender.WDR);
PARTNER_TO_SENDER.put("hr", Sender.HR);
PARTNER_TO_SENDER.put("br", Sender.BR);
PARTNER_TO_SENDER.put("radio_bremen", Sender.RBTV);
PARTNER_TO_SENDER.put("tagesschau24", Sender.ARD);
PARTNER_TO_SENDER.put("das_erste", Sender.ARD);
PARTNER_TO_SENDER.put("one", Sender.ONE); // ONE
PARTNER_TO_SENDER.put("ard-alpha", Sender.ARD_ALPHA); // ARD-alpha
PARTNER_TO_SENDER.put("funk", Sender.FUNK); // Funk.net
PARTNER_TO_SENDER.put("sr", Sender.SR);
PARTNER_TO_SENDER.put("phoenix", Sender.PHOENIX);
PARTNER_TO_SENDER.put("ard", Sender.ARD);
//IGNORED_SENDER "zdf", "kika", "3sat", "arte"
}

public static final String WEBSITE_URL = "https://www.ardmediathek.de/video/%s";

public static final String BASE_URL_SUBTITLES = "https://classic.ardmediathek.de";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,30 @@ public List<ArdFilmDto> deserialize(
JsonUtils.getAttributeAsString(itemObject, ATTRIBUTE_SYNOPSIS);
final Optional<LocalDateTime> date = parseDate(itemObject);
final Optional<Duration> duration = parseDuration(itemObject);
final Sender sender = determinePartner(itemObject);
final Optional<ArdVideoInfoDto> videoInfo = parseVideos(itemObject);

//final Sender sender = determinePartner(itemObject);
final Optional<String> partner = parsePartner(itemObject);
final Sender sender = ArdConstants.PARTNER_TO_SENDER.get(partner.orElse(""));
final Optional<ArdVideoInfoDto> videoInfo = parseVideos(itemObject, title.orElse(""));

if(title.orElse("").contains("- Die Antwort auf fast")) {

System.out.println("stop");
}

if (title.isEmpty() || topic.isEmpty() || videoInfo.isEmpty()) {
return films;
}

if (sender == null) {
LOG.error("Missing Partner {}", partner.orElse(""));
if (partner.isEmpty()) {
LOG.error("Missing Partner Element {}", jsonElement);
}

return films;
}


// add film to ARD
final ArdFilmDto filmDto =
new ArdFilmDto(
Expand Down Expand Up @@ -215,19 +233,26 @@ private Optional<String> parseTitle(final JsonObject playerPageObject) {
return title.map(nonNullTitle -> nonNullTitle.replace("Hörfassung", "Audiodeskription"));
}


/*
private Sender determinePartner(JsonObject playerPageObject) {
final Optional<String> partner = parsePartner(playerPageObject);
final Sender sender;
// If partner is present and an existing sender set it. Like for RBB
Sender partnerSender = null;
if (partner.isPresent()) {
final Optional<Sender> additionalSender = Sender.getSenderByName(partner.get());
sender = additionalSender.orElse(Sender.ARD);
partnerSender = ArdConstants.PARTNER_TO_SENDER.get(partner.get());
if (partnerSender != null) {
return partnerSender;
} else {
partnerSender = Sender.ARD;
LOG.info("unkown partner {}", partner.get() );
}
} else {
sender = Sender.ARD;
partnerSender = Sender.ARD;
LOG.info("missing partner {}", playerPageObject);
}
return sender;
}
return partnerSender;
} */

private Optional<String> parsePartner(final JsonObject playerPageObject) {
if (playerPageObject.has(ELEMENT_PUBLICATION_SERVICE)) {
Expand Down Expand Up @@ -344,7 +369,7 @@ private void addDGSUrls(final Film film, final Map<Resolution, String> videoUrls
}
}

private Optional<ArdVideoInfoDto> parseVideos(final JsonObject playerPageObject) {
private Optional<ArdVideoInfoDto> parseVideos(final JsonObject playerPageObject, final String title) {
ArdVideoInfoDto allVideoUrls = new ArdVideoInfoDto();
//
final Optional<Map<Resolution, String>> videoInfoStandard = parseVideoUrls(playerPageObject, MARKER_VIDEO_CATEGORY_MAIN, MARKER_VIDEO_STANDARD, MARKER_VIDEO_MP4);
Expand All @@ -362,9 +387,10 @@ private Optional<ArdVideoInfoDto> parseVideos(final JsonObject playerPageObject)
if (videoInfoDGS.isPresent()) {
allVideoUrls.putAllDGS(videoInfoDGS.get());
}
if (videoInfoStandard.isPresent()) {
// Sometimes we have DGS & standard
if (videoInfoStandard.isPresent() && !(videoInfoDGS.isPresent() && title.contains("Gebärdensprache"))) {
allVideoUrls.putAll(videoInfoStandard.get());
} else if (videoInfoAdaptive.isPresent()) {
} else if (videoInfoAdaptive.isPresent() && !(videoInfoDGS.isPresent() && title.contains("Gebärdensprache"))) {
ArdVideoInfoDto fallbackM3UUrl = new ArdVideoInfoDto();
fallbackM3UUrl.putAll(videoInfoAdaptive.get());
Optional<Map<Resolution, String>> fallback = fallbackToM3U(Optional.of(fallbackM3UUrl));
Expand Down Expand Up @@ -410,10 +436,15 @@ private Optional<Map<Resolution, String>> parseVideoUrls(final JsonObject player
}
}
}
if (videoInfo.size() > 0) {
return Optional.of(videoInfo);
} else {
if (videoInfo.size() == 0) {
return Optional.empty();
}
// TODO: FIX ME
if (!videoInfo.containsKey(Resolution.NORMAL)) {
Resolution r = videoInfo.keySet().stream().findFirst().get();
videoInfo.put(Resolution.NORMAL, videoInfo.get(r));
videoInfo.remove(r);
}
return Optional.of(videoInfo);
}
}

0 comments on commit aeb33aa

Please sign in to comment.