diff --git a/build.gradle b/build.gradle index 49b92a928..454cdc308 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ import java.nio.file.Files plugins { id 'application' id 'com.github.jk1.dependency-license-report' version "2.0" - id "org.sonarqube" version "3.4.0.2513" + id "org.sonarqube" version "4.4.1.3373" id 'org.openjfx.javafxplugin' version '0.0.13' } @@ -33,26 +33,31 @@ def jarName = 'MServer.jar' def mainClass = 'mServer.Main' dependencies { - implementation 'de.mediathekview:MLib:3.0.13' + compileOnly "com.sun.xml.ws:jaxws-rt:2.3.6" + compileOnly "org.glassfish.jaxb:jaxb-runtime:2.3.8" + + implementation 'de.mediathekview:MLib:3.0.14' implementation 'commons-net:commons-net:3.9.0' - implementation 'org.apache.commons:commons-compress:1.22' + implementation 'org.apache.commons:commons-compress:1.24.0' implementation 'org.apache.commons:commons-text:1.10.0' implementation 'org.tukaani:xz:1.9' implementation 'com.google.code.gson:gson:2.10.1' - implementation 'org.glassfish.jersey.core:jersey-client:3.0.8' - implementation 'org.glassfish.jersey.inject:jersey-hk2:3.0.8' - implementation 'org.jsoup:jsoup:1.15.4' + implementation 'org.glassfish.jersey.core:jersey-client:3.1.3' + implementation 'org.glassfish.jersey.inject:jersey-hk2:3.1.3' + implementation 'org.jsoup:jsoup:1.16.1' implementation 'javax.activation:activation:1.1.1' - implementation 'com.google.guava:guava:31.1-jre' + implementation 'com.google.guava:guava:32.0.0-jre' implementation 'org.apache.logging.log4j:log4j-core:2.20.0' implementation 'fm.void.jetm:jetm:1.2.3' testImplementation 'junit:junit:4.13.2' - testImplementation 'org.mockito:mockito-core:4.11.0' + testImplementation 'org.mockito:mockito-core:5.4.0' testImplementation 'com.squareup.okhttp3:mockwebserver:4.10.0' testImplementation "org.hamcrest:hamcrest-all:1.3" - testImplementation 'org.assertj:assertj-core:3.23.1' + testImplementation 'org.assertj:assertj-core:3.24.2' + testImplementation "com.sun.xml.ws:jaxws-rt:2.3.6" + testImplementation "org.glassfish.jaxb:jaxb-runtime:2.3.8" } @@ -174,7 +179,7 @@ processResources.dependsOn generateLicenseReport [distZip, distTar]*.shouldRunAfter compileJava, updateVersion, jar distTar.compression = Compression.GZIP -distTar.extension = 'tar.gz' +distTar.archiveExtension = 'tar.gz' jar { manifest { @@ -183,7 +188,7 @@ jar { 'Class-Path': configurations.compileClasspath.files.collect { "lib/$it.name" }.join(' ') ) } - archiveName = jarName + archiveFileName = jarName } distributions { diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 249e5832f..7f93135c4 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ae04661ee..ac72c34e8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index a69d9cb6c..0adc8e1a5 100755 --- a/gradlew +++ b/gradlew @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +80,11 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,22 +131,29 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -193,6 +198,10 @@ if "$cygwin" || "$msys" ; then done fi + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + # Collect all arguments for the java command; # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of # shell script including quotes and variable substitutions, so put them in diff --git a/gradlew.bat b/gradlew.bat index f127cfd49..93e3f59f1 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% diff --git a/src/main/java/mServer/crawler/FilmeSuchen.java b/src/main/java/mServer/crawler/FilmeSuchen.java index 91bd7bf76..5e3dd68a1 100644 --- a/src/main/java/mServer/crawler/FilmeSuchen.java +++ b/src/main/java/mServer/crawler/FilmeSuchen.java @@ -289,7 +289,7 @@ public ArrayList endeMeldung() { // Durchschnittswerte ausgeben double doub = (1.0 * listeSenderLaufen.get(RunSender.Count.SUM_TRAFFIC_BYTE)) / (sekunden == 0 ? 1 : sekunden) / 1000; - String rate = doub < 1 ? "<1" : String.format("%.1f", (doub)); + String rate = doub < 1 ? "<1" : "%.1f".formatted((doub)); retArray.add(" -> Rate[kB/s]: " + rate); retArray.add(" -> Dauer[Min]: " + (sekunden / 60 == 0 ? "<1" : sekunden / 60)); retArray.add(" -> Start: " + sdf.format(startZeit)); @@ -402,24 +402,24 @@ private void progressBar() { private void notifyStart(ListenerFilmeLadenEvent event) { for (Object l : listeners.getListenerList()) { - if (l instanceof ListenerFilmeLaden) { - ((ListenerFilmeLaden) l).start(event); + if (l instanceof ListenerFilmeLaden laden) { + laden.start(event); } } } private void notifyProgress(ListenerFilmeLadenEvent event) { for (Object l : listeners.getListenerList()) { - if (l instanceof ListenerFilmeLaden) { - ((ListenerFilmeLaden) l).progress(event); + if (l instanceof ListenerFilmeLaden laden) { + laden.progress(event); } } } private void notifyFertig(ListenerFilmeLadenEvent event) { for (Object l : listeners.getListenerList()) { - if (l instanceof ListenerFilmeLaden) { - ((ListenerFilmeLaden) l).fertig(event); + if (l instanceof ListenerFilmeLaden laden) { + laden.fertig(event); } } } diff --git a/src/main/java/mServer/crawler/ListeRunSender.java b/src/main/java/mServer/crawler/ListeRunSender.java index 67153e4fc..087a8b0be 100644 --- a/src/main/java/mServer/crawler/ListeRunSender.java +++ b/src/main/java/mServer/crawler/ListeRunSender.java @@ -122,7 +122,7 @@ public String getRate(String sender) { long groesseByte = get(sender, RunSender.Count.SUM_TRAFFIC_BYTE); if (groesseByte > 0 && dauerSender > 0) { double doub = (1.0 * groesseByte / dauerSender / 1000); // kB/s - rate = doub < 1 ? "<1" : String.format("%.1f", (doub)); + rate = doub < 1 ? "<1" : "%.1f".formatted((doub)); } return rate; } @@ -169,12 +169,12 @@ public void getTextSum(ArrayList retArray) { String rate = ""; if (groesseByte > 0 && dauerSender > 0) { double doub = (1.0 * groesseByte / dauerSender / 1000); // kB/s - rate = doub < 1 ? "<1" : String.format("%.1f", (doub)); + rate = doub < 1 ? "<1" : "%.1f".formatted((doub)); } String dauerProSeite = ""; if (anzahlSeiten > 0) { - dauerProSeite = String.format("%.2f", (1.0 * dauerSender / anzahlSeiten)); + dauerProSeite = "%.2f".formatted((1.0 * dauerSender / anzahlSeiten)); } // ================================= diff --git a/src/main/java/mServer/crawler/sender/MediathekReader.java b/src/main/java/mServer/crawler/sender/MediathekReader.java index baf07157b..e6fd951bb 100644 --- a/src/main/java/mServer/crawler/sender/MediathekReader.java +++ b/src/main/java/mServer/crawler/sender/MediathekReader.java @@ -229,7 +229,7 @@ protected void addFilm(DatenFilm film) { private void setFileSize(DatenFilm film) { // optimization for ORF and some others: don't try to determine filesize of m3u8-files Optional fileType = UrlUtils.getFileType(film.arr[DatenFilm.FILM_URL]); - if (!fileType.isPresent() || !fileType.get().equalsIgnoreCase("m3u8")) { + if (fileType.isEmpty() || !fileType.get().equalsIgnoreCase("m3u8")) { film.setFileSize(); } } diff --git a/src/main/java/mServer/crawler/sender/ard/ArdCrawler.java b/src/main/java/mServer/crawler/sender/ard/ArdCrawler.java index c6bf04ace..31425705b 100644 --- a/src/main/java/mServer/crawler/sender/ard/ArdCrawler.java +++ b/src/main/java/mServer/crawler/sender/ard/ArdCrawler.java @@ -67,7 +67,7 @@ private ConcurrentLinkedQueue createDayUrlsToCrawl() { private void addDayUrls(ConcurrentLinkedQueue dayUrlsToCrawl, LocalDateTime day) { final String formattedDay = day.format(DAY_PAGE_DATE_FORMATTER); for (String client : ArdConstants.CLIENTS) { - final String url = String.format(ArdConstants.DAY_PAGE_URL, client, formattedDay, formattedDay, ArdConstants.DAY_PAGE_SIZE); + final String url = (ArdConstants.DAY_PAGE_URL).formatted(client, formattedDay, formattedDay, ArdConstants.DAY_PAGE_SIZE); dayUrlsToCrawl.offer(new CrawlerUrlDTO(url)); } } @@ -144,7 +144,7 @@ private ConcurrentLinkedQueue getTopicEntriesBySender(final Strin private ConcurrentLinkedQueue createTopicsOverviewUrl(final String client) { final ConcurrentLinkedQueue urls = new ConcurrentLinkedQueue<>(); - final String url = String.format(ArdConstants.TOPICS_URL, client); + final String url = (ArdConstants.TOPICS_URL).formatted(client); urls.add(new CrawlerUrlDTO(url)); diff --git a/src/main/java/mServer/crawler/sender/ard/json/ArdVideoInfoJsonDeserializer.java b/src/main/java/mServer/crawler/sender/ard/json/ArdVideoInfoJsonDeserializer.java index a9ef781aa..5b8fdf197 100644 --- a/src/main/java/mServer/crawler/sender/ard/json/ArdVideoInfoJsonDeserializer.java +++ b/src/main/java/mServer/crawler/sender/ard/json/ArdVideoInfoJsonDeserializer.java @@ -74,7 +74,7 @@ private void loadM3U8(Map resolutionUrlMap) { if (resolution.isPresent()) { try { String videoUrl = entry.getUrl(); - if (!UrlUtils.getProtocol(videoUrl).isPresent()) { + if (UrlUtils.getProtocol(videoUrl).isEmpty()) { videoUrl = baseUrl + videoUrl; } resolutionUrlMap.put(resolution.get(), new URL(videoUrl)); @@ -99,7 +99,7 @@ private static Optional readContent(final URL aUrl) { return Optional.of(body.string()); } else { LOG.error( - String.format("ArdVideoInfoJsonDeserializer: Request '%s' failed: %s", aUrl, response.code())); + "ArdVideoInfoJsonDeserializer: Request '%s' failed: %s".formatted(aUrl, response.code())); } } catch (IOException ex) { LOG.error("ArdVideoInfoJsonDeserializer: ", ex); diff --git a/src/main/java/mServer/crawler/sender/ard/tasks/ArdFilmDetailTask.java b/src/main/java/mServer/crawler/sender/ard/tasks/ArdFilmDetailTask.java index 03119300c..e62341cd6 100644 --- a/src/main/java/mServer/crawler/sender/ard/tasks/ArdFilmDetailTask.java +++ b/src/main/java/mServer/crawler/sender/ard/tasks/ArdFilmDetailTask.java @@ -70,7 +70,7 @@ private void processRelatedFilms(final Set relatedFilms) { } private String getWebsiteUrl(final ArdFilmInfoDto aDTO) { - return String.format(ArdConstants.WEBSITE_URL, aDTO.getId()); + return (ArdConstants.WEBSITE_URL).formatted(aDTO.getId()); } @Override diff --git a/src/main/java/mServer/crawler/sender/ard/tasks/ArdTaskBase.java b/src/main/java/mServer/crawler/sender/ard/tasks/ArdTaskBase.java index 629651af7..32b625280 100644 --- a/src/main/java/mServer/crawler/sender/ard/tasks/ArdTaskBase.java +++ b/src/main/java/mServer/crawler/sender/ard/tasks/ArdTaskBase.java @@ -95,7 +95,7 @@ private boolean isSuccessResponse( LOG.error(logText); }); - return !error.isPresent(); + return error.isEmpty(); } private Response executeRequest(final WebTarget aTarget) { diff --git a/src/main/java/mServer/crawler/sender/arte/ArteCategoryFilmListDeserializer.java b/src/main/java/mServer/crawler/sender/arte/ArteCategoryFilmListDeserializer.java index 7484c964e..a73629c31 100644 --- a/src/main/java/mServer/crawler/sender/arte/ArteCategoryFilmListDeserializer.java +++ b/src/main/java/mServer/crawler/sender/arte/ArteCategoryFilmListDeserializer.java @@ -47,7 +47,7 @@ public ArteCategoryFilmsDTO deserialize(JsonElement aJsonElement, Type aType, Js if (programId.startsWith("RC-")) { try { long collectionId = Long.parseLong(programId.replace("RC-", "")); - dto.addCollection(String.format("RC-%06d", collectionId)); + dto.addCollection("RC-%06d".formatted(collectionId)); } catch (NumberFormatException e) { Log.errorLog(12834939, "Invalid collection id: " + programId); } diff --git a/src/main/java/mServer/crawler/sender/arte/ArteHttpClient.java b/src/main/java/mServer/crawler/sender/arte/ArteHttpClient.java index 367f9a0f0..72bfe51c7 100644 --- a/src/main/java/mServer/crawler/sender/arte/ArteHttpClient.java +++ b/src/main/java/mServer/crawler/sender/arte/ArteHttpClient.java @@ -80,8 +80,8 @@ public static T executeRequest(final String sender, Logger logger, Gson gson stop = true; } else { if (response.code() != 429) { - logger.error(String.format("ARTE Request '%s' failed: %s", aUrl, response.code())); - Log.sysLog(String.format("ARTE Request '%s' failed: %s", aUrl, response.code())); + logger.error("ARTE Request '%s' failed: %s".formatted(aUrl, response.code())); + Log.sysLog("ARTE Request '%s' failed: %s".formatted(aUrl, response.code())); FilmeSuchen.listeSenderLaufen.inc(sender, RunSender.Count.FEHLER); stop = true; } else { diff --git a/src/main/java/mServer/crawler/sender/arte/ArteProgramIdToDatenFilmCallable.java b/src/main/java/mServer/crawler/sender/arte/ArteProgramIdToDatenFilmCallable.java index c23252e82..854e2a558 100644 --- a/src/main/java/mServer/crawler/sender/arte/ArteProgramIdToDatenFilmCallable.java +++ b/src/main/java/mServer/crawler/sender/arte/ArteProgramIdToDatenFilmCallable.java @@ -55,7 +55,7 @@ public Set call() throws Exception { .registerTypeAdapter(ArteVideoDetailsDTO.class, new ArteVideoDetailsDeserializer(today)) .create(); - String videosUrl = String.format(ARTE_VIDEO_INFORMATION_URL_PATTERN, programId, langCode); + String videosUrl = ARTE_VIDEO_INFORMATION_URL_PATTERN.formatted(programId, langCode); ArteVideoDTO video = ArteHttpClient.executeRequest(senderName, LOG, gson, videosUrl, ArteVideoDTO.class); if (video != null) { @@ -76,7 +76,7 @@ public Set call() throws Exception { if (video.getVideoUrls().containsKey(Qualities.NORMAL)) { films.add(createFilm(details.getTheme(), details.getWebsite(), details.getTitle(), video.getVideoUrls(), details, durationAsTime, details.getDescription())); } else { - Log.sysLog(String.format("%s: no normal video url found for film %s, but small/hd", senderName, programId)); + Log.sysLog("%s: no normal video url found for film %s, but small/hd".formatted(senderName, programId)); FilmeSuchen.listeSenderLaufen.inc(senderName, RunSender.Count.FEHLER); } } @@ -102,7 +102,7 @@ public Set call() throws Exception { private ArteVideoDetailsDTO getVideoDetails(Gson gson, String programId) { //https://api.arte.tv/api/opa/v3/programs/[language:de/fr]/[programId] - String videosUrlVideoDetails2 = String.format(ARTE_VIDEO_INFORMATION_URL_PATTERN_2, langCode, programId); + String videosUrlVideoDetails2 = ARTE_VIDEO_INFORMATION_URL_PATTERN_2.formatted(langCode, programId); return ArteHttpClient.executeRequest(senderName, LOG, gson, videosUrlVideoDetails2, ArteVideoDetailsDTO.class); } diff --git a/src/main/java/mServer/crawler/sender/arte/MediathekArte.java b/src/main/java/mServer/crawler/sender/arte/MediathekArte.java index d8d382add..a659d17d4 100644 --- a/src/main/java/mServer/crawler/sender/arte/MediathekArte.java +++ b/src/main/java/mServer/crawler/sender/arte/MediathekArte.java @@ -145,7 +145,7 @@ public void addToList() { private void addCategories() { senderLanguages.forEach((sender, langCode) -> { for (String category : CATEGORIES) { - String categoryUrl = String.format(URL_CATEGORY, langCode.toLowerCase(), category); + String categoryUrl = URL_CATEGORY.formatted(langCode.toLowerCase(), category); listeThemen.add(new String[]{sender, langCode, category, categoryUrl}); } }); @@ -155,11 +155,11 @@ private void addTage() { senderLanguages.forEach((sender, langCode) -> { // http://www.arte.tv/guide/de/plus7/videos?day=-2&page=1&isLoading=true&sort=newest&country=DE for (int i = 0; i <= 14; ++i) { - String u = String.format(ARTE_API_TAG_URL_PATTERN, langCode.toUpperCase(), LocalDate.now().minusDays(i).format(ARTE_API_DATEFORMATTER)); + String u = ARTE_API_TAG_URL_PATTERN.formatted(langCode.toUpperCase(), LocalDate.now().minusDays(i).format(ARTE_API_DATEFORMATTER)); listeThemen.add(new String[]{sender, u}); } for (int i = 1; i <= 21; ++i) { - String u = String.format(ARTE_API_TAG_URL_PATTERN, langCode.toUpperCase(), LocalDate.now().plusDays(i).format(ARTE_API_DATEFORMATTER)); + String u = ARTE_API_TAG_URL_PATTERN.formatted(langCode.toUpperCase(), LocalDate.now().plusDays(i).format(ARTE_API_DATEFORMATTER)); listeThemen.add(new String[]{sender, u}); } }); @@ -233,22 +233,22 @@ private void loadCategory(String sender, String langCode, String aCategory, Stri ArteCategoryFilmsDTO dto = loadSubCategoryPage(gson, sender, aUrl); if (dto != null) { loadCollections(sender, langCode, gsonCollectionParent, gsonCollectionChild, dto); - Log.sysLog(String.format("%s: category %s: %d programs, %d collections", sender, aCategory, dto.getProgramIds().size(), dto.getCollectionIds().size())); + Log.sysLog("%s: category %s: %d programs, %d collections".formatted(sender, aCategory, dto.getProgramIds().size(), dto.getCollectionIds().size())); // alle programIds verarbeiten ListeFilme loadedFilme = loadPrograms(sender, langCode, dto); loadedFilme.forEach(film -> addFilm(film)); - Log.sysLog(String.format("%s: category %s: %d Filme", sender, aCategory, loadedFilme.size())); + Log.sysLog("%s: category %s: %d Filme".formatted(sender, aCategory, loadedFilme.size())); } } private void loadCollections(String sender, String langCode, Gson gsonParent, Gson gsonChild, ArteCategoryFilmsDTO dto) { dto.getCollectionIds().forEach(collectionId -> { - final String url = String.format(COLLECTION_URL, langCode, collectionId); + final String url = COLLECTION_URL.formatted(langCode, collectionId); try { final ArteCategoryFilmsDTO parentDto = ArteHttpClient.executeRequest(sender, LOG, gsonParent, url, ArteCategoryFilmsDTO.class); if (parentDto != null) { parentDto.getCollectionIds().forEach(childCollectionId -> { - final String urlChild = String.format(COLLECTION_URL, langCode, childCollectionId); + final String urlChild = COLLECTION_URL.formatted(langCode, childCollectionId); final ArteCategoryFilmsDTO collectionDto = ArteHttpClient.executeRequest(sender, LOG, gsonChild, urlChild, ArteCategoryFilmsDTO.class); if (collectionDto != null) { collectionDto.getProgramIds().forEach(dto::addProgramId); diff --git a/src/main/java/mServer/crawler/sender/base/AbstractDocumentTask.java b/src/main/java/mServer/crawler/sender/base/AbstractDocumentTask.java index c266240d8..4e01953d1 100644 --- a/src/main/java/mServer/crawler/sender/base/AbstractDocumentTask.java +++ b/src/main/java/mServer/crawler/sender/base/AbstractDocumentTask.java @@ -66,7 +66,7 @@ protected void processElement(final D aUrlDTO) { traceRequest(); processDocument(aUrlDTO, document); } catch (final HttpStatusException httpStatusError) { - Log.sysLog(String.format(LOAD_DOCUMENT_HTTPERROR, crawler.getSendername(), aUrlDTO.getUrl())); + Log.sysLog(LOAD_DOCUMENT_HTTPERROR.formatted(crawler.getSendername(), aUrlDTO.getUrl())); Log.errorLog(96459855, crawler.getSendername() + ": crawlerDocumentLoadError: " + aUrlDTO.getUrl() + ", " + httpStatusError.getStatusCode()); diff --git a/src/main/java/mServer/crawler/sender/base/HtmlDocumentUtils.java b/src/main/java/mServer/crawler/sender/base/HtmlDocumentUtils.java index 565d2df44..a4db95832 100644 --- a/src/main/java/mServer/crawler/sender/base/HtmlDocumentUtils.java +++ b/src/main/java/mServer/crawler/sender/base/HtmlDocumentUtils.java @@ -75,7 +75,7 @@ public static Optional getElementString(final String aElementSelector1, final Document aDocument) { Optional result = getElementString(aElementSelector1, aDocument); - if (!result.isPresent()) { + if (result.isEmpty()) { result = getElementString(aElementSelector2, aDocument); } diff --git a/src/main/java/mServer/crawler/sender/base/M3U8Dto.java b/src/main/java/mServer/crawler/sender/base/M3U8Dto.java index c68b02755..f4617233c 100644 --- a/src/main/java/mServer/crawler/sender/base/M3U8Dto.java +++ b/src/main/java/mServer/crawler/sender/base/M3U8Dto.java @@ -152,7 +152,7 @@ public int hashCode() { public Optional getNormalizedMeta(String m3u8Resolution) { final Optional resolutionMeta = getMeta(m3u8Resolution); - if (!resolutionMeta.isPresent()) { + if (resolutionMeta.isEmpty()) { return Optional.empty(); } @@ -161,7 +161,7 @@ public Optional getNormalizedMeta(String m3u8Resolution) { if (index == 4) { return resolutionMeta; } - return Optional.of( - String.format("0%sx0%s", metaValue.substring(0, index), metaValue.substring(index + 1))); + return Optional.of( + "0%sx0%s".formatted(metaValue.substring(0, index), metaValue.substring(index + 1))); } } diff --git a/src/main/java/mServer/crawler/sender/base/UrlUtils.java b/src/main/java/mServer/crawler/sender/base/UrlUtils.java index 1de4cb71b..0877660bf 100644 --- a/src/main/java/mServer/crawler/sender/base/UrlUtils.java +++ b/src/main/java/mServer/crawler/sender/base/UrlUtils.java @@ -86,7 +86,7 @@ public static String changeOrAddParameter(final String aUrl, final String aParam if (splittedUrl.length == 2) { final String cleanedParameters = splittedUrl[1] + URL_TO_PARAMETERS_SPLITTERATOR - .replaceAll(String.format(URL_PARAMETER_REPLACEMENT_REGEX_PATTERN, aParameter), "") + .replaceAll(URL_PARAMETER_REPLACEMENT_REGEX_PATTERN.formatted(aParameter), "") .replaceAll(REGEX_ESCAPOR + WRONG_PARAMETER_START, URL_TO_PARAMETERS_SPLITTERATOR); newUrlBuilder.append(URL_TO_PARAMETERS_SPLITTERATOR); @@ -98,7 +98,7 @@ public static String changeOrAddParameter(final String aUrl, final String aParam newUrlBuilder.append(URL_TO_PARAMETERS_SPLITTERATOR); } - newUrlBuilder.append(String.format(PARAMETER_PATTERN, aParameter, aValue)); + newUrlBuilder.append(PARAMETER_PATTERN.formatted(aParameter, aValue)); return newUrlBuilder.toString(); } diff --git a/src/main/java/mServer/crawler/sender/dreisat/DreiSatCrawler.java b/src/main/java/mServer/crawler/sender/dreisat/DreiSatCrawler.java index e1018ffab..0b5eb885f 100644 --- a/src/main/java/mServer/crawler/sender/dreisat/DreiSatCrawler.java +++ b/src/main/java/mServer/crawler/sender/dreisat/DreiSatCrawler.java @@ -72,7 +72,7 @@ private ConcurrentLinkedQueue getExtraDayUrls() { final LocalDateTime local = LocalDateTime.now().minus(i, ChronoUnit.DAYS); final String date = local.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); - final String url = String.format(DreisatConstants.URL_HTML_DAY, date); + final String url = (DreisatConstants.URL_HTML_DAY).formatted(date); urls.add(new CrawlerUrlDTO(url)); } diff --git a/src/main/java/mServer/crawler/sender/dreisat/DreisatDayPageHtmlDeserializer.java b/src/main/java/mServer/crawler/sender/dreisat/DreisatDayPageHtmlDeserializer.java index 6b467dddb..a9dadeeb3 100644 --- a/src/main/java/mServer/crawler/sender/dreisat/DreisatDayPageHtmlDeserializer.java +++ b/src/main/java/mServer/crawler/sender/dreisat/DreisatDayPageHtmlDeserializer.java @@ -36,6 +36,6 @@ public Set deserialize(final Document document) { private Optional buildFilmUrlJsonFromHtmlLink(String attr) { return UrlUtils.getFileName(attr) - .map(s -> String.format(ZdfConstants.URL_FILM_JSON, urlApiBase, s.split("\\.")[0])); + .map(s -> (ZdfConstants.URL_FILM_JSON).formatted(urlApiBase, s.split("\\.")[0])); } } diff --git a/src/main/java/mServer/crawler/sender/dw/parser/DwFilmDetailDeserializer.java b/src/main/java/mServer/crawler/sender/dw/parser/DwFilmDetailDeserializer.java index a86db8db0..1de7f0f48 100644 --- a/src/main/java/mServer/crawler/sender/dw/parser/DwFilmDetailDeserializer.java +++ b/src/main/java/mServer/crawler/sender/dw/parser/DwFilmDetailDeserializer.java @@ -52,16 +52,16 @@ protected boolean isValidVideo( Optional type, Optional title, Optional topic) { - if (!videoId.isPresent()) { + if (videoId.isEmpty()) { LOG.error("Could not find mandatory element videoId"); return false; - } else if (!title.isPresent()) { + } else if (title.isEmpty()) { LOG.error("Could not find mandatory element title for videoId {} ", videoId.get()); return false; - } else if (!topic.isPresent()) { + } else if (topic.isEmpty()) { LOG.error("Could not find mandatory element topic for videoId {} ", videoId.get()); return false; - } else if (!type.isPresent()) { + } else if (type.isEmpty()) { LOG.error("Could not find mandatory element type for videoId {} ", videoId.get()); return false; } else if (!type.get().equalsIgnoreCase("video")) { @@ -75,9 +75,8 @@ protected boolean isValidVideo( .has(ELEMENT_MAINCONTENT_SOURCES)) { LOG.error("Could not find sources for videoId {}", videoId.get()); return false; - } else if (!JsonUtils.getAttributeAsString( - jsonObject.get(ELEMENT_MAINCONTENT).getAsJsonObject(), ELEMENT_MAINCONTENT_LINK) - .isPresent()) { + } else if (JsonUtils.getAttributeAsString( + jsonObject.get(ELEMENT_MAINCONTENT).getAsJsonObject(), ELEMENT_MAINCONTENT_LINK).isEmpty()) { LOG.error("Could not find thisPageUrl for videoId {}", videoId.get()); return false; } diff --git a/src/main/java/mServer/crawler/sender/dw/tasks/DWOverviewTask.java b/src/main/java/mServer/crawler/sender/dw/tasks/DWOverviewTask.java index c216933b6..3faac2c1d 100644 --- a/src/main/java/mServer/crawler/sender/dw/tasks/DWOverviewTask.java +++ b/src/main/java/mServer/crawler/sender/dw/tasks/DWOverviewTask.java @@ -37,7 +37,7 @@ public DWOverviewTask( protected void processRestTarget(final CrawlerUrlDTO aDTO, final WebTarget aTarget) { final Optional> overviewDtoOptional = deserializeOptional(aTarget, OPTIONAL_OVERVIEW_DTO_TYPE_TOKEN); - if (!overviewDtoOptional.isPresent()) { + if (overviewDtoOptional.isEmpty()) { FilmeSuchen.listeSenderLaufen.inc(crawler.getSendername(), RunSender.Count.FEHLER); FilmeSuchen.listeSenderLaufen.inc(crawler.getSendername(), RunSender.Count.FEHLVERSUCHE); return; diff --git a/src/main/java/mServer/crawler/sender/dw/tasks/DwFilmDetailTask.java b/src/main/java/mServer/crawler/sender/dw/tasks/DwFilmDetailTask.java index c091da6dd..b2b3d923f 100644 --- a/src/main/java/mServer/crawler/sender/dw/tasks/DwFilmDetailTask.java +++ b/src/main/java/mServer/crawler/sender/dw/tasks/DwFilmDetailTask.java @@ -46,7 +46,7 @@ protected void processRestTarget(final CrawlerUrlDTO aDTO, final WebTarget aTarg } catch (Exception e) { LOG.error("error processing {} ", aDTO.getUrl(), e); } - if (!filmDetailDtoOptional.isPresent()) { + if (filmDetailDtoOptional.isEmpty()) { FilmeSuchen.listeSenderLaufen.inc(crawler.getSendername(), RunSender.Count.FEHLER); FilmeSuchen.listeSenderLaufen.inc(crawler.getSendername(), RunSender.Count.FEHLVERSUCHE); return; diff --git a/src/main/java/mServer/crawler/sender/funk/ApiUrlBuilder.java b/src/main/java/mServer/crawler/sender/funk/ApiUrlBuilder.java index 143d7f437..30083d8e7 100644 --- a/src/main/java/mServer/crawler/sender/funk/ApiUrlBuilder.java +++ b/src/main/java/mServer/crawler/sender/funk/ApiUrlBuilder.java @@ -34,7 +34,7 @@ public String asString() { final List urlParameter = new ArrayList<>(); urlParameter.add(String.valueOf(apiUrl.get())); urlParameter.addAll(parameters); - return String.format(urlTemplate, urlParameter.toArray()); + return urlTemplate.formatted(urlParameter.toArray()); } else { throw new IllegalStateException("The API base URL is empty!"); } diff --git a/src/main/java/mServer/crawler/sender/funk/json/AbstractFunkElementDeserializer.java b/src/main/java/mServer/crawler/sender/funk/json/AbstractFunkElementDeserializer.java index bbd1ab40d..7b33d3f0b 100644 --- a/src/main/java/mServer/crawler/sender/funk/json/AbstractFunkElementDeserializer.java +++ b/src/main/java/mServer/crawler/sender/funk/json/AbstractFunkElementDeserializer.java @@ -54,7 +54,7 @@ baseElement, TAG_EMBEDDED, getElementListTag())) { .filter(Objects::nonNull) .collect(Collectors.toSet())); } else { - Log.errorLog(178522355, String.format("A Funk list is broken! %s", baseElement)); + Log.errorLog(178522355, "A Funk list is broken! %s".formatted(baseElement)); LOG.fatal("A Funk list is broken! {}", baseElement); } diff --git a/src/main/java/mServer/crawler/sender/funk/json/FunkVideoDeserializer.java b/src/main/java/mServer/crawler/sender/funk/json/FunkVideoDeserializer.java index deab73a27..5b5f7b815 100644 --- a/src/main/java/mServer/crawler/sender/funk/json/FunkVideoDeserializer.java +++ b/src/main/java/mServer/crawler/sender/funk/json/FunkVideoDeserializer.java @@ -42,8 +42,8 @@ protected FilmInfoDto mapToElement(final JsonObject jsonObject) { filmInfo.setTime(LocalDateTime.parse(timeText, DATE_TIME_FORMATTER)); } catch (final DateTimeParseException dateTimeParseException) { LOG.error( - String.format( - "The text \"%s\" couldn't be parsed withe the pattern \"%s\".", + + "The text \"%s\" couldn't be parsed withe the pattern \"%s\".".formatted( timeText, DATE_TIME_FORMAT_PATTERN), dateTimeParseException); } diff --git a/src/main/java/mServer/crawler/sender/funk/json/NexxCloudVideoDetailsDeserializer.java b/src/main/java/mServer/crawler/sender/funk/json/NexxCloudVideoDetailsDeserializer.java index ad0b87a80..fff6ca3ab 100644 --- a/src/main/java/mServer/crawler/sender/funk/json/NexxCloudVideoDetailsDeserializer.java +++ b/src/main/java/mServer/crawler/sender/funk/json/NexxCloudVideoDetailsDeserializer.java @@ -120,14 +120,14 @@ private FilmUrlInfoDto buildFilmUrlInfoDtoAzure( final String id, final NexxResolutionDTO res) { return new FilmUrlInfoDto( - String.format( - VIDEO_FILE_URL_PATTERN, - cdnShieldProgHTTP, - azureLocator, - id, - res.getWidht(), - res.getHeight(), - res.getSize()), + + VIDEO_FILE_URL_PATTERN.formatted( + cdnShieldProgHTTP, + azureLocator, + id, + res.getWidht(), + res.getHeight(), + res.getSize()), res.getWidht(), res.getHeight()); } @@ -148,8 +148,8 @@ private FilmUrlInfoDto buildFilmUrlInfoDto3q( } return new FilmUrlInfoDto( - String.format( - VIDEO_FILE_URL_PATTERN_3Q, cdnShieldProgHTTP, account, prefix, locator, fileId), + + VIDEO_FILE_URL_PATTERN_3Q.formatted(cdnShieldProgHTTP, account, prefix, locator, fileId), width, height); } diff --git a/src/main/java/mServer/crawler/sender/kika/Resolution.java b/src/main/java/mServer/crawler/sender/kika/Resolution.java index f1563c343..4d83fb7cb 100644 --- a/src/main/java/mServer/crawler/sender/kika/Resolution.java +++ b/src/main/java/mServer/crawler/sender/kika/Resolution.java @@ -140,7 +140,7 @@ static Resolution getResoultionByResolutionSize(final int searchedResolutionSize } throw new NoSuchElementException( - String.format("Resolution with ResolutionIndex %d not found", searchedResolutionSize)); + "Resolution with ResolutionIndex %d not found".formatted(searchedResolutionSize)); } public String getDescription() { diff --git a/src/main/java/mServer/crawler/sender/kika/json/KikaApiTopicPageDeserializer.java b/src/main/java/mServer/crawler/sender/kika/json/KikaApiTopicPageDeserializer.java index 0eab95d85..fc04d935a 100644 --- a/src/main/java/mServer/crawler/sender/kika/json/KikaApiTopicPageDeserializer.java +++ b/src/main/java/mServer/crawler/sender/kika/json/KikaApiTopicPageDeserializer.java @@ -86,7 +86,7 @@ protected Optional parseFilm(final JsonElement arrayElement) { // if (oId.isPresent()) { aFilm = Optional.of(new KikaApiFilmDto( - String.format(KikaApiConstants.FILM, oId.get()), + (KikaApiConstants.FILM).formatted(oId.get()), oTopic, oTitle, oId, diff --git a/src/main/java/mServer/crawler/sender/kika/tasks/KikaApiFilmTask.java b/src/main/java/mServer/crawler/sender/kika/tasks/KikaApiFilmTask.java index 033089973..f90d12d9b 100644 --- a/src/main/java/mServer/crawler/sender/kika/tasks/KikaApiFilmTask.java +++ b/src/main/java/mServer/crawler/sender/kika/tasks/KikaApiFilmTask.java @@ -64,7 +64,7 @@ protected void handleHttpError(KikaApiFilmDto dto, URI url, Response response) { "A HTTP error {} occurred when getting REST information from: \"{}\".", response.getStatus(), url); - Log.errorLog(324978334, String.format("A HTTP error %d occurred when getting REST information from: \"%s\".", + Log.errorLog(324978334, "A HTTP error %d occurred when getting REST information from: \"%s\".".formatted( response.getStatus(), url)); } @@ -76,7 +76,7 @@ protected void postProcessing(KikaApiVideoInfoDto aResponseObj, KikaApiFilmDto a // if (aResponseObj.getErrorCode().isPresent()) { LOG.error("Error {} : {} for target {} ", aResponseObj.getErrorCode().get(), aResponseObj.getErrorMesssage().orElse(""), aDTO.getUrl()); - Log.errorLog(324978335, String.format("Error %s} : %s for target %s ", aResponseObj.getErrorCode().get(), aResponseObj.getErrorMesssage().orElse(""), aDTO.getUrl())); + Log.errorLog(324978335, "Error %s} : %s for target %s ".formatted(aResponseObj.getErrorCode().get(), aResponseObj.getErrorMesssage().orElse(""), aDTO.getUrl())); return; } // @@ -86,14 +86,14 @@ protected void postProcessing(KikaApiVideoInfoDto aResponseObj, KikaApiFilmDto a } // final Optional airedDate = getAiredDateTime(aDTO); - if (!aDTO.getTitle().isPresent() || !aDTO.getTopic().isPresent() || !airedDate.isPresent() || !aDTO.getDuration().isPresent()) { - if (!aDTO.getTitle().isPresent()) { + if (aDTO.getTitle().isEmpty() || aDTO.getTopic().isEmpty() || airedDate.isEmpty() || aDTO.getDuration().isEmpty()) { + if (aDTO.getTitle().isEmpty()) { LOG.error("Missing title for {}", aDTO.getUrl()); - } else if (!aDTO.getTopic().isPresent()) { + } else if (aDTO.getTopic().isEmpty()) { LOG.error("Missing topic for {}", aDTO.getUrl()); - } else if (!airedDate.isPresent()) { + } else if (airedDate.isEmpty()) { LOG.error("Missing date for {}", aDTO.getUrl()); - } else if (!aDTO.getDuration().isPresent()) { + } else if (aDTO.getDuration().isEmpty()) { LOG.error("Missing duration for {}", aDTO.getUrl()); } return; diff --git a/src/main/java/mServer/crawler/sender/kika/tasks/KikaApiTopicTask.java b/src/main/java/mServer/crawler/sender/kika/tasks/KikaApiTopicTask.java index f08263da1..ca64799d2 100644 --- a/src/main/java/mServer/crawler/sender/kika/tasks/KikaApiTopicTask.java +++ b/src/main/java/mServer/crawler/sender/kika/tasks/KikaApiTopicTask.java @@ -50,7 +50,7 @@ protected void postProcessing(KikaApiTopicDto aResponseObj, TopicUrlDTO aDTO) { // aResponseObj.getErrorCode().ifPresent(errorCode -> { LOG.error("Error {} : {} for target {} ", errorCode, aResponseObj.getErrorMesssage().orElse(""), aDTO.getUrl()); - Log.errorLog(324978332, String.format("Error %s : %s for target %s ", errorCode, aResponseObj.getErrorMesssage().orElse(""), aDTO.getUrl())); + Log.errorLog(324978332, "Error %s : %s for target %s ".formatted(errorCode, aResponseObj.getErrorMesssage().orElse(""), aDTO.getUrl())); return; }); // @@ -66,7 +66,7 @@ protected void postProcessing(KikaApiTopicDto aResponseObj, TopicUrlDTO aDTO) { subpageCrawler = Optional.empty(); } for (KikaApiFilmDto aFilm : aResponseObj.getElements()) { - if (!aFilm.getTopic().isPresent()) { + if (aFilm.getTopic().isEmpty()) { aFilm.setTopic(Optional.of(aDTO.getTopic())); } taskResults.add(aFilm); @@ -81,7 +81,7 @@ protected void handleHttpError(TopicUrlDTO dto, URI url, Response response) { "A HTTP error {} occurred when getting REST information from: \"{}\".", response.getStatus(), url); - Log.errorLog(324978333, String.format("A HTTP error %d occurred when getting REST information from: \"%s}\".", + Log.errorLog(324978333, "A HTTP error %d occurred when getting REST information from: \"%s}\".".formatted( response.getStatus(), url)); } diff --git a/src/main/java/mServer/crawler/sender/orf/tasks/OrfDayTask.java b/src/main/java/mServer/crawler/sender/orf/tasks/OrfDayTask.java index 67fb3ded4..655805501 100644 --- a/src/main/java/mServer/crawler/sender/orf/tasks/OrfDayTask.java +++ b/src/main/java/mServer/crawler/sender/orf/tasks/OrfDayTask.java @@ -36,7 +36,7 @@ protected void processDocument(CrawlerUrlDTO aUrlDTO, Document aDocument) { } }); - ORF_LOGGER.trace(String.format("%s: Anzahl Filme: %d", aUrlDTO.getUrl(), taskResults.size())); + ORF_LOGGER.trace("%s: Anzahl Filme: %d".formatted(aUrlDTO.getUrl(), taskResults.size())); } private Element getTitleElement(Element item) { diff --git a/src/main/java/mServer/crawler/sender/orf/tasks/OrfFilmDetailTask.java b/src/main/java/mServer/crawler/sender/orf/tasks/OrfFilmDetailTask.java index 9cc8a858c..10c1cf4be 100644 --- a/src/main/java/mServer/crawler/sender/orf/tasks/OrfFilmDetailTask.java +++ b/src/main/java/mServer/crawler/sender/orf/tasks/OrfFilmDetailTask.java @@ -76,7 +76,7 @@ protected void processDocument(TopicUrlDTO aUrlDTO, Document aDocument) { } } - ORF_LOGGER.trace(String.format("%s - %s: Anzahl Filme: %d", aUrlDTO.getTopic(), aUrlDTO.getUrl(), taskResults.size())); + ORF_LOGGER.trace("%s - %s: Anzahl Filme: %d".formatted(aUrlDTO.getTopic(), aUrlDTO.getUrl(), taskResults.size())); } @Override @@ -172,12 +172,12 @@ private static Optional parseDate(Document aDocument) { private static Optional parseDuration(Document aDocument) { Optional duration = HtmlDocumentUtils.getElementString(DURATION_SELECTOR, aDocument); - if (!duration.isPresent()) { + if (duration.isEmpty()) { return Optional.empty(); } Optional unit = determineChronoUnit(duration.get()); - if (!unit.isPresent()) { + if (unit.isEmpty()) { Log.sysLog("OrfFilmDetailTask: unknown duration type: " + duration.get()); return Optional.empty(); } diff --git a/src/main/java/mServer/crawler/sender/orf/tasks/OrfTaskBase.java b/src/main/java/mServer/crawler/sender/orf/tasks/OrfTaskBase.java index 3ac1b8928..bafadbe9b 100644 --- a/src/main/java/mServer/crawler/sender/orf/tasks/OrfTaskBase.java +++ b/src/main/java/mServer/crawler/sender/orf/tasks/OrfTaskBase.java @@ -64,7 +64,7 @@ protected void processElement(final D aUrlDTO) { FilmeSuchen.listeSenderLaufen.inc(crawler.getSendername(), RunSender.Count.FEHLER); FilmeSuchen.listeSenderLaufen.inc(crawler.getSendername(), RunSender.Count.FEHLVERSUCHE); ORF_LOGGER.trace(httpStatusError); - Log.sysLog(String.format(LOAD_DOCUMENT_HTTPERROR, crawler.getSendername(), aUrlDTO.getUrl())); + Log.sysLog(LOAD_DOCUMENT_HTTPERROR.formatted(crawler.getSendername(), aUrlDTO.getUrl())); Log.errorLog(96459855, crawler.getSendername() + ": crawlerDocumentLoadError: " + aUrlDTO.getUrl() + ", " + httpStatusError.getStatusCode()); @@ -97,13 +97,13 @@ private Document loadDocument(final D aUrlDTO, int timeout) throws IOException { long end = System.currentTimeMillis(); - ORF_LOGGER.trace(String.format("%s: %d - loaded in %d ms", aUrlDTO.getUrl(), response.statusCode(), end - start)); + ORF_LOGGER.trace("%s: %d - loaded in %d ms".formatted(aUrlDTO.getUrl(), response.statusCode(), end - start)); traceRequest(); final Document document = response.parse(); end = System.currentTimeMillis(); - ORF_LOGGER.trace(String.format("%s: %d - parsed in %d ms", aUrlDTO.getUrl(), response.statusCode(), end - start)); + ORF_LOGGER.trace("%s: %d - parsed in %d ms".formatted(aUrlDTO.getUrl(), response.statusCode(), end - start)); return document; } diff --git a/src/main/java/mServer/crawler/sender/phoenix/parser/PhoenixFilmDetailDeserializer.java b/src/main/java/mServer/crawler/sender/phoenix/parser/PhoenixFilmDetailDeserializer.java index 8bc3a3b5f..7c186eee9 100644 --- a/src/main/java/mServer/crawler/sender/phoenix/parser/PhoenixFilmDetailDeserializer.java +++ b/src/main/java/mServer/crawler/sender/phoenix/parser/PhoenixFilmDetailDeserializer.java @@ -35,7 +35,7 @@ public Optional deserialize(JsonElement aJsonElement, Type final Optional baseName = parseBaseName(jsonObject); final Optional website = parseWebsite(jsonObject); - if (!title.isPresent() || !subtitle.isPresent() || !baseName.isPresent()) { + if (title.isEmpty() || subtitle.isEmpty() || baseName.isEmpty()) { return Optional.empty(); } @@ -53,19 +53,19 @@ public Optional deserialize(JsonElement aJsonElement, Type private String determineTitle(Optional title, Optional subtitle, Optional verortung) { - if (!verortung.isPresent() || verortung.get().equalsIgnoreCase(title.get())) { + if (verortung.isEmpty() || verortung.get().equalsIgnoreCase(title.get())) { return subtitle.get(); } - if (!subtitle.isPresent() || subtitle.get().isEmpty()) { + if (subtitle.isEmpty() || subtitle.get().isEmpty()) { return title.get(); } - return String.format("%s - %s", title.get(), subtitle.get()); + return "%s - %s".formatted(title.get(), subtitle.get()); } private String determineTopic(Optional title, Optional verortung) { - if (!verortung.isPresent()) { + if (verortung.isEmpty()) { return title.get(); } return verortung.get(); diff --git a/src/main/java/mServer/crawler/sender/phoenix/tasks/PhoenixFilmDetailTask.java b/src/main/java/mServer/crawler/sender/phoenix/tasks/PhoenixFilmDetailTask.java index 0de6a7e1e..1eb853220 100644 --- a/src/main/java/mServer/crawler/sender/phoenix/tasks/PhoenixFilmDetailTask.java +++ b/src/main/java/mServer/crawler/sender/phoenix/tasks/PhoenixFilmDetailTask.java @@ -42,7 +42,7 @@ protected AbstractRecursivConverterTask createNewOwnIn @Override protected void processRestTarget(CrawlerUrlDTO aDTO, WebTarget aTarget) { Optional filmDetailDtoOptional = deserializeOptional(aTarget, OPTIONAL_FILM_DETAIL_DTO_TYPE_TOKEN); - if (!filmDetailDtoOptional.isPresent()) { + if (filmDetailDtoOptional.isEmpty()) { // tritt auf, wenn kein Film vorhanden return; } @@ -51,8 +51,8 @@ protected void processRestTarget(CrawlerUrlDTO aDTO, WebTarget aTarget) { ConcurrentLinkedQueue shows = new ConcurrentLinkedQueue<>(); shows.add( new CrawlerUrlDTO( - String.format( - PhoenixConstants.URL_VIDEO_DETAILS, + ( + PhoenixConstants.URL_VIDEO_DETAILS).formatted( this.filmDetailHost, filmDetailDto.getBaseName()))); final ZdfFilmDetailTask zdfFilmDetailTask = diff --git a/src/main/java/mServer/crawler/sender/phoenix/tasks/PhoenixOverviewTask.java b/src/main/java/mServer/crawler/sender/phoenix/tasks/PhoenixOverviewTask.java index de02b71bc..ca85dda7d 100644 --- a/src/main/java/mServer/crawler/sender/phoenix/tasks/PhoenixOverviewTask.java +++ b/src/main/java/mServer/crawler/sender/phoenix/tasks/PhoenixOverviewTask.java @@ -46,7 +46,7 @@ public PhoenixOverviewTask(MediathekReader aCrawler, protected void processRestTarget(CrawlerUrlDTO aDTO, WebTarget aTarget) { try { Optional overviewDtoOptional = deserializeOptional(aTarget, OPTIONAL_OVERVIEW_DTO_TYPE_TOKEN); - if (!overviewDtoOptional.isPresent()) { + if (overviewDtoOptional.isEmpty()) { LOG.fatal("PhoenixOverviewTask: error processing url {}", aDTO.getUrl()); return; } diff --git a/src/main/java/mServer/crawler/sender/sr/tasks/SrTopicsOverviewPageTask.java b/src/main/java/mServer/crawler/sender/sr/tasks/SrTopicsOverviewPageTask.java index 665932217..145442c43 100644 --- a/src/main/java/mServer/crawler/sender/sr/tasks/SrTopicsOverviewPageTask.java +++ b/src/main/java/mServer/crawler/sender/sr/tasks/SrTopicsOverviewPageTask.java @@ -33,7 +33,7 @@ public class SrTopicsOverviewPageTask implements Callable caption = UrlUtils.getUrlParameterValue(videoUrl, "caption"); if (subtitleBaseUrl.isPresent() && caption.isPresent()) { - String subtitleUrl = String.format( - "%s/%s", - subtitleBaseUrl.get(), - convertVideoCaptionToSubtitleFile(caption.get())); + String subtitleUrl = + "%s/%s".formatted( + subtitleBaseUrl.get(), + convertVideoCaptionToSubtitleFile(caption.get())); return UrlUtils.addProtocolIfMissing(subtitleUrl, UrlUtils.PROTOCOL_HTTPS); } @@ -155,7 +155,7 @@ private static String parseResourceList(JsonElement aResourceListElement) { private static Optional getResolution(M3U8Dto aDto) { Optional resolution = aDto.getResolution(); - if (!resolution.isPresent()) { + if (resolution.isEmpty()) { Optional codecMeta = aDto.getMeta(M3U8Constants.M3U8_CODECS); // Codec muss "avcl" beinhalten, sonst ist es kein Video @@ -307,7 +307,7 @@ private Map readUrls(String aM3U8Url) { final String optimizedUrl = UrlUtils.removeParameters(getOptimizedUrl(aM3U8Url)); Optional content = loadM3u8(optimizedUrl); - if (!content.isPresent()) { + if (content.isEmpty()) { content = loadM3u8(aM3U8Url); } @@ -333,7 +333,7 @@ private Map readUrls(String aM3U8Url) { private String enrichUrl(String m3u8Url, String videoUrl) { // some video urls contain only filename - if (!UrlUtils.getProtocol(videoUrl).isPresent()) { + if (UrlUtils.getProtocol(videoUrl).isEmpty()) { final String m3u8WithoutParameters = UrlUtils.removeParameters(m3u8Url); final Optional m3u8File = UrlUtils.getFileName(m3u8WithoutParameters); if (m3u8File.isPresent()) { diff --git a/src/main/java/mServer/crawler/sender/srf/parser/SrfTopicDeserializer.java b/src/main/java/mServer/crawler/sender/srf/parser/SrfTopicDeserializer.java index 3a4c0a027..30d06d6c9 100644 --- a/src/main/java/mServer/crawler/sender/srf/parser/SrfTopicDeserializer.java +++ b/src/main/java/mServer/crawler/sender/srf/parser/SrfTopicDeserializer.java @@ -47,7 +47,7 @@ public PagedElementListDTO deserialize( id.ifPresent( s -> results.addElement( - new CrawlerUrlDTO(String.format(SrfConstants.SHOW_DETAIL_PAGE_URL, s)))); + new CrawlerUrlDTO((SrfConstants.SHOW_DETAIL_PAGE_URL).formatted(s)))); }); return results; diff --git a/src/main/java/mServer/crawler/sender/srf/parser/SrfTopicsDeserializer.java b/src/main/java/mServer/crawler/sender/srf/parser/SrfTopicsDeserializer.java index 12773d7dc..b4e3afdad 100644 --- a/src/main/java/mServer/crawler/sender/srf/parser/SrfTopicsDeserializer.java +++ b/src/main/java/mServer/crawler/sender/srf/parser/SrfTopicsDeserializer.java @@ -37,7 +37,7 @@ public Set deserialize( id.ifPresent( s -> results.add( - new TopicUrlDTO(s, String.format(SrfConstants.SHOW_OVERVIEW_PAGE_URL, SrfConstants.BASE_URL, s)))); + new TopicUrlDTO(s, (SrfConstants.SHOW_OVERVIEW_PAGE_URL).formatted(SrfConstants.BASE_URL, s)))); }); return results; diff --git a/src/main/java/mServer/crawler/sender/srf/tasks/SrfTopicOverviewTask.java b/src/main/java/mServer/crawler/sender/srf/tasks/SrfTopicOverviewTask.java index ef65ffd82..ebfd54281 100644 --- a/src/main/java/mServer/crawler/sender/srf/tasks/SrfTopicOverviewTask.java +++ b/src/main/java/mServer/crawler/sender/srf/tasks/SrfTopicOverviewTask.java @@ -72,7 +72,7 @@ private void processNextPage(final String aTopic, final String aNextPageId) { urlDtos.add( new TopicUrlDTO( aTopic, - String.format(SrfConstants.SHOW_OVERVIEW_NEXT_PAGE_URL, baseUrl, aTopic, aNextPageId))); + (SrfConstants.SHOW_OVERVIEW_NEXT_PAGE_URL).formatted(baseUrl, aTopic, aNextPageId))); Set results = createNewOwnInstance(urlDtos, pageNumber + 1).invoke(); taskResults.addAll(results); } diff --git a/src/main/java/mServer/crawler/sender/srf/tasks/SrfTopicsOverviewTask.java b/src/main/java/mServer/crawler/sender/srf/tasks/SrfTopicsOverviewTask.java index 028c015b4..0f9d237cf 100644 --- a/src/main/java/mServer/crawler/sender/srf/tasks/SrfTopicsOverviewTask.java +++ b/src/main/java/mServer/crawler/sender/srf/tasks/SrfTopicsOverviewTask.java @@ -45,8 +45,8 @@ private Set addSpecialShows() { shows.add( new TopicUrlDTO( SrfConstants.ID_SHOW_SPORT_CLIP, - String.format( - SrfConstants.SHOW_OVERVIEW_PAGE_URL, + ( + SrfConstants.SHOW_OVERVIEW_PAGE_URL).formatted( SrfConstants.BASE_URL, SrfConstants.ID_SHOW_SPORT_CLIP))); diff --git a/src/main/java/mServer/crawler/sender/zdf/AbstractZdfCrawler.java b/src/main/java/mServer/crawler/sender/zdf/AbstractZdfCrawler.java index b73a5be97..8e876a4c2 100644 --- a/src/main/java/mServer/crawler/sender/zdf/AbstractZdfCrawler.java +++ b/src/main/java/mServer/crawler/sender/zdf/AbstractZdfCrawler.java @@ -112,7 +112,7 @@ private ConcurrentLinkedQueue getDayUrls() { .plus(daysFuture, ChronoUnit.DAYS) .minus(i, ChronoUnit.DAYS); final String date = local.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); - final String url = String.format(getUrlDay(), date, date); + final String url = getUrlDay().formatted(date, date); urls.add(new CrawlerUrlDTO(url)); } diff --git a/src/main/java/mServer/crawler/sender/zdf/ZdfCrawler.java b/src/main/java/mServer/crawler/sender/zdf/ZdfCrawler.java index c4f278ec5..c03261f86 100644 --- a/src/main/java/mServer/crawler/sender/zdf/ZdfCrawler.java +++ b/src/main/java/mServer/crawler/sender/zdf/ZdfCrawler.java @@ -93,7 +93,7 @@ private ConcurrentLinkedQueue getExtraDayUrls() { final LocalDateTime local = LocalDateTime.now().minus(i, ChronoUnit.DAYS); final String date = local.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); - final String url = String.format(ZdfConstants.URL_HTML_DAY, date); + final String url = (ZdfConstants.URL_HTML_DAY).formatted(date); urls.add(new CrawlerUrlDTO(url)); } diff --git a/src/main/java/mServer/crawler/sender/zdf/ZdfVideoUrlOptimizer.java b/src/main/java/mServer/crawler/sender/zdf/ZdfVideoUrlOptimizer.java index a0a132a09..153614d02 100644 --- a/src/main/java/mServer/crawler/sender/zdf/ZdfVideoUrlOptimizer.java +++ b/src/main/java/mServer/crawler/sender/zdf/ZdfVideoUrlOptimizer.java @@ -118,7 +118,7 @@ public Optional determineUrlHd(final String aNormalUrl) { private String optimize(final String aUrl, Map aOptimizerMap) { final Optional fileNameOptional = UrlUtils.getFileName(aUrl); - if (!fileNameOptional.isPresent()) { + if (fileNameOptional.isEmpty()) { return aUrl; } diff --git a/src/main/java/mServer/crawler/sender/zdf/json/ZdfDownloadDtoDeserializer.java b/src/main/java/mServer/crawler/sender/zdf/json/ZdfDownloadDtoDeserializer.java index 102180486..346214ab3 100644 --- a/src/main/java/mServer/crawler/sender/zdf/json/ZdfDownloadDtoDeserializer.java +++ b/src/main/java/mServer/crawler/sender/zdf/json/ZdfDownloadDtoDeserializer.java @@ -179,7 +179,7 @@ private void parseSubtitle(final DownloadDto dto, final JsonObject rootNode) { // prefer xml subtitles if (uriValue.endsWith(RELEVANT_SUBTITLE_TYPE) - || !dto.getSubTitleUrl(language).isPresent()) { + || dto.getSubTitleUrl(language).isEmpty()) { dto.addSubTitleUrl(language, uriValue); } } diff --git a/src/main/java/mServer/crawler/sender/zdf/parser/ZdfDayPageHtmlDeserializer.java b/src/main/java/mServer/crawler/sender/zdf/parser/ZdfDayPageHtmlDeserializer.java index 882ce31e3..92e13bdc5 100644 --- a/src/main/java/mServer/crawler/sender/zdf/parser/ZdfDayPageHtmlDeserializer.java +++ b/src/main/java/mServer/crawler/sender/zdf/parser/ZdfDayPageHtmlDeserializer.java @@ -35,6 +35,6 @@ public Set deserialize(final Document document) { private Optional buildFilmUrlJsonFromHtmlLink(String attr) { return UrlUtils.getFileName(attr) - .map(s -> String.format(ZdfConstants.URL_FILM_JSON, urlApiBase, s.split("\\.")[0])); + .map(s -> (ZdfConstants.URL_FILM_JSON).formatted(urlApiBase, s.split("\\.")[0])); } } diff --git a/src/main/java/mServer/crawler/sender/zdf/parser/ZdfTopicPageHtmlDeserializer.java b/src/main/java/mServer/crawler/sender/zdf/parser/ZdfTopicPageHtmlDeserializer.java index 8b99ada88..81d873876 100644 --- a/src/main/java/mServer/crawler/sender/zdf/parser/ZdfTopicPageHtmlDeserializer.java +++ b/src/main/java/mServer/crawler/sender/zdf/parser/ZdfTopicPageHtmlDeserializer.java @@ -88,7 +88,7 @@ public Set deserialize(final Document document) { mainVideo -> { final String id = mainVideo.attr("data-zdfplayer-id"); if (id != null) { - final String url = String.format(ZdfConstants.URL_FILM_JSON, urlApiBase, id); + final String url = (ZdfConstants.URL_FILM_JSON).formatted(urlApiBase, id); results.add(new CrawlerUrlDTO(url)); } }); @@ -135,7 +135,7 @@ private void parseHeadline(Set results, Element headline) { s -> results.add( new CrawlerUrlDTO( - String.format(ZdfConstants.URL_FILM_JSON, urlApiBase, s)))); + (ZdfConstants.URL_FILM_JSON).formatted(urlApiBase, s)))); } catch (UrlParseException e) { LOG.error(e); } @@ -144,6 +144,6 @@ private void parseHeadline(Set results, Element headline) { private Optional buildFilmUrlJsonFromHtmlLink(String attr) { return UrlUtils.getFileName(attr) - .map(s -> String.format(ZdfConstants.URL_FILM_JSON, urlApiBase, s.split("\\.")[0])); + .map(s -> (ZdfConstants.URL_FILM_JSON).formatted(urlApiBase, s.split("\\.")[0])); } } diff --git a/src/main/java/mServer/crawler/sender/zdf/tasks/ZdfIndexPageTask.java b/src/main/java/mServer/crawler/sender/zdf/tasks/ZdfIndexPageTask.java index 663f8e32b..7de204ce2 100644 --- a/src/main/java/mServer/crawler/sender/zdf/tasks/ZdfIndexPageTask.java +++ b/src/main/java/mServer/crawler/sender/zdf/tasks/ZdfIndexPageTask.java @@ -56,9 +56,9 @@ public ZdfConfiguration call() { Optional videoBearer = parseBearerIndexPage(document.get(), QUERY_VIDEO_BEARER_INDEX_PAGE, "\""); - if (!videoBearer.isPresent()) { + if (videoBearer.isEmpty()) { videoBearer = parseBearerIndexPage(document.get(), QUERY_VIDEO_BEARER_INDEX_PAGE2, "\""); - if (!videoBearer.isPresent()) { + if (videoBearer.isEmpty()) { videoBearer = parseTokenFromSubPage(document.get()); } } diff --git a/src/main/java/mServer/tool/M3U8Utils.java b/src/main/java/mServer/tool/M3U8Utils.java index 2fd855fab..b09528cbe 100644 --- a/src/main/java/mServer/tool/M3U8Utils.java +++ b/src/main/java/mServer/tool/M3U8Utils.java @@ -79,21 +79,21 @@ public static Map gatherUrlsFromWdrM3U8(String aWDRM3U8Url) { List urlQualityParts = Arrays.asList(StringUtils.split(urlQualityPartsText, ',')); if (urlQualityParts.size() == 1) { urlAndQualities.put(Qualities.SMALL, - String.format(WDR_MP4_URL_PATTERN, region, fsk, unkownNumber, videoId, urlQualityParts.get(0))); + WDR_MP4_URL_PATTERN.formatted(region, fsk, unkownNumber, videoId, urlQualityParts.get(0))); } else if (urlQualityParts.size() == 2) { urlAndQualities.put(Qualities.SMALL, - String.format(WDR_MP4_URL_PATTERN, region, fsk, unkownNumber, videoId, urlQualityParts.get(0))); + WDR_MP4_URL_PATTERN.formatted(region, fsk, unkownNumber, videoId, urlQualityParts.get(0))); urlAndQualities.put(Qualities.NORMAL, - String.format(WDR_MP4_URL_PATTERN, region, fsk, unkownNumber, videoId, urlQualityParts.get(1))); + WDR_MP4_URL_PATTERN.formatted(region, fsk, unkownNumber, videoId, urlQualityParts.get(1))); } else if (urlQualityParts.size() >= 3) { List bestThreeUrlQualityParts = urlQualityParts.subList(urlQualityParts.size() - 3, urlQualityParts.size()); - urlAndQualities.put(Qualities.SMALL, String.format(WDR_MP4_URL_PATTERN, region, fsk, unkownNumber, videoId, - bestThreeUrlQualityParts.get(0))); - urlAndQualities.put(Qualities.NORMAL, String.format(WDR_MP4_URL_PATTERN, region, fsk, unkownNumber, videoId, - bestThreeUrlQualityParts.get(1))); - urlAndQualities.put(Qualities.HD, String.format(WDR_MP4_URL_PATTERN, region, fsk, unkownNumber, videoId, - bestThreeUrlQualityParts.get(2))); + urlAndQualities.put(Qualities.SMALL, WDR_MP4_URL_PATTERN.formatted(region, fsk, unkownNumber, videoId, + bestThreeUrlQualityParts.get(0))); + urlAndQualities.put(Qualities.NORMAL, WDR_MP4_URL_PATTERN.formatted(region, fsk, unkownNumber, videoId, + bestThreeUrlQualityParts.get(1))); + urlAndQualities.put(Qualities.HD, WDR_MP4_URL_PATTERN.formatted(region, fsk, unkownNumber, videoId, + bestThreeUrlQualityParts.get(2))); } return urlAndQualities; } diff --git a/src/main/java/mServer/tool/MserverDatumZeit.java b/src/main/java/mServer/tool/MserverDatumZeit.java index 104f0a81a..586709943 100644 --- a/src/main/java/mServer/tool/MserverDatumZeit.java +++ b/src/main/java/mServer/tool/MserverDatumZeit.java @@ -83,7 +83,7 @@ public static String formatDate(String dateValue, FastDateFormat sdf) { try { return FDF_OUT_DAY.format(sdf.parse(dateValue)); } catch (ParseException ex) { - LOG.debug(String.format("Fehler beim Parsen des Datums %s: %s", dateValue, ex.getMessage())); + LOG.debug("Fehler beim Parsen des Datums %s: %s".formatted(dateValue, ex.getMessage())); } return ""; @@ -99,7 +99,7 @@ public static String formatTime(String dateValue, FastDateFormat sdf) { try { return FDF_OUT_TIME.format(sdf.parse(dateValue)); } catch (ParseException ex) { - LOG.debug(String.format("Fehler beim Parsen des Datums %s: %s", dateValue, ex.getMessage())); + LOG.debug("Fehler beim Parsen des Datums %s: %s".formatted(dateValue, ex.getMessage())); } return "";