diff --git a/src/main/java/me/kavin/piped/server/handlers/ChannelHandlers.java b/src/main/java/me/kavin/piped/server/handlers/ChannelHandlers.java index 541f14d..7feb05a 100644 --- a/src/main/java/me/kavin/piped/server/handlers/ChannelHandlers.java +++ b/src/main/java/me/kavin/piped/server/handlers/ChannelHandlers.java @@ -11,6 +11,7 @@ import me.kavin.piped.utils.obj.federation.FederatedVideoInfo; import me.kavin.piped.utils.resp.InvalidRequestResponse; import org.apache.commons.lang3.StringUtils; import org.hibernate.StatelessSession; +import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.Page; import org.schabi.newpipe.extractor.channel.ChannelInfo; @@ -28,6 +29,7 @@ import java.util.stream.Collectors; import static me.kavin.piped.consts.Constants.YOUTUBE_SERVICE; import static me.kavin.piped.consts.Constants.mapper; +import static me.kavin.piped.utils.CollectionUtils.collectPreloadedTabs; import static me.kavin.piped.utils.CollectionUtils.collectRelatedItems; import static me.kavin.piped.utils.URLUtils.rewriteURL; @@ -38,24 +40,30 @@ public class ChannelHandlers { final ChannelInfo info = ChannelInfo.getInfo("https://youtube.com/" + channelPath); - final List relatedStreams = collectRelatedItems(info.getRelatedItems()); + final ChannelTabInfo tabInfo = ChannelTabInfo.getInfo(YOUTUBE_SERVICE, collectPreloadedTabs(info.getTabs()).get(0)); - Multithreading.runAsync(() -> info.getRelatedItems().forEach(infoItem -> { - if ( - infoItem.getUploadDate() != null && - System.currentTimeMillis() - infoItem.getUploadDate().offsetDateTime().toInstant().toEpochMilli() - < TimeUnit.DAYS.toMillis(Constants.FEED_RETENTION) - ) - try { - MatrixHelper.sendEvent("video.piped.stream.info", new FederatedVideoInfo( - StringUtils.substring(infoItem.getUrl(), -11), StringUtils.substring(infoItem.getUploaderUrl(), -24), - infoItem.getName(), - infoItem.getDuration(), infoItem.getViewCount()) - ); - } catch (IOException e) { - throw new RuntimeException(e); - } - })); + final List relatedStreams = collectRelatedItems(tabInfo.getRelatedItems()); + + Multithreading.runAsync(() -> tabInfo.getRelatedItems() + .stream().filter(StreamInfoItem.class::isInstance) + .map(StreamInfoItem.class::cast) + .forEach(infoItem -> { + if ( + infoItem.getUploadDate() != null && + System.currentTimeMillis() - infoItem.getUploadDate().offsetDateTime().toInstant().toEpochMilli() + < TimeUnit.DAYS.toMillis(Constants.FEED_RETENTION) + ) + try { + MatrixHelper.sendEvent("video.piped.stream.info", new FederatedVideoInfo( + StringUtils.substring(infoItem.getUrl(), -11), StringUtils.substring(infoItem.getUploaderUrl(), -24), + infoItem.getName(), + infoItem.getDuration(), infoItem.getViewCount()) + ); + } catch (IOException e) { + throw new RuntimeException(e); + } + }) + ); Multithreading.runAsync(() -> { try { @@ -75,8 +83,10 @@ public class ChannelHandlers { ChannelHelpers.updateChannel(s, channel, info.getName(), info.getAvatarUrl(), info.isVerified()); - Set ids = info.getRelatedItems() + Set ids = tabInfo.getRelatedItems() .stream() + .filter(StreamInfoItem.class::isInstance) + .map(StreamInfoItem.class::cast) .filter(item -> { long time = item.getUploadDate() != null ? item.getUploadDate().offsetDateTime().toInstant().toEpochMilli() @@ -94,32 +104,35 @@ public class ChannelHandlers { List