Implement RYD-Proxy API implementation. (#293)

This commit is contained in:
Kavin 2022-06-27 17:11:22 +01:00 committed by GitHub
parent b7a91036f9
commit 374d067a95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 0 deletions

View file

@ -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

View file

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

View file

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

View 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);
}
}