mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
Update video views on channel visits.
This commit is contained in:
parent
eadba21321
commit
7a18a6e6b2
1 changed files with 34 additions and 7 deletions
|
@ -164,9 +164,10 @@ public class ResponseHelper {
|
||||||
info.getStreamSegments().forEach(
|
info.getStreamSegments().forEach(
|
||||||
segment -> segments.add(new ChapterSegment(segment.getTitle(), segment.getStartTimeSeconds())));
|
segment -> segments.add(new ChapterSegment(segment.getTitle(), segment.getStartTimeSeconds())));
|
||||||
|
|
||||||
if (info.getUploadDate() != null && System.currentTimeMillis()
|
long time = info.getUploadDate().offsetDateTime().toInstant().toEpochMilli();
|
||||||
- info.getUploadDate().offsetDateTime().toInstant().toEpochMilli() < TimeUnit.DAYS.toMillis(10))
|
|
||||||
updateViews(info.getId(), info.getViewCount());
|
if (info.getUploadDate() != null && System.currentTimeMillis() - time < TimeUnit.DAYS.toMillis(10))
|
||||||
|
updateViews(info.getId(), info.getViewCount(), time, false);
|
||||||
|
|
||||||
final Streams streams = new Streams(info.getName(), info.getDescription().getContent(),
|
final Streams streams = new Streams(info.getName(), info.getDescription().getContent(),
|
||||||
info.getTextualUploadDate(), info.getUploaderName(), info.getUploaderUrl().substring(23),
|
info.getTextualUploadDate(), info.getUploaderName(), info.getUploaderUrl().substring(23),
|
||||||
|
@ -191,6 +192,25 @@ public class ResponseHelper {
|
||||||
item.getTextualUploadDate(), item.getDuration(), item.getViewCount()));
|
item.getTextualUploadDate(), item.getDuration(), item.getViewCount()));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Multithreading.runAsync(() -> {
|
||||||
|
Session s = DatabaseSessionFactory.createSession();
|
||||||
|
|
||||||
|
me.kavin.piped.utils.obj.db.Channel channel = DatabaseHelper.getChannelFromId(s, info.getId());
|
||||||
|
|
||||||
|
if (channel != null) {
|
||||||
|
for (StreamInfoItem item : info.getRelatedItems()) {
|
||||||
|
long time = item.getUploadDate() != null
|
||||||
|
? item.getUploadDate().offsetDateTime().toInstant().toEpochMilli()
|
||||||
|
: System.currentTimeMillis();
|
||||||
|
if (System.currentTimeMillis() - time < TimeUnit.DAYS.toMillis(10))
|
||||||
|
updateViews(item.getUrl().substring("https://www.youtube.com/watch?v=".length()),
|
||||||
|
item.getViewCount(), time, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
s.close();
|
||||||
|
});
|
||||||
|
|
||||||
String nextpage = null;
|
String nextpage = null;
|
||||||
if (info.hasNextPage()) {
|
if (info.hasNextPage()) {
|
||||||
Page page = info.getNextPage();
|
Page page = info.getNextPage();
|
||||||
|
@ -544,7 +564,7 @@ public class ResponseHelper {
|
||||||
|
|
||||||
Session s = DatabaseSessionFactory.createSession();
|
Session s = DatabaseSessionFactory.createSession();
|
||||||
|
|
||||||
User user = DatabaseHelper.getUserFromSession(s, session);
|
User user = DatabaseHelper.getUserFromSessionWithSubscribed(s, session);
|
||||||
|
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
if (!user.getSubscribed().contains(channelId)) {
|
if (!user.getSubscribed().contains(channelId)) {
|
||||||
|
@ -713,7 +733,7 @@ public class ResponseHelper {
|
||||||
long infoTime = info.getUploadDate() != null ? info.getUploadDate().offsetDateTime().toInstant().toEpochMilli()
|
long infoTime = info.getUploadDate() != null ? info.getUploadDate().offsetDateTime().toInstant().toEpochMilli()
|
||||||
: System.currentTimeMillis();
|
: System.currentTimeMillis();
|
||||||
|
|
||||||
Video video;
|
Video video = null;
|
||||||
|
|
||||||
if (channel != null && (video = DatabaseHelper.getVideoFromId(s, info.getId())) == null
|
if (channel != null && (video = DatabaseHelper.getVideoFromId(s, info.getId())) == null
|
||||||
&& (System.currentTimeMillis() - infoTime) < TimeUnit.DAYS.toMillis(10)) {
|
&& (System.currentTimeMillis() - infoTime) < TimeUnit.DAYS.toMillis(10)) {
|
||||||
|
@ -723,6 +743,12 @@ public class ResponseHelper {
|
||||||
|
|
||||||
s.save(video);
|
s.save(video);
|
||||||
|
|
||||||
|
s.beginTransaction().commit();
|
||||||
|
} else if (video != null) {
|
||||||
|
video.setViews(info.getViewCount());
|
||||||
|
|
||||||
|
s.update(video);
|
||||||
|
|
||||||
s.beginTransaction().commit();
|
s.beginTransaction().commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -730,7 +756,7 @@ public class ResponseHelper {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void updateViews(String id, long views) {
|
private static void updateViews(String id, long views, long time, boolean addIfNonExistent) {
|
||||||
Multithreading.runAsync(() -> {
|
Multithreading.runAsync(() -> {
|
||||||
try {
|
try {
|
||||||
Session s = DatabaseSessionFactory.createSession();
|
Session s = DatabaseSessionFactory.createSession();
|
||||||
|
@ -741,7 +767,8 @@ public class ResponseHelper {
|
||||||
video.setViews(views);
|
video.setViews(views);
|
||||||
s.update(video);
|
s.update(video);
|
||||||
s.beginTransaction().commit();
|
s.beginTransaction().commit();
|
||||||
}
|
} else if (addIfNonExistent)
|
||||||
|
handleNewVideo("https://www.youtube.com/watch?v=" + id, time);
|
||||||
|
|
||||||
s.close();
|
s.close();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue