[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:
parent
c589a2c1a2
commit
1f4ed9dce9
|
@ -22,6 +22,8 @@ import java.io.IOException;
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public class YoutubeFeedExtractor extends FeedExtractor {
|
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) {
|
public YoutubeFeedExtractor(final StreamingService service, final ListLinkHandler linkHandler) {
|
||||||
super(service, linkHandler);
|
super(service, linkHandler);
|
||||||
}
|
}
|
||||||
|
@ -57,19 +59,40 @@ public class YoutubeFeedExtractor extends FeedExtractor {
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return document.getElementsByTag("yt:channelId").first().text();
|
return getUrl().replace(WEBSITE_CHANNEL_BASE_URL, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getUrl() {
|
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
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
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
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue