Skip to content

Commit

Permalink
OldFormatWriter AD & GS logic
Browse files Browse the repository at this point in the history
  • Loading branch information
codingPF committed Nov 19, 2023
1 parent 49bce56 commit 11b633e
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,28 @@ public boolean write(Filmlist filmlist, OutputStream outputStream) throws IOExce
writeColumnHeader(jsonWriter);
filmlist.getSorted(MediaResourceComperators.DEFAULT_COMPERATOR.getComparator()).forEach(aFilm -> {
try {
writeRecord(aFilm, jsonWriter);
cnt++;
if (aFilm.getUrls().size() > 0) {
writeRecord(aFilm, jsonWriter);
cnt++;
}
if (aFilm instanceof Film pFilm && pFilm.getAudioDescriptions().size() > 0) {
Film AD = new Film(pFilm);
if (!AD.getTitel().toLowerCase().contains("audiodeskription")) {
AD.setTitel(AD.getTitel() + " (Audiodeskription)");
}
AD.setUrls(AD.getAudioDescriptions());
writeRecord(AD, jsonWriter);
cnt++;
}
if (aFilm instanceof Film pFilm && pFilm.getSignLanguages().size() > 0) {
Film GS = new Film(pFilm);
if (!GS.getTitel().toLowerCase().contains("gebärdensprache")) {
GS.setTitel(GS.getTitel() + " (Gebärdensprache)");
}
GS.setUrls(GS.getSignLanguages());
writeRecord(GS, jsonWriter);
cnt++;
}
} catch (IOException e) {
LOG.error(e);
}
Expand Down Expand Up @@ -206,10 +226,6 @@ private String writeRecord08Beschreibung(AbstractMediaResource<?> in) {
private String writeRecord09UrlNormal(AbstractMediaResource<?> in) {
if ((in instanceof Podcast pIn) && pIn.getUrl(Resolution.NORMAL) != null) {
return pIn.getUrl(Resolution.NORMAL).getUrl().toString();
} else if ((in instanceof Film pIn) && pIn.getAudioDescription(Resolution.NORMAL) != null) {
return pIn.getAudioDescription(Resolution.NORMAL).getUrl().toString();
} else if ((in instanceof Film pIn) && pIn.getSignLanguage(Resolution.NORMAL) != null) {
return pIn.getSignLanguage(Resolution.NORMAL).getUrl().toString();
}
return "";
}
Expand All @@ -235,10 +251,6 @@ private String writeRecord12UrlRTMP(AbstractMediaResource<?> in) {
private String writeRecord13UrlKlein(AbstractMediaResource<?> in) {
if ((in instanceof Podcast pIn) && in.getUrl(Resolution.SMALL) != null && pIn.getUrl(Resolution.NORMAL) != null) {
return reduceUrl(pIn.getUrl(Resolution.NORMAL).getUrl().toString(), pIn.getUrl(Resolution.SMALL).getUrl().toString());
} else if ((in instanceof Film pIn) && pIn.getAudioDescription(Resolution.NORMAL) != null && pIn.getAudioDescription(Resolution.SMALL) != null) {
return reduceUrl(pIn.getAudioDescription(Resolution.NORMAL).getUrl().toString(), pIn.getAudioDescription(Resolution.SMALL).getUrl().toString());
} else if ((in instanceof Film pIn) && pIn.getSignLanguage(Resolution.NORMAL) != null && pIn.getSignLanguage(Resolution.SMALL) != null) {
return reduceUrl(pIn.getSignLanguage(Resolution.NORMAL).getUrl().toString(), pIn.getSignLanguage(Resolution.SMALL).getUrl().toString());
}
return "";
}
Expand All @@ -250,10 +262,6 @@ private String writeRecord14UrlKleinRTMP(AbstractMediaResource<?> in) {
private String writeRecord15UrlHD(AbstractMediaResource<?> in) {
if ((in instanceof Podcast pIn) && in.getUrl(Resolution.HD) != null && in.getUrl(Resolution.NORMAL) != null) {
return reduceUrl(pIn.getUrl(Resolution.NORMAL).getUrl().toString(), pIn.getUrl(Resolution.HD).getUrl().toString());
} else if ((in instanceof Film pIn) && pIn.getAudioDescription(Resolution.NORMAL) != null && pIn.getAudioDescription(Resolution.HD) != null) {
return reduceUrl(pIn.getAudioDescription(Resolution.NORMAL).getUrl().toString(), pIn.getAudioDescription(Resolution.HD).getUrl().toString());
} else if ((in instanceof Film pIn) && pIn.getSignLanguage(Resolution.NORMAL) != null && pIn.getSignLanguage(Resolution.HD) != null) {
return reduceUrl(pIn.getSignLanguage(Resolution.NORMAL).getUrl().toString(), pIn.getSignLanguage(Resolution.HD).getUrl().toString());
}
return "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ void readFilmlistOldFormatIncludingBrokenRecords()
void readWriteFilmlistAndCheckAllUrlTypesDoPersist()
throws IOException {
//
Filmlist input = inputFilmlist();
Filmlist expected = expectedFilmlist();
//
Path tempFile = Files.createTempFile(tempDir, "TestFilmlistOldFormatWriter", ".out");
new FilmlistOldFormatWriter().write(expected, tempFile);
new FilmlistOldFormatWriter().write(input, tempFile);
assertTrue( Files.exists(tempFile));
//
Optional<Filmlist> afterWriteAndRead = new FilmlistOldFormatReader().read(new FileInputStream(tempFile.toString()));
Expand Down Expand Up @@ -92,12 +94,6 @@ private void compareFilmIncludingShifterUrls(Film aFilm, Film bFilm) {
bFilm.getUrls().forEach( (resolution, url) -> {
if (aFilm.getUrl(resolution) != null) {
assertEquals(aFilm.getUrl(resolution).toString(), url.toString());
} else if (aFilm.getAudioDescription(resolution) != null) {
assertEquals(aFilm.getAudioDescription(resolution).toString(), url.toString());
} else if (aFilm.getSignLanguage(resolution) != null) {
assertEquals(aFilm.getSignLanguage(resolution).toString(), url.toString());
} else {
assertEquals("We did expect an url but could not find any", "");
}
});
}
Expand All @@ -111,7 +107,7 @@ private Filmlist expectedFilmlist() {
completeMatchExpected.setUuid(UUID.randomUUID());
completeMatchExpected.setSender(Sender.DREISAT);
completeMatchExpected.setThema("37 Grad");
completeMatchExpected.setTitelRaw("37° Totgerast");
completeMatchExpected.setTitelRaw("37°: Ein Gen verändert unser Leben");
completeMatchExpected.setBeschreibung("description");
completeMatchExpected.setDuration(Duration.ofMinutes(28).plusSeconds(45));
completeMatchExpected.setTime(LocalDateTime.of(2023, 5, 30, 22, 15, 0));
Expand Down Expand Up @@ -143,11 +139,139 @@ private Filmlist expectedFilmlist() {
completeMatchExpected.setUuid(UUID.randomUUID());
completeMatchExpected.setSender(Sender.DREISAT);
completeMatchExpected.setThema("37 Grad");
completeMatchExpected.setTitelRaw("37°: Ein Gen verändert unser Leben (Gebaerdensprache)");
completeMatchExpected.setTitelRaw("37°: Ein Gen verändert unser Leben (Gebärdensprache)");
completeMatchExpected.setBeschreibung("description \"37°\" with quotes");
completeMatchExpected.setDuration(Duration.ofMinutes(28).plusSeconds(41));
completeMatchExpected.setTime(LocalDateTime.of(2023, 5, 16, 22, 15, 0));
completeMatchExpected.setWebsite(new URL("https://host.de/something/website.html"));
completeMatchExpected.addSignLanguage(Resolution.NORMAL, new FilmUrl(new URL("https://some.host.de/SignLanguageNormal.mp4"), 405L));
completeMatchExpected.addSignLanguage(Resolution.SMALL, new FilmUrl(new URL("https://some.host.de/SignLanguageSmall.mp4"), 0L));
completeMatchExpected.addSignLanguage(Resolution.HD, new FilmUrl(new URL("https://some.host.de/SignLanguageHd.mp4"), 0L));
completeMatchExpected.addGeolocation(GeoLocations.GEO_DE_AT_CH);
completeMatchExpected.addSubtitle(new URL("https://host.de/23/05/230502_2215_sendung_37g/4/subtitle.xml"));
expectedFilmlist.add(completeMatchExpected);
//
completeMatchExpected = new Film();
completeMatchExpected.setUuid(UUID.randomUUID());
completeMatchExpected.setSender(Sender.DREISAT);
completeMatchExpected.setThema("37 Grad");
completeMatchExpected.setTitelRaw("37°: Everything at once");
completeMatchExpected.setBeschreibung("description \"37°\" with quotes");
completeMatchExpected.setDuration(Duration.ofMinutes(28).plusSeconds(41));
completeMatchExpected.setTime(LocalDateTime.of(2023, 5, 16, 22, 15, 0));
completeMatchExpected.setWebsite(new URL("https://host.de/something/website.html"));
completeMatchExpected.addUrl(Resolution.NORMAL, new FilmUrl(new URL("https://some.host.de/normal.mp4"), 405L));
completeMatchExpected.addUrl(Resolution.SMALL, new FilmUrl(new URL("https://some.host.de/small.mp4"), 0L));
completeMatchExpected.addUrl(Resolution.HD, new FilmUrl(new URL("https://some.host.de/hd.mp4"), 0L));
completeMatchExpected.addGeolocation(GeoLocations.GEO_DE_AT_CH);
completeMatchExpected.addSubtitle(new URL("https://host.de/23/05/230502_2215_sendung_37g/4/subtitle.xml"));
expectedFilmlist.add(completeMatchExpected);
//
completeMatchExpected = new Film();
completeMatchExpected.setUuid(UUID.randomUUID());
completeMatchExpected.setSender(Sender.DREISAT);
completeMatchExpected.setThema("37 Grad");
completeMatchExpected.setTitelRaw("37°: Everything at once (Audiodeskription)");
completeMatchExpected.setBeschreibung("description \"37°\" with quotes");
completeMatchExpected.setDuration(Duration.ofMinutes(28).plusSeconds(41));
completeMatchExpected.setTime(LocalDateTime.of(2023, 5, 16, 22, 15, 0));
completeMatchExpected.setWebsite(new URL("https://host.de/something/website.html"));
completeMatchExpected.addUrl(Resolution.NORMAL, new FilmUrl(new URL("https://some.host.de/AudioDescriptionNormal.mp4"), 405L));
completeMatchExpected.addUrl(Resolution.SMALL, new FilmUrl(new URL("https://some.host.de/AudioDescriptionSmall.mp4"), 0L));
completeMatchExpected.addUrl(Resolution.HD, new FilmUrl(new URL("https://some.host.de/AudioDescriptionHd.mp4"), 0L));
completeMatchExpected.addGeolocation(GeoLocations.GEO_DE_AT_CH);
completeMatchExpected.addSubtitle(new URL("https://host.de/23/05/230502_2215_sendung_37g/4/subtitle.xml"));
expectedFilmlist.add(completeMatchExpected);
//
completeMatchExpected = new Film();
completeMatchExpected.setUuid(UUID.randomUUID());
completeMatchExpected.setSender(Sender.DREISAT);
completeMatchExpected.setThema("37 Grad");
completeMatchExpected.setTitelRaw("37°: Everything at once (Gebärdensprache)");
completeMatchExpected.setBeschreibung("description \"37°\" with quotes");
completeMatchExpected.setDuration(Duration.ofMinutes(28).plusSeconds(41));
completeMatchExpected.setTime(LocalDateTime.of(2023, 5, 16, 22, 15, 0));
completeMatchExpected.setWebsite(new URL("https://host.de/something/website.html"));
completeMatchExpected.addUrl(Resolution.NORMAL, new FilmUrl(new URL("https://some.host.de/SignLanguageNormal.mp4"), 405L));
completeMatchExpected.addUrl(Resolution.SMALL, new FilmUrl(new URL("https://some.host.de/SignLanguageSmall.mp4"), 0L));
completeMatchExpected.addUrl(Resolution.HD, new FilmUrl(new URL("https://some.host.de/SignLanguageHd.mp4"), 0L));
completeMatchExpected.addGeolocation(GeoLocations.GEO_DE_AT_CH);
completeMatchExpected.addSubtitle(new URL("https://host.de/23/05/230502_2215_sendung_37g/4/subtitle.xml"));
expectedFilmlist.add(completeMatchExpected);

} catch (Exception e) {
e.printStackTrace();
}
return expectedFilmlist;
}

private Filmlist inputFilmlist() {
Filmlist expectedFilmlist = new Filmlist();
try {
Film completeMatchExpected = new Film();
//
completeMatchExpected.setUuid(UUID.randomUUID());
completeMatchExpected.setSender(Sender.DREISAT);
completeMatchExpected.setThema("37 Grad");
completeMatchExpected.setTitelRaw("37°: Ein Gen verändert unser Leben");
completeMatchExpected.setBeschreibung("description");
completeMatchExpected.setDuration(Duration.ofMinutes(28).plusSeconds(45));
completeMatchExpected.setTime(LocalDateTime.of(2023, 5, 30, 22, 15, 0));
completeMatchExpected.setWebsite(new URL("https://host.de/something/website.html"));
completeMatchExpected.addUrl(Resolution.NORMAL, new FilmUrl(new URL("https://some.host.de/normal.mp4"), 405L));
completeMatchExpected.addUrl(Resolution.SMALL, new FilmUrl(new URL("https://some.host.de/small.mp4"), 0L));
completeMatchExpected.addUrl(Resolution.HD, new FilmUrl(new URL("https://some.host.de/hd.mp4"), 0L));
completeMatchExpected.addGeolocation(GeoLocations.GEO_DE_AT_CH);
completeMatchExpected.addSubtitle(new URL("https://host.de/23/05/230502_2215_sendung_37g/4/subtitle.xml"));
expectedFilmlist.add(completeMatchExpected);
//
completeMatchExpected = new Film();
completeMatchExpected.setUuid(UUID.randomUUID());
completeMatchExpected.setSender(Sender.DREISAT);
completeMatchExpected.setThema("37 Grad");
completeMatchExpected.setTitelRaw("37°: Ein Gen verändert unser Leben (Audiodeskription)");
completeMatchExpected.setBeschreibung("description \"37°\" with quotes");
completeMatchExpected.setDuration(Duration.ofMinutes(28).plusSeconds(41));
completeMatchExpected.setTime(LocalDateTime.of(2023, 5, 16, 22, 15, 0));
completeMatchExpected.setWebsite(new URL("https://host.de/something/website.html"));
completeMatchExpected.addAudioDescription(Resolution.NORMAL, new FilmUrl(new URL("https://some.host.de/AudioDescriptionNormal.mp4"), 405L));
completeMatchExpected.addAudioDescription(Resolution.SMALL, new FilmUrl(new URL("https://some.host.de/AudioDescriptionSmall.mp4"), 0L));
completeMatchExpected.addAudioDescription(Resolution.HD, new FilmUrl(new URL("https://some.host.de/AudioDescriptionHd.mp4"), 0L));
completeMatchExpected.addGeolocation(GeoLocations.GEO_DE_AT_CH);
completeMatchExpected.addSubtitle(new URL("https://host.de/23/05/230502_2215_sendung_37g/4/subtitle.xml"));
expectedFilmlist.add(completeMatchExpected);
//
completeMatchExpected = new Film();
completeMatchExpected.setUuid(UUID.randomUUID());
completeMatchExpected.setSender(Sender.DREISAT);
completeMatchExpected.setThema("37 Grad");
completeMatchExpected.setTitelRaw("37°: Ein Gen verändert unser Leben (Gebärdensprache)");
completeMatchExpected.setBeschreibung("description \"37°\" with quotes");
completeMatchExpected.setDuration(Duration.ofMinutes(28).plusSeconds(41));
completeMatchExpected.setTime(LocalDateTime.of(2023, 5, 16, 22, 15, 0));
completeMatchExpected.setWebsite(new URL("https://host.de/something/website.html"));
completeMatchExpected.addSignLanguage(Resolution.NORMAL, new FilmUrl(new URL("https://some.host.de/SignLanguageNormal.mp4"), 405L));
completeMatchExpected.addSignLanguage(Resolution.SMALL, new FilmUrl(new URL("https://some.host.de/SignLanguageSmall.mp4"), 0L));
completeMatchExpected.addSignLanguage(Resolution.HD, new FilmUrl(new URL("https://some.host.de/SignLanguageHd.mp4"), 0L));
completeMatchExpected.addGeolocation(GeoLocations.GEO_DE_AT_CH);
completeMatchExpected.addSubtitle(new URL("https://host.de/23/05/230502_2215_sendung_37g/4/subtitle.xml"));
expectedFilmlist.add(completeMatchExpected);
//
completeMatchExpected = new Film();
completeMatchExpected.setUuid(UUID.randomUUID());
completeMatchExpected.setSender(Sender.DREISAT);
completeMatchExpected.setThema("37 Grad");
completeMatchExpected.setTitelRaw("37°: Everything at once");
completeMatchExpected.setBeschreibung("description \"37°\" with quotes");
completeMatchExpected.setDuration(Duration.ofMinutes(28).plusSeconds(41));
completeMatchExpected.setTime(LocalDateTime.of(2023, 5, 16, 22, 15, 0));
completeMatchExpected.setWebsite(new URL("https://host.de/something/website.html"));
completeMatchExpected.addUrl(Resolution.NORMAL, new FilmUrl(new URL("https://some.host.de/normal.mp4"), 405L));
completeMatchExpected.addUrl(Resolution.SMALL, new FilmUrl(new URL("https://some.host.de/small.mp4"), 0L));
completeMatchExpected.addUrl(Resolution.HD, new FilmUrl(new URL("https://some.host.de/hd.mp4"), 0L));
completeMatchExpected.addAudioDescription(Resolution.NORMAL, new FilmUrl(new URL("https://some.host.de/AudioDescriptionNormal.mp4"), 405L));
completeMatchExpected.addAudioDescription(Resolution.SMALL, new FilmUrl(new URL("https://some.host.de/AudioDescriptionSmall.mp4"), 0L));
completeMatchExpected.addAudioDescription(Resolution.HD, new FilmUrl(new URL("https://some.host.de/AudioDescriptionHd.mp4"), 0L));
completeMatchExpected.addSignLanguage(Resolution.NORMAL, new FilmUrl(new URL("https://some.host.de/SignLanguageNormal.mp4"), 405L));
completeMatchExpected.addSignLanguage(Resolution.SMALL, new FilmUrl(new URL("https://some.host.de/SignLanguageSmall.mp4"), 0L));
completeMatchExpected.addSignLanguage(Resolution.HD, new FilmUrl(new URL("https://some.host.de/SignLanguageHd.mp4"), 0L));
Expand Down

0 comments on commit 11b633e

Please sign in to comment.