From e7cbcfdb619b4c57a336bc42312f24a0d8da1029 Mon Sep 17 00:00:00 2001 From: jafea7 Date: Fri, 11 Apr 2025 13:36:02 +1000 Subject: [PATCH] Replace deprecated calls --- .../main/java/ctbrec/RecordingDownload.java | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/client/src/main/java/ctbrec/RecordingDownload.java b/client/src/main/java/ctbrec/RecordingDownload.java index 7c437e69..9bca4d45 100644 --- a/client/src/main/java/ctbrec/RecordingDownload.java +++ b/client/src/main/java/ctbrec/RecordingDownload.java @@ -4,6 +4,8 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.time.Instant; @@ -40,14 +42,28 @@ public class RecordingDownload extends MergedFfmpegHlsDownload { throws InvalidKeyException, NoSuchAlgorithmException, IllegalStateException, InterruptedException, IOException, ParseException, PlaylistException { running = true; if (Config.getInstance().getSettings().requireAuthentication) { - URL u = new URL(segmentPlaylistUri); - String path = u.getPath(); - byte[] key = Config.getInstance().getSettings().key; - if (!Config.getInstance().getContextPath().isEmpty()) { - path = path.substring(Config.getInstance().getContextPath().length()); + try { + URI uri = new URI(segmentPlaylistUri); + URL u = uri.toURL(); + String path = u.getPath(); + byte[] key = Config.getInstance().getSettings().key; + if (!Config.getInstance().getContextPath().isEmpty()) { + path = path.substring(Config.getInstance().getContextPath().length()); + } + String hmac = Hmac.calculate(path, key); + segmentPlaylistUri = segmentPlaylistUri + "?hmac=" + hmac; + } catch (URISyntaxException e) { + throw new IllegalArgumentException("Invalid URI: " + segmentPlaylistUri, e); } - String hmac = Hmac.calculate(path, key); - segmentPlaylistUri = segmentPlaylistUri + "?hmac=" + hmac; + + + // URL u = new URL(segmentPlaylistUri); + // String path = u.getPath(); + // byte[] key = Config.getInstance().getSettings().key; + // if (!Config.getInstance().getContextPath().isEmpty()) { + // path = path.substring(Config.getInstance().getContextPath().length()); + // } + // String hmac = Hmac.calculate(path, key); } startFfmpegProcess(target);