Use static regex pattern for excluded path segments
This commit is contained in:
parent
d3f80d1538
commit
0e67d820bc
|
@ -1,5 +1,6 @@
|
|||
package org.schabi.newpipe.extractor.services.youtube.linkHandler;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
|
||||
import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper;
|
||||
|
@ -49,6 +50,7 @@ public class YoutubeChannelLinkHandlerFactory extends ListLinkHandlerFactory {
|
|||
return "https://www.youtube.com/" + id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if path conform to
|
||||
* custom short channel URLs like youtube.com/yourcustomname
|
||||
|
@ -56,15 +58,17 @@ public class YoutubeChannelLinkHandlerFactory extends ListLinkHandlerFactory {
|
|||
* @param splitPath path segments array
|
||||
* @return true - if value conform to short channel URL, false - not
|
||||
*/
|
||||
private boolean isCustomShortChannelUrl(String[] splitPath) {
|
||||
return splitPath.length == 1 &&
|
||||
!splitPath[0].matches("playlist|watch|attribution_link|watch_popup|embed|feed|select_site");
|
||||
private boolean isCustomShortChannelUrl(final String[] splitPath) {
|
||||
return splitPath.length == 1 && !excludedSegments.matcher(splitPath[0]).matches();
|
||||
}
|
||||
|
||||
private static final Pattern excludedSegments =
|
||||
Pattern.compile("playlist|watch|attribution_link|watch_popup|embed|feed|select_site");
|
||||
|
||||
@Override
|
||||
public String getId(String url) throws ParsingException {
|
||||
try {
|
||||
URL urlObj = Utils.stringToURL(url);
|
||||
final URL urlObj = Utils.stringToURL(url);
|
||||
String path = urlObj.getPath();
|
||||
|
||||
if (!Utils.isHTTP(urlObj) || !(YoutubeParsingHelper.isYoutubeURL(urlObj) ||
|
||||
|
@ -86,7 +90,7 @@ public class YoutubeChannelLinkHandlerFactory extends ListLinkHandlerFactory {
|
|||
throw new ParsingException("the URL given is neither a channel nor an user");
|
||||
}
|
||||
|
||||
String id = splitPath[1];
|
||||
final String id = splitPath[1];
|
||||
|
||||
if (id == null || !id.matches("[A-Za-z0-9_-]+")) {
|
||||
throw new ParsingException("The given id is not a Youtube-Video-ID");
|
||||
|
|
Loading…
Reference in New Issue