Merge pull request #605 from TeamPiped/channel-no-videos-tab-fix

Fix for fetching channels without a videos tab.
This commit is contained in:
Kavin 2023-06-01 19:15:51 +01:00 committed by GitHub
commit e0dc4f8784
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -41,10 +41,18 @@ public class ChannelHandlers {
final ChannelInfo info = ChannelInfo.getInfo("https://youtube.com/" + channelPath); final ChannelInfo info = ChannelInfo.getInfo("https://youtube.com/" + channelPath);
final ChannelTabInfo tabInfo = ChannelTabInfo.getInfo(YOUTUBE_SERVICE, collectPreloadedTabs(info.getTabs()).get(0)); final var preloadedVideosTab = collectPreloadedTabs(info.getTabs())
.stream()
.filter(tab -> tab.getContentFilters().contains(ChannelTabs.VIDEOS))
.findFirst();
final List<ContentItem> relatedStreams = collectRelatedItems(tabInfo.getRelatedItems()); final ChannelTabInfo tabInfo = preloadedVideosTab.isPresent() ?
ChannelTabInfo.getInfo(YOUTUBE_SERVICE, preloadedVideosTab.get()) :
null;
final List<ContentItem> relatedStreams = tabInfo != null ? collectRelatedItems(tabInfo.getRelatedItems()) : List.of();
if (tabInfo != null)
Multithreading.runAsync(() -> tabInfo.getRelatedItems() Multithreading.runAsync(() -> tabInfo.getRelatedItems()
.stream().filter(StreamInfoItem.class::isInstance) .stream().filter(StreamInfoItem.class::isInstance)
.map(StreamInfoItem.class::cast) .map(StreamInfoItem.class::cast)
@ -74,6 +82,7 @@ public class ChannelHandlers {
} }
}); });
if (tabInfo != null)
Multithreading.runAsync(() -> { Multithreading.runAsync(() -> {
var channel = DatabaseHelper.getChannelFromId(info.getId()); var channel = DatabaseHelper.getChannelFromId(info.getId());
@ -132,7 +141,7 @@ public class ChannelHandlers {
}); });
String nextpage = null; String nextpage = null;
if (tabInfo.hasNextPage()) { if (tabInfo != null && tabInfo.hasNextPage()) {
Page page = tabInfo.getNextPage(); Page page = tabInfo.getNextPage();
nextpage = mapper.writeValueAsString(page); nextpage = mapper.writeValueAsString(page);
} }