Federate new video content.

This commit is contained in:
Kavin 2022-11-13 01:00:26 +00:00
parent 0dcbb2e70e
commit 79621ac562
No known key found for this signature in database
GPG key ID: 49451E4482CC5BCD

View file

@ -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()));