Replace deprecated calls
This commit is contained in:
parent
1e8de4d9e4
commit
14b019e87d
|
@ -2,6 +2,8 @@ package ctbrec.io;
|
|||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
@ -14,16 +16,20 @@ public class UrlUtil {
|
|||
private UrlUtil() {}
|
||||
|
||||
public static String addHmac(String url, Config config) throws MalformedURLException, InvalidKeyException, NoSuchAlgorithmException, IllegalStateException, UnsupportedEncodingException {
|
||||
URL u = new URL(url);
|
||||
String path = u.getPath();
|
||||
if (!config.getContextPath().isEmpty()) {
|
||||
path = path.substring(config.getContextPath().length());
|
||||
try {
|
||||
URI uri = new URI(url);
|
||||
URL u = uri.toURL();
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import java.io.*;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
|
@ -199,18 +201,24 @@ public class HlsDownload extends AbstractHlsDownload {
|
|||
|
||||
@Override
|
||||
protected OutputStream getSegmentOutputStream(Segment segment) throws FileNotFoundException, MalformedURLException {
|
||||
URL segmentUrl = new URL(segment.url);
|
||||
File tmp = new File(segmentUrl.getFile());
|
||||
String prefixedFileName = segment.prefix + '_' + tmp.getName();
|
||||
int questionMarkPosition = prefixedFileName.indexOf('?');
|
||||
if (questionMarkPosition > 0) {
|
||||
prefixedFileName = prefixedFileName.substring(0, questionMarkPosition);
|
||||
try {
|
||||
URI segmentUri = new URI(segment.url);
|
||||
URL segmentUrl = segmentUri.toURL();
|
||||
|
||||
File tmp = new File(segmentUrl.getFile());
|
||||
String prefixedFileName = segment.prefix + '_' + tmp.getName();
|
||||
int questionMarkPosition = prefixedFileName.indexOf('?');
|
||||
if (questionMarkPosition > 0) {
|
||||
prefixedFileName = prefixedFileName.substring(0, questionMarkPosition);
|
||||
}
|
||||
if (!prefixedFileName.endsWith(".ts")) {
|
||||
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);
|
||||
}
|
||||
if (!prefixedFileName.endsWith(".ts")) {
|
||||
prefixedFileName += ".ts";
|
||||
}
|
||||
segment.targetFile = FileSystems.getDefault().getPath(downloadDir.toAbsolutePath().toString(), prefixedFileName).toFile();
|
||||
return new FileOutputStream(segment.targetFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -15,6 +15,8 @@ import org.slf4j.LoggerFactory;
|
|||
import javax.crypto.NoSuchPaddingException;
|
||||
import java.io.*;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
|
@ -48,7 +50,13 @@ public class SegmentDownload implements Callable<SegmentDownload> {
|
|||
this.segment = segment;
|
||||
this.client = client;
|
||||
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
|
||||
|
|
|
@ -81,8 +81,8 @@ public class Remux extends AbstractPostProcessor {
|
|||
|
||||
private String[] prepareCommandline(File inputFile, File remuxedFile) throws IOException {
|
||||
String[] argsPreFfmpeg = getConfig().get(PRE_FFMPEG_ARGS).isEmpty()
|
||||
? new String[] {} // If empty, create an empty array
|
||||
: getConfig().get(PRE_FFMPEG_ARGS).split(" ");
|
||||
? new String[] {} // If empty, create an empty array
|
||||
: getConfig().get(PRE_FFMPEG_ARGS).split(" ");
|
||||
String[] args = getConfig().get(FFMPEG_ARGS).split(" ");
|
||||
String[] argsPlusFile = new String[argsPreFfmpeg.length + args.length + 3];
|
||||
int i = 0;
|
||||
|
|
|
@ -24,8 +24,6 @@ import java.time.Duration;
|
|||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
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.Model.State.*;
|
||||
|
|
|
@ -13,7 +13,6 @@ import org.json.JSONObject;
|
|||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
|
|
Loading…
Reference in New Issue