mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 16:59:39 -05:00
Updated ProxyData exceptions to include previous exception to finish stacktrace
Updated LiveUserData.Request to throw an IllegalArgumentException when a null or blank username is provided Updated HttpClientSettings to use setProxyClientSettings instead of direct access Fixed ProxyRotation bug starting at index 1 instead of 0 and made methods default to synchronized in case concurrency is used in implementors code Changed HttpClient#toUrl to toUri Added @Getter to HttpClientFactory for liveClientSettings Added consumer to TikTokLive#requests so that way proxies can be used when calling the fetch methods Changed LiveUserData.Response#startTime to clarify the variable name
This commit is contained in:
@@ -50,16 +50,12 @@ public class ProxyData
|
||||
|
||||
return new ProxyData(address, port);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new IllegalArgumentException("Port must be a valid integer!");
|
||||
throw new IllegalArgumentException("Port must be a valid integer!", e);
|
||||
} catch (UnknownHostException e) {
|
||||
throw new IllegalArgumentException("Address must be valid IPv4, IPv6, or domain name!");
|
||||
throw new IllegalArgumentException("Address must be valid IPv4, IPv6, or domain name!", e);
|
||||
}
|
||||
}
|
||||
|
||||
public ProxyData clone() {
|
||||
return new ProxyData(address, port);
|
||||
}
|
||||
|
||||
public InetSocketAddress toSocketAddress() {
|
||||
return new InetSocketAddress(address, port);
|
||||
}
|
||||
|
||||
@@ -27,18 +27,23 @@ import lombok.*;
|
||||
public class LiveUserData {
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public static class Request {
|
||||
private String userName;
|
||||
private final String userName;
|
||||
|
||||
public Request(String userName) {
|
||||
if (userName == null || userName.isBlank())
|
||||
throw new IllegalArgumentException("Invalid empty username!");
|
||||
this.userName = userName;
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public static class Response {
|
||||
private String json;
|
||||
private UserStatus userStatus;
|
||||
private String roomId;
|
||||
private long startedAtTimeStamp;
|
||||
private final String json;
|
||||
private final UserStatus userStatus;
|
||||
private final String roomId;
|
||||
private final long startTime;
|
||||
|
||||
public boolean isLiveOnline() {
|
||||
return userStatus == LiveUserData.UserStatus.Live || userStatus == LiveUserData.UserStatus.LivePaused;
|
||||
|
||||
@@ -97,7 +97,7 @@ public class HttpClientSettings {
|
||||
newSettings.getHeaders().putAll(new TreeMap<>(this.headers));
|
||||
newSettings.getCookies().putAll(new TreeMap<>(this.cookies));
|
||||
newSettings.getParams().putAll(new TreeMap<>(this.params));
|
||||
newSettings.proxyClientSettings = this.proxyClientSettings;
|
||||
newSettings.setProxyClientSettings(this.proxyClientSettings);
|
||||
|
||||
return newSettings;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class ProxyClientSettings implements Iterator<ProxyData>
|
||||
private boolean enabled, autoDiscard = true, fallback = true;
|
||||
private Rotation rotation = Rotation.CONSECUTIVE;
|
||||
private final List<ProxyData> proxyList = new ArrayList<>();
|
||||
private int index = -1;
|
||||
private int index;
|
||||
private Proxy.Type type = Proxy.Type.DIRECT;
|
||||
private Consumer<ProxyData> onProxyUpdated = x -> {};
|
||||
|
||||
@@ -57,33 +57,27 @@ public class ProxyClientSettings implements Iterator<ProxyData>
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
public synchronized boolean hasNext() {
|
||||
return !proxyList.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProxyData next() {
|
||||
var nextProxy = switch (rotation)
|
||||
{
|
||||
case CONSECUTIVE -> {
|
||||
index = (index+1) % proxyList.size();
|
||||
yield proxyList.get(index).clone();
|
||||
public synchronized ProxyData next() {
|
||||
try {
|
||||
var nextProxy = proxyList.get(index);
|
||||
onProxyUpdated.accept(nextProxy);
|
||||
return nextProxy;
|
||||
} finally {
|
||||
switch (rotation) {
|
||||
case CONSECUTIVE -> index = ++index % proxyList.size();
|
||||
case RANDOM -> index = (int) (Math.random() * proxyList.size());
|
||||
case NONE -> index = Math.max(index, 0);
|
||||
}
|
||||
case RANDOM -> {
|
||||
index = new Random().nextInt(proxyList.size());
|
||||
yield proxyList.get(index).clone();
|
||||
}
|
||||
case NONE -> {
|
||||
index = Math.max(index, 0);
|
||||
yield proxyList.get(index).clone();
|
||||
}
|
||||
};
|
||||
onProxyUpdated.accept(nextProxy);
|
||||
return nextProxy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
public synchronized void remove() {
|
||||
proxyList.remove(index);
|
||||
}
|
||||
|
||||
@@ -97,8 +91,8 @@ public class ProxyClientSettings implements Iterator<ProxyData>
|
||||
}
|
||||
}
|
||||
|
||||
public ProxyClientSettings clone()
|
||||
{
|
||||
@Override
|
||||
public ProxyClientSettings clone() {
|
||||
ProxyClientSettings settings = new ProxyClientSettings();
|
||||
settings.setEnabled(enabled);
|
||||
settings.setRotation(rotation);
|
||||
@@ -109,6 +103,19 @@ public class ProxyClientSettings implements Iterator<ProxyData>
|
||||
return settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ProxyClientSettings{" +
|
||||
"enabled=" + enabled +
|
||||
", autoDiscard=" + autoDiscard +
|
||||
", fallback=" + fallback +
|
||||
", rotation=" + rotation +
|
||||
", proxyList=" + proxyList +
|
||||
", index=" + index +
|
||||
", type=" + type +
|
||||
'}';
|
||||
}
|
||||
|
||||
public enum Rotation
|
||||
{
|
||||
/** Rotate addresses consecutively, from proxy 0 -> 1 -> 2 -> ...etc. */
|
||||
|
||||
Reference in New Issue
Block a user