Skip to content

Commit

Permalink
Fix parameter reassignment and other style issues
Browse files Browse the repository at this point in the history
Also remove left-behind debug statement
  • Loading branch information
Stypox committed Jun 28, 2020
1 parent 7ed38b7 commit 495f219
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,18 +279,18 @@ public CommentsExtractor getCommentsExtractor(String url) throws ExtractionExcep
* @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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ public String getUrl(String id, String baseUrl) throws ParsingException {
* @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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public String getUrl(String id, List<String> contentFilter, String sortFilter, S
///////////////////////////////////

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ public static String removeUTF8BOM(String s) {
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);
Expand Down

0 comments on commit 495f219

Please sign in to comment.