From a896ec41b9a44074684a8ffacd005b35223d30cf Mon Sep 17 00:00:00 2001 From: TobiGr Date: Thu, 31 Dec 2020 16:58:40 +0100 Subject: [PATCH] [media.ccc.de] Use Pattern for getting the ive stream id --- .../extractors/MediaCCCParsingHelper.java | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCParsingHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCParsingHelper.java index 7ea3e20ce..a3aec1dd9 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCParsingHelper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCParsingHelper.java @@ -1,7 +1,6 @@ package org.schabi.newpipe.extractor.services.media_ccc.extractors; import com.grack.nanojson.JsonArray; -import com.grack.nanojson.JsonObject; import com.grack.nanojson.JsonParser; import com.grack.nanojson.JsonParserException; import org.schabi.newpipe.extractor.downloader.Downloader; @@ -13,9 +12,11 @@ import org.schabi.newpipe.extractor.localization.Localization; import java.io.IOException; import java.time.OffsetDateTime; import java.time.format.DateTimeParseException; +import java.util.Locale; import java.util.regex.Pattern; public final class MediaCCCParsingHelper { + private static final Pattern LIVE_STREAM_ID_PATTERN = Pattern.compile("\\w+/\\w+"); // {conference_slug}/{room_slug} private static JsonArray liveStreams = null; private MediaCCCParsingHelper() { } @@ -28,12 +29,28 @@ public final class MediaCCCParsingHelper { } } + /** + * Check whether an id is a live stream id + * @param id the {@code id} to check + * @return returns {@code true} if the {@code id} is formatted like {@code {conference_slug}/{room_slug}}; + * {@code false} otherwise + */ public static boolean isLiveStreamId(final String id) { - final String pattern = "\\w+/\\w+"; - return Pattern.matches(pattern, id); // {conference_slug}/{room_slug} + return LIVE_STREAM_ID_PATTERN.matcher(id).find(); } - public static JsonArray getLiveStreams(final Downloader downloader, final Localization localization) throws ExtractionException { + /** + * Get currently available live streams from + * https://streaming.media.ccc.de/streams/v2.json. + * Use this method to cache requests, because they can get quite big. + * TODO: implement better caching policy (max-age: 3 min) + * @param downloader The downloader to use for making the request + * @param localization The localization to be used. Will most likely be ignored. + * @return {@link JsonArray} containing current conferences and info about their rooms and streams. + * @throws ExtractionException if the data could not be fetched or the retrieved data could not be parsed to a {@link JsonArray} + */ + public static JsonArray getLiveStreams(final Downloader downloader, final Localization localization) + throws ExtractionException { if (liveStreams == null) { try { final String site = downloader.get("https://streaming.media.ccc.de/streams/v2.json",