mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
Implement RYD-Proxy API implementation. (#293)
This commit is contained in:
parent
b7a91036f9
commit
374d067a95
4 changed files with 51 additions and 0 deletions
|
@ -21,6 +21,10 @@ DISABLE_REGISTRATION:false
|
|||
FEED_RETENTION:30
|
||||
# Disable CPU expensive timers (for nodes with low CPU, at least one node should have this disabled)
|
||||
DISABLE_TIMERS:false
|
||||
# RYD Proxy URL (see https://github.com/TeamPiped/RYD-Proxy)
|
||||
RYD_PROXY_URL:https://ryd-proxy.kavin.rocks
|
||||
# Disable the usage of RYD
|
||||
DISABLE_RYD:false
|
||||
# Hibernate properties
|
||||
hibernate.connection.url:jdbc:postgresql://postgres:5432/piped
|
||||
hibernate.connection.driver_class:org.postgresql.Driver
|
||||
|
|
|
@ -51,6 +51,10 @@ public class Constants {
|
|||
|
||||
public static final boolean DISABLE_TIMERS;
|
||||
|
||||
public static final String RYD_PROXY_URL;
|
||||
|
||||
public static final boolean DISABLE_RYD;
|
||||
|
||||
public static final String VERSION;
|
||||
|
||||
public static final ObjectMapper mapper = new ObjectMapper().addMixIn(Page.class, PageMixin.class);
|
||||
|
@ -78,6 +82,8 @@ public class Constants {
|
|||
DISABLE_REGISTRATION = Boolean.parseBoolean(getProperty(prop, "DISABLE_REGISTRATION", "false"));
|
||||
FEED_RETENTION = Integer.parseInt(getProperty(prop, "FEED_RETENTION", "30"));
|
||||
DISABLE_TIMERS = Boolean.parseBoolean(getProperty(prop, "DISABLE_TIMERS", "false"));
|
||||
RYD_PROXY_URL = getProperty(prop, "RYD_PROXY_URL", "https://ryd-proxy.kavin.rocks");
|
||||
DISABLE_RYD = Boolean.parseBoolean(getProperty(prop, "DISABLE_RYD", "false"));
|
||||
System.getenv().forEach((key, value) -> {
|
||||
if (key.startsWith("hibernate"))
|
||||
hibernateProperties.put(key, value);
|
||||
|
|
|
@ -98,6 +98,15 @@ public class ResponseHelper {
|
|||
return null;
|
||||
});
|
||||
|
||||
final var futureDislikeRating = Multithreading.supplyAsync(() -> {
|
||||
try {
|
||||
return RydHelper.getDislikeRating(videoId);
|
||||
} catch (Exception e) {
|
||||
ExceptionHandler.handle(e);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
final List<Subtitle> subtitles = new ObjectArrayList<>();
|
||||
final List<ChapterSegment> chapters = new ObjectArrayList<>();
|
||||
|
||||
|
@ -165,6 +174,20 @@ public class ResponseHelper {
|
|||
lbryId = null;
|
||||
}
|
||||
|
||||
// Attempt to get dislikes calculating with the RYD API rating
|
||||
if (info.getDislikeCount() < 0 && info.getLikeCount() >= 0) {
|
||||
double rating;
|
||||
try {
|
||||
rating = futureDislikeRating.get(2, TimeUnit.SECONDS);
|
||||
} catch (Exception e) {
|
||||
rating = -1;
|
||||
}
|
||||
|
||||
if (rating > 1 && rating <= 5) {
|
||||
info.setDislikeCount(Math.round(info.getLikeCount() * ((5 - rating) / (rating - 1))));
|
||||
}
|
||||
}
|
||||
|
||||
final Streams streams = new Streams(info.getName(), info.getDescription().getContent(),
|
||||
info.getTextualUploadDate(), info.getUploaderName(), substringYouTube(info.getUploaderUrl()),
|
||||
rewriteURL(info.getUploaderAvatarUrl()), rewriteURL(info.getThumbnailUrl()), info.getDuration(),
|
||||
|
|
18
src/main/java/me/kavin/piped/utils/RydHelper.java
Normal file
18
src/main/java/me/kavin/piped/utils/RydHelper.java
Normal file
|
@ -0,0 +1,18 @@
|
|||
package me.kavin.piped.utils;
|
||||
|
||||
|
||||
import me.kavin.piped.consts.Constants;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class RydHelper {
|
||||
public static double getDislikeRating(String videoId) throws IOException {
|
||||
|
||||
if (Constants.DISABLE_RYD)
|
||||
return -1;
|
||||
|
||||
return Constants.mapper.readTree(RequestUtils.sendGet(Constants.RYD_PROXY_URL + "/votes/" + videoId))
|
||||
.get("rating")
|
||||
.asDouble(-1);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue