diff --git a/build.gradle b/build.gradle index 401b144..291848a 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ dependencies { implementation 'it.unimi.dsi:fastutil-core:8.5.12' implementation 'commons-codec:commons-codec:1.15' implementation 'org.bouncycastle:bcprov-jdk15on:1.70' - implementation 'com.github.FireMasterK.NewPipeExtractor:NewPipeExtractor:a0037b718448d744b151412953ed28254acf5389' + implementation 'com.github.FireMasterK.NewPipeExtractor:NewPipeExtractor:251b204a23742c3413426c9b6131d084b190636f' implementation 'com.github.FireMasterK:nanojson:01934924442edda6952f3bedf80ba9e969cba8bc' implementation 'com.fasterxml.jackson.core:jackson-core:2.15.1' implementation 'com.fasterxml.jackson.core:jackson-annotations:2.15.1' 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..a7a5f79 100644 --- a/src/main/java/me/kavin/piped/server/handlers/ChannelHandlers.java +++ b/src/main/java/me/kavin/piped/server/handlers/ChannelHandlers.java @@ -11,12 +11,14 @@ 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; import org.schabi.newpipe.extractor.channel.ChannelTabInfo; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.linkhandler.ChannelTabs; import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; import org.schabi.newpipe.extractor.stream.StreamInfoItem; @@ -28,6 +30,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 +41,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 +84,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,37 +105,41 @@ public class ChannelHandlers { List