mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
Add support for a different address for proxying images. (#252)
This commit is contained in:
parent
1adbdeabe6
commit
a5296d6e5a
4 changed files with 19 additions and 9 deletions
|
@ -370,7 +370,7 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher {
|
|||
HttpResponse response = HttpResponse.ofCode(code).withBody(body).withHeader(CONTENT_TYPE, contentType)
|
||||
.withHeader(CACHE_CONTROL, cache);
|
||||
if (prefetchProxy)
|
||||
response = response.withHeader(LINK, String.format("<%s>; rel=preconnect", Constants.PROXY_PART));
|
||||
response = response.withHeader(LINK, String.format("<%s>; rel=preconnect", Constants.IMAGE_PROXY_PART));
|
||||
return response;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,8 @@ public class Constants {
|
|||
|
||||
public static final String PROXY_PART;
|
||||
|
||||
public static final String IMAGE_PROXY_PART;
|
||||
|
||||
public static final String CAPTCHA_BASE_URL, CAPTCHA_API_KEY;
|
||||
|
||||
public static final StreamingService YOUTUBE_SERVICE;
|
||||
|
@ -61,6 +63,7 @@ public class Constants {
|
|||
HTTP_WORKERS = getProperty(prop, "HTTP_WORKERS",
|
||||
String.valueOf(Runtime.getRuntime().availableProcessors()));
|
||||
PROXY_PART = getProperty(prop, "PROXY_PART");
|
||||
IMAGE_PROXY_PART = getProperty(prop, "IMAGE_PROXY_PART", PROXY_PART);
|
||||
CAPTCHA_BASE_URL = getProperty(prop, "CAPTCHA_BASE_URL");
|
||||
CAPTCHA_API_KEY = getProperty(prop, "CAPTCHA_API_KEY");
|
||||
PUBLIC_URL = getProperty(prop, "API_URL");
|
||||
|
|
|
@ -56,8 +56,7 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static me.kavin.piped.consts.Constants.YOUTUBE_SERVICE;
|
||||
import static me.kavin.piped.utils.URLUtils.rewriteURL;
|
||||
import static me.kavin.piped.utils.URLUtils.substringYouTube;
|
||||
import static me.kavin.piped.utils.URLUtils.*;
|
||||
import static org.schabi.newpipe.extractor.NewPipe.getPreferredContentCountry;
|
||||
import static org.schabi.newpipe.extractor.NewPipe.getPreferredLocalization;
|
||||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getJsonPostResponse;
|
||||
|
@ -126,17 +125,17 @@ public class ResponseHelper {
|
|||
boolean livestream = info.getStreamType() == StreamType.LIVE_STREAM;
|
||||
|
||||
if (!livestream) {
|
||||
info.getVideoOnlyStreams().forEach(stream -> videoStreams.add(new PipedStream(rewriteURL(stream.getUrl()),
|
||||
info.getVideoOnlyStreams().forEach(stream -> videoStreams.add(new PipedStream(rewriteVideoURL(stream.getUrl()),
|
||||
String.valueOf(stream.getFormat()), stream.getResolution(), stream.getFormat().getMimeType(), true,
|
||||
stream.getBitrate(), stream.getInitStart(), stream.getInitEnd(), stream.getIndexStart(),
|
||||
stream.getIndexEnd(), stream.getCodec(), stream.getWidth(), stream.getHeight(), 30)));
|
||||
info.getVideoStreams()
|
||||
.forEach(stream -> videoStreams
|
||||
.add(new PipedStream(rewriteURL(stream.getUrl()), String.valueOf(stream.getFormat()),
|
||||
.add(new PipedStream(rewriteVideoURL(stream.getUrl()), String.valueOf(stream.getFormat()),
|
||||
stream.getResolution(), stream.getFormat().getMimeType(), false)));
|
||||
|
||||
info.getAudioStreams()
|
||||
.forEach(stream -> audioStreams.add(new PipedStream(rewriteURL(stream.getUrl()),
|
||||
.forEach(stream -> audioStreams.add(new PipedStream(rewriteVideoURL(stream.getUrl()),
|
||||
String.valueOf(stream.getFormat()), stream.getAverageBitrate() + " kbps",
|
||||
stream.getFormat().getMimeType(), false, stream.getBitrate(), stream.getInitStart(),
|
||||
stream.getInitEnd(), stream.getIndexStart(), stream.getIndexEnd(), stream.getCodec())));
|
||||
|
@ -167,8 +166,8 @@ public class ResponseHelper {
|
|||
info.getTextualUploadDate(), info.getUploaderName(), substringYouTube(info.getUploaderUrl()),
|
||||
rewriteURL(info.getUploaderAvatarUrl()), rewriteURL(info.getThumbnailUrl()), info.getDuration(),
|
||||
info.getViewCount(), info.getLikeCount(), info.getDislikeCount(), info.getUploaderSubscriberCount(), info.isUploaderVerified(),
|
||||
audioStreams, videoStreams, relatedStreams, subtitles, livestream, rewriteURL(info.getHlsUrl()),
|
||||
rewriteURL(info.getDashMpdUrl()), lbryId, chapters);
|
||||
audioStreams, videoStreams, relatedStreams, subtitles, livestream, rewriteVideoURL(info.getHlsUrl()),
|
||||
rewriteVideoURL(info.getDashMpdUrl()), lbryId, chapters);
|
||||
|
||||
return Constants.mapper.writeValueAsBytes(streams);
|
||||
|
||||
|
|
|
@ -34,6 +34,14 @@ public class URLUtils {
|
|||
}
|
||||
|
||||
public static String rewriteURL(final String old) {
|
||||
return rewriteURL(old, Constants.IMAGE_PROXY_PART);
|
||||
}
|
||||
|
||||
public static String rewriteVideoURL(final String old) {
|
||||
return rewriteURL(old, Constants.PROXY_PART);
|
||||
}
|
||||
|
||||
public static String rewriteURL(final String old, final String proxy) {
|
||||
|
||||
if (StringUtils.isEmpty(old)) return null;
|
||||
|
||||
|
@ -57,7 +65,7 @@ public class URLUtils {
|
|||
path = StringUtils.substringBefore(path, "=") + "=" + StringUtils.substringAfter(path, "=").replace("-rj", "-rw");
|
||||
}
|
||||
|
||||
return Constants.PROXY_PART + path + (hasQuery ? "?" + query + "&host=" : "?host=") + silentEncode(host);
|
||||
return proxy + path + (hasQuery ? "?" + query + "&host=" : "?host=") + silentEncode(host);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue