[YouTube] Fix channel ID extraction of YouTube channel RSS feeds

The yt:channelId element doesn't provide the channel ID anymore and is empty,
like the id element, so we need now to extract it from the channel URL provided
in two elements: author -> uri and feed -> link.

Also avoid a NullPointerException in getUrl and getName methods.
This commit is contained in:
AudricV 2023-01-17 21:00:21 +01:00
parent c589a2c1a2
commit 1f4ed9dce9
No known key found for this signature in database
GPG Key ID: DA92EC7905614198
1 changed files with 26 additions and 3 deletions

View File

@ -22,6 +22,8 @@ import java.io.IOException;
import javax.annotation.Nonnull;
public class YoutubeFeedExtractor extends FeedExtractor {
private static final String WEBSITE_CHANNEL_BASE_URL = "https://www.youtube.com/channel/";
public YoutubeFeedExtractor(final StreamingService service, final ListLinkHandler linkHandler) {
super(service, linkHandler);
}
@ -57,19 +59,40 @@ public class YoutubeFeedExtractor extends FeedExtractor {
@Nonnull
@Override
public String getId() {
return document.getElementsByTag("yt:channelId").first().text();
return getUrl().replace(WEBSITE_CHANNEL_BASE_URL, "");
}
@Nonnull
@Override
public String getUrl() {
return document.select("feed > author > uri").first().text();
final Element authorUriElement = document.select("feed > author > uri")
.first();
if (authorUriElement != null) {
final String authorUriElementText = authorUriElement.text();
if (!authorUriElementText.equals("")) {
return authorUriElementText;
}
}
final Element linkElement = document.select("feed > link[rel*=alternate]")
.first();
if (linkElement != null) {
return linkElement.attr("href");
}
return "";
}
@Nonnull
@Override
public String getName() {
return document.select("feed > author > name").first().text();
final Element nameElement = document.select("feed > author > name")
.first();
if (nameElement == null) {
return "";
}
return nameElement.text();
}
@Override