Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public String getUrl(final String id,
* @return whether the value conform to short channel URLs
*/
private boolean isCustomShortChannelUrl(@Nonnull final String[] splitPath) {
return splitPath.length == 1 && !EXCLUDED_SEGMENTS.matcher(splitPath[0]).matches();
return splitPath.length == 1 && !splitPath[0].isEmpty()
&& !EXCLUDED_SEGMENTS.matcher(splitPath[0]).matches();
}

/**
Expand Down Expand Up @@ -99,15 +100,12 @@ public String getId(final String url) throws ParsingException, UnsupportedOperat
// Remove leading "/"
path = path.substring(1);

String[] splitPath = path.split("/");
final String[] splitPath = path.split("/");

if (isHandle(splitPath)) {
// Handle YouTube handle URLs like youtube.com/@yourhandle
if (isHandle(splitPath) || isCustomShortChannelUrl(splitPath)) {
// Handle YouTube handle URLs like youtube.com/@yourhandle and
// custom short channel URLs like youtube.com/yourcustomname
return splitPath[0];
} else if (isCustomShortChannelUrl(splitPath)) {
// Handle custom short channel URLs like youtube.com/yourcustomname
path = "c/" + path;
splitPath = path.split("/");
}

if (!path.startsWith("user/") && !path.startsWith("channel/")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,18 @@ void acceptUrlTest() throws ParsingException {

// do not accept URLs which are not channels
assertFalse(linkHandler.acceptUrl("https://www.youtube.com/watch?v=jZViOEv90dI&t=100"));
assertFalse(linkHandler.acceptUrl("https://www.youtube.com/watch"));
assertFalse(linkHandler.acceptUrl("http://www.youtube.com/watch_popup?v=uEJuoEs1UxY"));
assertFalse(linkHandler.acceptUrl("http://www.youtube.com/watch_popup"));
assertFalse(linkHandler.acceptUrl("http://www.youtube.com/attribution_link?a=JdfC0C9V6ZI&u=%2Fwatch%3Fv%3DEhxJLojIE_o%26feature%3Dshare"));
assertFalse(linkHandler.acceptUrl("http://www.youtube.com/attribution_link"));
assertFalse(linkHandler.acceptUrl("https://www.youtube.com/playlist?list=PLW5y1tjAOzI3orQNF1yGGVL5x-pR2K1d"));
assertFalse(linkHandler.acceptUrl("https://www.youtube.com/playlist"));
assertFalse(linkHandler.acceptUrl("https://www.youtube.com/embed/jZViOEv90dI"));
assertFalse(linkHandler.acceptUrl("https://www.youtube.com/embed"));
assertFalse(linkHandler.acceptUrl("https://www.youtube.com/feed/subscriptions?list=PLz8YL4HVC87WJQDzVoY943URKQCsHS9XV"));
assertFalse(linkHandler.acceptUrl("https://www.youtube.com/?app=desktop&persist_app=1"));
assertFalse(linkHandler.acceptUrl("https://www.youtube.com/feed"));
assertFalse(linkHandler.acceptUrl("https://www.youtube.com"));
assertFalse(linkHandler.acceptUrl("https://m.youtube.com/select_site"));
}

Expand Down Expand Up @@ -88,5 +94,8 @@ void getIdFromUrl() throws ParsingException {

assertEquals("@Gronkh", linkHandler.fromUrl("https://www.youtube.com/@Gronkh?ucbcb=1").getId());
assertEquals("@YouTubeCreators", linkHandler.fromUrl("https://www.youtube.com/@YouTubeCreators/shorts").getId());

assertEquals("PewDiePie", linkHandler.fromUrl("https://www.youtube.com/PewDiePie").getId());
assertEquals("DreamTraps", linkHandler.fromUrl("https://www.youtube.com/DreamTraps").getId());
}
}