Replace deprecated calls

This commit is contained in:
jafea7 2025-04-27 20:20:30 +10:00
parent 1e8de4d9e4
commit 14b019e87d
6 changed files with 47 additions and 28 deletions

View File

@ -2,6 +2,8 @@ package ctbrec.io;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
@ -14,16 +16,20 @@ public class UrlUtil {
private UrlUtil() {} private UrlUtil() {}
public static String addHmac(String url, Config config) throws MalformedURLException, InvalidKeyException, NoSuchAlgorithmException, IllegalStateException, UnsupportedEncodingException { public static String addHmac(String url, Config config) throws MalformedURLException, InvalidKeyException, NoSuchAlgorithmException, IllegalStateException, UnsupportedEncodingException {
URL u = new URL(url); try {
String path = u.getPath(); URI uri = new URI(url);
if (!config.getContextPath().isEmpty()) { URL u = uri.toURL();
path = path.substring(config.getContextPath().length()); String path = u.getPath();
if (!config.getContextPath().isEmpty()) {
path = path.substring(config.getContextPath().length());
}
byte[] key = config.getSettings().key;
String hmac = Hmac.calculate(path, key);
url = url + "?hmac=" + hmac;
return url;
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Invalid URI format: " + url, e);
} }
byte[] key = config.getSettings().key;
String hmac = Hmac.calculate(path, key);
url = url + "?hmac=" + hmac;
return url;
} }
} }

View File

@ -13,6 +13,8 @@ import org.slf4j.LoggerFactory;
import java.io.*; import java.io.*;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.nio.file.FileSystems; import java.nio.file.FileSystems;
import java.nio.file.Files; import java.nio.file.Files;
@ -199,18 +201,24 @@ public class HlsDownload extends AbstractHlsDownload {
@Override @Override
protected OutputStream getSegmentOutputStream(Segment segment) throws FileNotFoundException, MalformedURLException { protected OutputStream getSegmentOutputStream(Segment segment) throws FileNotFoundException, MalformedURLException {
URL segmentUrl = new URL(segment.url); try {
File tmp = new File(segmentUrl.getFile()); URI segmentUri = new URI(segment.url);
String prefixedFileName = segment.prefix + '_' + tmp.getName(); URL segmentUrl = segmentUri.toURL();
int questionMarkPosition = prefixedFileName.indexOf('?');
if (questionMarkPosition > 0) { File tmp = new File(segmentUrl.getFile());
prefixedFileName = prefixedFileName.substring(0, questionMarkPosition); String prefixedFileName = segment.prefix + '_' + tmp.getName();
} int questionMarkPosition = prefixedFileName.indexOf('?');
if (!prefixedFileName.endsWith(".ts")) { if (questionMarkPosition > 0) {
prefixedFileName += ".ts"; prefixedFileName = prefixedFileName.substring(0, questionMarkPosition);
} }
segment.targetFile = FileSystems.getDefault().getPath(downloadDir.toAbsolutePath().toString(), prefixedFileName).toFile(); if (!prefixedFileName.endsWith(".ts")) {
return new FileOutputStream(segment.targetFile); prefixedFileName += ".ts";
}
segment.targetFile = FileSystems.getDefault().getPath(downloadDir.toAbsolutePath().toString(), prefixedFileName).toFile();
return new FileOutputStream(segment.targetFile);
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Invalid URI format: " + segment.url, e);
}
} }
@Override @Override

View File

@ -15,6 +15,8 @@ import org.slf4j.LoggerFactory;
import javax.crypto.NoSuchPaddingException; import javax.crypto.NoSuchPaddingException;
import java.io.*; import java.io.*;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.security.InvalidAlgorithmParameterException; import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
@ -48,7 +50,13 @@ public class SegmentDownload implements Callable<SegmentDownload> {
this.segment = segment; this.segment = segment;
this.client = client; this.client = client;
this.out = out; this.out = out;
this.url = new URL(segment.url);
try {
URI uri = new URI(segment.url);
url = uri.toURL();
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Invalid URI format: " + segment.url, e);
}
} }
@Override @Override

View File

@ -81,8 +81,8 @@ public class Remux extends AbstractPostProcessor {
private String[] prepareCommandline(File inputFile, File remuxedFile) throws IOException { private String[] prepareCommandline(File inputFile, File remuxedFile) throws IOException {
String[] argsPreFfmpeg = getConfig().get(PRE_FFMPEG_ARGS).isEmpty() String[] argsPreFfmpeg = getConfig().get(PRE_FFMPEG_ARGS).isEmpty()
? new String[] {} // If empty, create an empty array ? new String[] {} // If empty, create an empty array
: getConfig().get(PRE_FFMPEG_ARGS).split(" "); : getConfig().get(PRE_FFMPEG_ARGS).split(" ");
String[] args = getConfig().get(FFMPEG_ARGS).split(" "); String[] args = getConfig().get(FFMPEG_ARGS).split(" ");
String[] argsPlusFile = new String[argsPreFfmpeg.length + args.length + 3]; String[] argsPlusFile = new String[argsPreFfmpeg.length + args.length + 3];
int i = 0; int i = 0;

View File

@ -24,8 +24,6 @@ import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.util.*; import java.util.*;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static ctbrec.ErrorMessages.HTTP_RESPONSE_BODY_IS_NULL; import static ctbrec.ErrorMessages.HTTP_RESPONSE_BODY_IS_NULL;
import static ctbrec.Model.State.*; import static ctbrec.Model.State.*;

View File

@ -13,7 +13,6 @@ import org.json.JSONObject;
import java.io.IOException; import java.io.IOException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.time.Duration; import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;