diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java b/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java index cc9df054..358e03c9 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java @@ -1,5 +1,7 @@ package org.schabi.newpipe.extractor.kiosk; +import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; + import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.Page; import org.schabi.newpipe.extractor.StreamingService; @@ -8,13 +10,12 @@ import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory; import org.schabi.newpipe.extractor.localization.ContentCountry; import org.schabi.newpipe.extractor.localization.Localization; -import javax.annotation.Nullable; import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Set; -import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; +import javax.annotation.Nullable; public class KioskList { @@ -78,10 +79,10 @@ public class KioskList { if (!isNullOrEmpty(defaultKiosk)) { return getExtractorById(defaultKiosk, nextPage, localization); } else { - if (!kioskList.isEmpty()) { + final String first = kioskList.keySet().stream().findAny().orElse(null); + if (first != null) { // if not set get any entry - final Object[] keySet = kioskList.keySet().toArray(); - return getExtractorById(keySet[0].toString(), nextPage, localization); + return getExtractorById(first, nextPage, localization); } else { return null; } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Parser.java b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Parser.java index 3654061f..64707cd3 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Parser.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Parser.java @@ -20,23 +20,18 @@ package org.schabi.newpipe.extractor.utils; -import org.nibor.autolink.LinkExtractor; -import org.nibor.autolink.LinkSpan; -import org.nibor.autolink.LinkType; +import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; + import org.schabi.newpipe.extractor.exceptions.ParsingException; -import javax.annotation.Nonnull; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; -import java.util.ArrayList; -import java.util.EnumSet; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; -import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; +import javax.annotation.Nonnull; /** * Avoid using regex !!! @@ -111,24 +106,4 @@ public final class Parser { } return map; } - - @Nonnull - public static String[] getLinksFromString(final String txt) throws ParsingException { - try { - final List links = new ArrayList<>(); - final LinkExtractor linkExtractor = LinkExtractor.builder() - .linkTypes(EnumSet.of(LinkType.URL, LinkType.WWW)) - .build(); - final Iterable linkSpans = linkExtractor.extractLinks(txt); - for (final LinkSpan ls : linkSpans) { - links.add(txt.substring(ls.getBeginIndex(), ls.getEndIndex())); - } - - String[] linksarray = new String[links.size()]; - linksarray = links.toArray(linksarray); - return linksarray; - } catch (final Exception e) { - throw new ParsingException("Could not get links from string", e); - } - } }