Skip to content

Commit 94e7f0d

Browse files
StypoxTobiGr
authored andcommitted
Fix fallback method is not tried on exception
in YoutubeChannelInfoItem.getUrl()
1 parent 6d504e0 commit 94e7f0d

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelInfoItemExtractor.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,25 @@ public String getName() throws ParsingException {
5656

5757
@Override
5858
public String getUrl() throws ParsingException {
59-
String buttonTrackingUrl = el.select("button[class*=\"yt-uix-button\"]").first()
60-
.attr("abs:data-href");
59+
try {
60+
String buttonTrackingUrl = el.select("button[class*=\"yt-uix-button\"]").first()
61+
.attr("abs:data-href");
6162

62-
Pattern channelIdPattern = Pattern.compile("(?:.*?)\\%252Fchannel\\%252F([A-Za-z0-9\\-\\_]+)(?:.*)");
63-
Matcher match = channelIdPattern.matcher(buttonTrackingUrl);
63+
Pattern channelIdPattern = Pattern.compile("(?:.*?)\\%252Fchannel\\%252F([A-Za-z0-9\\-\\_]+)(?:.*)");
64+
Matcher match = channelIdPattern.matcher(buttonTrackingUrl);
6465

65-
if (match.matches()) {
66-
return YoutubeChannelExtractor.CHANNEL_URL_BASE + match.group(1);
67-
} else {
66+
if (match.matches()) {
67+
return YoutubeChannelExtractor.CHANNEL_URL_BASE + match.group(1);
68+
}
69+
} catch(Throwable ignored) {}
70+
71+
try {
6872
// fallback method just in case youtube changes things; it should never run and tests will fail
6973
// provides an url with "/user/NAME", that is inconsistent with stream and channel extractor
7074
return el.select("a[class*=\"yt-uix-tile-link\"]").first()
7175
.attr("abs:href");
76+
} catch (Throwable e) {
77+
throw new ParsingException("Could not get channel url", e);
7278
}
7379
}
7480

0 commit comments

Comments
 (0)