mirror of
https://github.com/TeamPiped/Piped-Backend
synced 2025-09-06 13:31:17 +02:00
Merge pull request #430 from TeamPiped/send-new-videos
Federate new video content.
This commit is contained in:
commit
f06f23b07f
@ -1,7 +1,10 @@
|
|||||||
package me.kavin.piped.utils;
|
package me.kavin.piped.utils;
|
||||||
|
|
||||||
import me.kavin.piped.consts.Constants;
|
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.db.Video;
|
||||||
|
import me.kavin.piped.utils.obj.federation.FederatedVideoInfo;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.hibernate.StatelessSession;
|
import org.hibernate.StatelessSession;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
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) {
|
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)
|
if (channel == null)
|
||||||
channel = DatabaseHelper.getChannelFromId(
|
channel = DatabaseHelper.getChannelFromId(
|
||||||
info.getUploaderUrl().substring("https://www.youtube.com/channel/".length()));
|
info.getUploaderUrl().substring("https://www.youtube.com/channel/".length()));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user