|
|
|
|
@@ -381,7 +381,7 @@ public final class VideoCache {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
URLConnection raw = URI.create(url).toURL().openConnection();
|
|
|
|
|
URLConnection raw = URI.create(encodeForRequest(url)).toURL().openConnection();
|
|
|
|
|
raw.setConnectTimeout(10_000);
|
|
|
|
|
raw.setReadTimeout(30_000);
|
|
|
|
|
raw.setRequestProperty("User-Agent", "video_player/" + VideoPlayerMod.MOD_ID);
|
|
|
|
|
@@ -522,6 +522,31 @@ public final class VideoCache {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Percent-encode any non-ASCII characters in the URL so Java's {@link HttpURLConnection}
|
|
|
|
|
* puts a valid request line on the wire. The stored cache key, the {@link #sha256(String)}
|
|
|
|
|
* filename, and the {@link #READY} map all keep the ORIGINAL {@code url} string — only the
|
|
|
|
|
* bytes actually sent in the HTTP request are encoded — so {@link #lookup(String)} still
|
|
|
|
|
* matches the anchor's raw URL.
|
|
|
|
|
*
|
|
|
|
|
* <p>Without this, a URL with a non-ASCII path segment (e.g. {@code .../음악퀴즈/...}) is sent
|
|
|
|
|
* verbatim and the server answers HTTP 400, so every preload fails silently and the disk
|
|
|
|
|
* cache stays empty — clients then fall back to live streaming for every video. FFmpeg
|
|
|
|
|
* (playback) tolerates the raw URL, which is why playback "works" while the cache never
|
|
|
|
|
* fills. The multi-arg {@link URI} constructor encodes each component; an already-encoded
|
|
|
|
|
* URL round-trips unchanged (decode-then-encode is idempotent for these paths). On any
|
|
|
|
|
* parse failure we fall back to the raw string rather than dropping the download.
|
|
|
|
|
*/
|
|
|
|
|
private static String encodeForRequest(String url) {
|
|
|
|
|
try {
|
|
|
|
|
URI u = URI.create(url);
|
|
|
|
|
URI enc = new URI(u.getScheme(), u.getAuthority(), u.getPath(), u.getQuery(), u.getFragment());
|
|
|
|
|
return enc.toASCIIString();
|
|
|
|
|
} catch (Throwable t) {
|
|
|
|
|
return url;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Best-effort filename extension from the URL path so FFmpeg's container probe gets a hint
|
|
|
|
|
* (e.g. {@code .webm} for a webm stream). Falls back to {@code .bin}.
|
|
|
|
|
|