From 79621ac562bf187118548d4af148612b6f1f9d5b Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Sun, 13 Nov 2022 01:00:26 +0000 Subject: [PATCH] Federate new video content. --- .../java/me/kavin/piped/utils/VideoHelpers.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/java/me/kavin/piped/utils/VideoHelpers.java b/src/main/java/me/kavin/piped/utils/VideoHelpers.java index 200c758..ad50912 100644 --- a/src/main/java/me/kavin/piped/utils/VideoHelpers.java +++ b/src/main/java/me/kavin/piped/utils/VideoHelpers.java @@ -1,7 +1,10 @@ package me.kavin.piped.utils; import me.kavin.piped.consts.Constants; +import me.kavin.piped.utils.obj.MatrixHelper; import me.kavin.piped.utils.obj.db.Video; +import me.kavin.piped.utils.obj.federation.FederatedVideoInfo; +import org.apache.commons.lang3.StringUtils; import org.hibernate.StatelessSession; import org.schabi.newpipe.extractor.stream.StreamInfo; import org.schabi.newpipe.extractor.stream.StreamInfoItem; @@ -19,6 +22,20 @@ public class VideoHelpers { public static void handleNewVideo(StreamInfo info, long time, me.kavin.piped.utils.obj.db.Channel channel) { + Multithreading.runAsync(() -> { + if (info.getUploadDate() != null && System.currentTimeMillis() - info.getUploadDate().offsetDateTime().toInstant().toEpochMilli() < TimeUnit.DAYS.toMillis(Constants.FEED_RETENTION)) { + try { + MatrixHelper.sendEvent("video.piped.stream.info", new FederatedVideoInfo( + StringUtils.substring(info.getUrl(), -11), StringUtils.substring(info.getUploaderUrl(), -24), + info.getName(), + info.getDuration(), info.getViewCount()) + ); + } catch (Exception e) { + ExceptionHandler.handle(e); + } + } + }); + if (channel == null) channel = DatabaseHelper.getChannelFromId( info.getUploaderUrl().substring("https://www.youtube.com/channel/".length()));