mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2025-04-29 16:30:29 +05:30
Suppress video insert errors on conflict
This commit is contained in:
parent
e66917d428
commit
f4040772a2
@ -6,7 +6,6 @@ import me.kavin.piped.consts.Constants;
|
|||||||
import me.kavin.piped.utils.obj.db.Video;
|
import me.kavin.piped.utils.obj.db.Video;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.hibernate.StatelessSession;
|
import org.hibernate.StatelessSession;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
|
||||||
import org.schabi.newpipe.extractor.stream.StreamExtractor;
|
import org.schabi.newpipe.extractor.stream.StreamExtractor;
|
||||||
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;
|
||||||
@ -49,14 +48,7 @@ public class VideoHelpers {
|
|||||||
Video video = new Video(info.getId(), info.getName(), info.getViewCount(), info.getDuration(),
|
Video video = new Video(info.getId(), info.getName(), info.getViewCount(), info.getDuration(),
|
||||||
Math.max(infoTime, time), info.getThumbnailUrl(), info.isShortFormContent(), channel);
|
Math.max(infoTime, time), info.getThumbnailUrl(), info.isShortFormContent(), channel);
|
||||||
|
|
||||||
var tr = s.beginTransaction();
|
insertVideo(video);
|
||||||
try {
|
|
||||||
s.insert(video);
|
|
||||||
tr.commit();
|
|
||||||
} catch (Exception e) {
|
|
||||||
tr.rollback();
|
|
||||||
ExceptionHandler.handle(e);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -87,14 +79,7 @@ public class VideoHelpers {
|
|||||||
Video video = new Video(extractor.getId(), extractor.getName(), extractor.getViewCount(), extractor.getLength(),
|
Video video = new Video(extractor.getId(), extractor.getName(), extractor.getViewCount(), extractor.getLength(),
|
||||||
Math.max(infoTime, time), extractor.getThumbnailUrl(), isShort, channel);
|
Math.max(infoTime, time), extractor.getThumbnailUrl(), isShort, channel);
|
||||||
|
|
||||||
var tr = s.beginTransaction();
|
insertVideo(video);
|
||||||
try {
|
|
||||||
s.insert(video);
|
|
||||||
tr.commit();
|
|
||||||
} catch (Exception e) {
|
|
||||||
tr.rollback();
|
|
||||||
ExceptionHandler.handle(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -169,4 +154,26 @@ public class VideoHelpers {
|
|||||||
return updated > 0;
|
return updated > 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void insertVideo(Video video) {
|
||||||
|
try (StatelessSession s = DatabaseSessionFactory.createStatelessSession()) {
|
||||||
|
var tr = s.beginTransaction();
|
||||||
|
try {
|
||||||
|
s.createNativeMutationQuery("INSERT INTO videos (uploader_id,duration,is_short,thumbnail,title,uploaded,views,id) values " +
|
||||||
|
"(:uploader_id,:duration,:is_short,:thumbnail,:title,:uploaded,:views,:id) ON CONFLICT DO NOTHING")
|
||||||
|
.setParameter("uploader_id", video.getChannel())
|
||||||
|
.setParameter("duration", video.getDuration())
|
||||||
|
.setParameter("is_short", video.isShort())
|
||||||
|
.setParameter("thumbnail", video.getThumbnail())
|
||||||
|
.setParameter("title", video.getTitle())
|
||||||
|
.setParameter("uploaded", video.getUploaded())
|
||||||
|
.setParameter("views", video.getViews())
|
||||||
|
.setParameter("id", video.getId()).executeUpdate();
|
||||||
|
tr.commit();
|
||||||
|
} catch (Exception e) {
|
||||||
|
tr.rollback();
|
||||||
|
ExceptionHandler.handle(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user