Skip to content

Commit 0e67d82

Browse files
author
Bartosz Rumiński
committed
Use static regex pattern for excluded path segments
1 parent d3f80d1 commit 0e67d82

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeChannelLinkHandlerFactory.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.schabi.newpipe.extractor.services.youtube.linkHandler;
22

3+
import java.util.regex.Pattern;
34
import org.schabi.newpipe.extractor.exceptions.ParsingException;
45
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
56
import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper;
@@ -49,22 +50,25 @@ public String getUrl(String id, List<String> contentFilters, String searchFilter
4950
return "https://www.youtube.com/" + id;
5051
}
5152

53+
5254
/**
5355
* Returns true if path conform to
5456
* custom short channel URLs like youtube.com/yourcustomname
5557
*
5658
* @param splitPath path segments array
5759
* @return true - if value conform to short channel URL, false - not
5860
*/
59-
private boolean isCustomShortChannelUrl(String[] splitPath) {
60-
return splitPath.length == 1 &&
61-
!splitPath[0].matches("playlist|watch|attribution_link|watch_popup|embed|feed|select_site");
61+
private boolean isCustomShortChannelUrl(final String[] splitPath) {
62+
return splitPath.length == 1 && !excludedSegments.matcher(splitPath[0]).matches();
6263
}
6364

65+
private static final Pattern excludedSegments =
66+
Pattern.compile("playlist|watch|attribution_link|watch_popup|embed|feed|select_site");
67+
6468
@Override
6569
public String getId(String url) throws ParsingException {
6670
try {
67-
URL urlObj = Utils.stringToURL(url);
71+
final URL urlObj = Utils.stringToURL(url);
6872
String path = urlObj.getPath();
6973

7074
if (!Utils.isHTTP(urlObj) || !(YoutubeParsingHelper.isYoutubeURL(urlObj) ||
@@ -86,7 +90,7 @@ public String getId(String url) throws ParsingException {
8690
throw new ParsingException("the URL given is neither a channel nor an user");
8791
}
8892

89-
String id = splitPath[1];
93+
final String id = splitPath[1];
9094

9195
if (id == null || !id.matches("[A-Za-z0-9_-]+")) {
9296
throw new ParsingException("The given id is not a Youtube-Video-ID");

0 commit comments

Comments
 (0)