From 9e53cf0b56652c37e68d3c5a03624f0b6d8fff05 Mon Sep 17 00:00:00 2001 From: Stypox Date: Sun, 28 Jun 2020 22:44:16 +0200 Subject: [PATCH] Fix parameter reassignment and other style issues Also remove left-behind debug statement --- .../org/schabi/newpipe/extractor/StreamingService.java | 10 +++++----- .../extractor/linkhandler/LinkHandlerFactory.java | 9 ++++----- .../extractor/linkhandler/ListLinkHandlerFactory.java | 8 ++++---- .../java/org/schabi/newpipe/extractor/utils/Utils.java | 8 ++++---- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java b/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java index 3d09d5094..dcde0aff6 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java @@ -279,18 +279,18 @@ public abstract class StreamingService { * @param url the url on which it should be decided of which link type it is * @return the link type of url */ - public final LinkType getLinkTypeByUrl(String url) throws ParsingException { - url = Utils.followGoogleRedirectIfNeeded(url); + public final LinkType getLinkTypeByUrl(final String url) throws ParsingException { + final String polishedUrl = Utils.followGoogleRedirectIfNeeded(url); final LinkHandlerFactory sH = getStreamLHFactory(); final LinkHandlerFactory cH = getChannelLHFactory(); final LinkHandlerFactory pH = getPlaylistLHFactory(); - if (sH != null && sH.acceptUrl(url)) { + if (sH != null && sH.acceptUrl(polishedUrl)) { return LinkType.STREAM; - } else if (cH != null && cH.acceptUrl(url)) { + } else if (cH != null && cH.acceptUrl(polishedUrl)) { return LinkType.CHANNEL; - } else if (pH != null && pH.acceptUrl(url)) { + } else if (pH != null && pH.acceptUrl(polishedUrl)) { return LinkType.PLAYLIST; } else { return LinkType.NONE; diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/LinkHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/LinkHandlerFactory.java index 7dcfe5f48..ca428b706 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/LinkHandlerFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/LinkHandlerFactory.java @@ -49,11 +49,10 @@ public abstract class LinkHandlerFactory { * @param url the url to extract path and id from * @return a {@link LinkHandler} complete with information */ - public LinkHandler fromUrl(String url) throws ParsingException { - if (url == null) throw new IllegalArgumentException("url can not be null"); - url = Utils.followGoogleRedirectIfNeeded(url); - final String baseUrl = Utils.getBaseUrl(url); - return fromUrl(url, baseUrl); + public LinkHandler fromUrl(final String url) throws ParsingException { + final String polishedUrl = Utils.followGoogleRedirectIfNeeded(url); + final String baseUrl = Utils.getBaseUrl(polishedUrl); + return fromUrl(polishedUrl, baseUrl); } /** diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/ListLinkHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/ListLinkHandlerFactory.java index cdbbab4f0..4980c3191 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/ListLinkHandlerFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/ListLinkHandlerFactory.java @@ -31,10 +31,10 @@ public abstract class ListLinkHandlerFactory extends LinkHandlerFactory { /////////////////////////////////// @Override - public ListLinkHandler fromUrl(String url) throws ParsingException { - url = Utils.followGoogleRedirectIfNeeded(url); - final String baseUrl = Utils.getBaseUrl(url); - return fromUrl(url, baseUrl); + public ListLinkHandler fromUrl(final String url) throws ParsingException { + final String polishedUrl = Utils.followGoogleRedirectIfNeeded(url); + final String baseUrl = Utils.getBaseUrl(polishedUrl); + return fromUrl(polishedUrl, baseUrl); } @Override diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java index e8823af86..959202700 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java @@ -181,15 +181,15 @@ public class Utils { return s; } - public static String getBaseUrl(String url) throws ParsingException { + public static String getBaseUrl(final String url) throws ParsingException { try { final URL uri = stringToURL(url); return uri.getProtocol() + "://" + uri.getAuthority(); - } catch (MalformedURLException e) { + } catch (final MalformedURLException e) { final String message = e.getMessage(); if (message.startsWith("unknown protocol: ")) { - System.out.println(message.substring(18)); - return message.substring(18); // return just the protocol (e.g. vnd.youtube) + // return just the protocol (e.g. vnd.youtube) + return message.substring("unknown protocol: ".length()); } throw new ParsingException("Malformed url: " + url, e);