mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 16:59:39 -05:00
Compare commits
33 Commits
1.8.10-Rel
...
develop-1.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
735bdfbb10 | ||
|
|
28ef3562b6 | ||
|
|
3b6b381e31 | ||
|
|
86a79d687e | ||
|
|
65a651d4b8 | ||
|
|
8bda5d789c | ||
|
|
81fb2b4576 | ||
|
|
64b2e74d2b | ||
|
|
8a1f3255d0 | ||
|
|
03892390fa | ||
|
|
71602d5513 | ||
|
|
20db7cb773 | ||
|
|
3fda7fe446 | ||
|
|
8fcbb4b20f | ||
|
|
d90ab60e52 | ||
|
|
33f9862758 | ||
|
|
d74c294323 | ||
|
|
31f0e4210d | ||
|
|
2e22da1fbe | ||
|
|
4b4874d33e | ||
|
|
9c7b24f33e | ||
|
|
7476a11ae0 | ||
|
|
125e421ea9 | ||
|
|
5d84e28bdb | ||
|
|
a9003f4296 | ||
|
|
8cd640f8eb | ||
|
|
ca741ed931 | ||
|
|
96872e27b5 | ||
|
|
f6fbd60eca | ||
|
|
437335f784 | ||
|
|
84b0a3aaf4 | ||
|
|
14bf9c8c9b | ||
|
|
2dc3001e7b |
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<version>1.8.9-Release</version>
|
<version>1.9.1-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>API</artifactId>
|
<artifactId>API</artifactId>
|
||||||
|
|||||||
@@ -23,11 +23,12 @@
|
|||||||
package io.github.jwdeveloper.tiktok.annotations;
|
package io.github.jwdeveloper.tiktok.annotations;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HIGHEST 1
|
ORDER -
|
||||||
* HIGH 2
|
* HIGHEST 1st,
|
||||||
* NORMAL 3
|
* HIGH 2nd,
|
||||||
* LOW 4
|
* NORMAL 3rd,
|
||||||
* LOWEST 5
|
* LOW 4th,
|
||||||
|
* LOWEST 5th
|
||||||
*/
|
*/
|
||||||
public enum Priority {
|
public enum Priority {
|
||||||
LOWEST(2), LOW(1), NORMAL(0), HIGH(-1), HIGHEST(-2);
|
LOWEST(2), LOW(1), NORMAL(0), HIGH(-1), HIGHEST(-2);
|
||||||
|
|||||||
@@ -36,11 +36,6 @@ public class TikTokDisconnectedEvent extends TikTokLiveClientEvent {
|
|||||||
this.reason = reason.isBlank() ? "None" : reason;
|
this.reason = reason.isBlank() ? "None" : reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokDisconnectedEvent() {
|
|
||||||
this("None");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static TikTokDisconnectedEvent of(String reason)
|
public static TikTokDisconnectedEvent of(String reason)
|
||||||
{
|
{
|
||||||
return new TikTokDisconnectedEvent(reason);
|
return new TikTokDisconnectedEvent(reason);
|
||||||
|
|||||||
@@ -25,11 +25,12 @@ package io.github.jwdeveloper.tiktok.data.events;
|
|||||||
import io.github.jwdeveloper.tiktok.annotations.*;
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.battles.*;
|
import io.github.jwdeveloper.tiktok.data.models.battles.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException;
|
||||||
import io.github.jwdeveloper.tiktok.messages.enums.LinkMicBattleStatus;
|
import io.github.jwdeveloper.tiktok.messages.enums.LinkMicBattleStatus;
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicBattle;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicBattle;
|
||||||
import lombok.*;
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Triggered every time a battle starts & ends
|
* Triggered every time a battle starts & ends
|
||||||
@@ -43,23 +44,22 @@ public class TikTokLinkMicBattleEvent extends TikTokHeaderEvent
|
|||||||
true if battle is finished otherwise false
|
true if battle is finished otherwise false
|
||||||
*/
|
*/
|
||||||
private final boolean finished;
|
private final boolean finished;
|
||||||
private final List<Team> teams;
|
private final Team team1, team2;
|
||||||
|
|
||||||
public TikTokLinkMicBattleEvent(WebcastLinkMicBattle msg) {
|
public TikTokLinkMicBattleEvent(WebcastLinkMicBattle msg) {
|
||||||
super(msg.getCommon());
|
super(msg.getCommon());
|
||||||
battleId = msg.getId();
|
battleId = msg.getId();
|
||||||
finished = msg.getBattleStatus() == LinkMicBattleStatus.BATTLE_FINISHED;
|
finished = msg.getBattleStatus() == LinkMicBattleStatus.BATTLE_FINISHED;
|
||||||
teams = new ArrayList<>();
|
|
||||||
if (msg.getHostTeamCount() == 2) { // 1v1 battle
|
if (msg.getHostTeamCount() == 2) { // 1v1 battle
|
||||||
teams.add(new Team1v1(msg.getHostTeam(0), msg));
|
team1 = new Team1v1(msg.getHostTeam(0), msg);
|
||||||
teams.add(new Team1v1(msg.getHostTeam(1), msg));
|
team2 = new Team1v1(msg.getHostTeam(1), msg);
|
||||||
} else { // 2v2 battle
|
} else { // 2v2 battle
|
||||||
if (isFinished()) {
|
if (isFinished()) {
|
||||||
teams.add(new Team2v2(msg.getHostData2V2List().stream().filter(data -> data.getTeamNumber() == 1).findFirst().orElse(null), msg));
|
team1 = new Team2v2(msg.getHostData2V2List().stream().filter(data -> data.getTeamNumber() == 1).findFirst().orElse(null), msg);
|
||||||
teams.add(new Team2v2(msg.getHostData2V2List().stream().filter(data -> data.getTeamNumber() == 2).findFirst().orElse(null), msg));
|
team2 = new Team2v2(msg.getHostData2V2List().stream().filter(data -> data.getTeamNumber() == 2).findFirst().orElse(null), msg);
|
||||||
} else {
|
} else {
|
||||||
teams.add(new Team2v2(msg.getHostTeam(0), msg.getHostTeam(1), msg));
|
team1 = new Team2v2(msg.getHostTeam(0), msg.getHostTeam(1), msg);
|
||||||
teams.add(new Team2v2(msg.getHostTeam(2), msg.getHostTeam(3), msg));
|
team2 = new Team2v2(msg.getHostTeam(2), msg.getHostTeam(3), msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,15 +69,69 @@ public class TikTokLinkMicBattleEvent extends TikTokHeaderEvent
|
|||||||
// - msg.getHostTeamCount() always is 2 for 1v1 or 4 for 2v2
|
// - msg.getHostTeamCount() always is 2 for 1v1 or 4 for 2v2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param battleHostName name of host to search
|
||||||
|
* @return Team1v1 instance containing name of host or null if no team found */
|
||||||
|
public Team1v1 get1v1Team(String battleHostName) {
|
||||||
|
if (!is1v1())
|
||||||
|
throw new TikTokLiveException("Teams are not instance of 1v1 battle!");
|
||||||
|
List<Team> list = getTeams(battleHostName);
|
||||||
|
return list.isEmpty() ? null : list.get(0).getAs1v1Team();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Team2v2 get2v2Team(String battleHostName) {
|
||||||
|
if (!is2v2())
|
||||||
|
throw new TikTokLiveException("Teams are not instance of 2v2 battle!");
|
||||||
|
List<Team> list = getTeams(battleHostName);
|
||||||
|
return list.isEmpty() ? null : list.get(0).getAs2v2Team();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param battleHostName name of host to search
|
||||||
|
* @return Team1v1 instance not containing name of host */
|
||||||
|
public Team1v1 get1v1OpponentTeam(String battleHostName) {
|
||||||
|
if (!is1v1())
|
||||||
|
throw new TikTokLiveException("Teams are not instance of 1v1 battle!");
|
||||||
|
List<Team> list = getTeams(battleHostName);
|
||||||
|
return list.isEmpty() ? null : list.get(1).getAs1v1Team();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Team2v2 get2x2OpponentTeam(String battleHostName) {
|
||||||
|
if (!is2v2())
|
||||||
|
throw new TikTokLiveException("Teams are not instance of 2v2 battle!");
|
||||||
|
List<Team> list = getTeams(battleHostName);
|
||||||
|
return list.isEmpty() ? null : list.get(1).getAs2v2Team();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param battleHostName name of host to search
|
||||||
|
* @return {@link List<Team>} with host team first, then opponent team
|
||||||
|
* <p> Empty if host is in neither otherwise always 2 in length;
|
||||||
|
*/
|
||||||
|
public List<Team> getTeams(String battleHostName) {
|
||||||
|
if (is1v1()) {
|
||||||
|
if (team1.getAs1v1Team().getHost().getName().equals(battleHostName))
|
||||||
|
return List.of(team1, team2);
|
||||||
|
if (team2.getAs1v1Team().getHost().getName().equals(battleHostName))
|
||||||
|
return List.of(team2, team1);
|
||||||
|
} else {
|
||||||
|
if (team1.getAs2v2Team().getHosts().stream().anyMatch(user -> user.getName().equals(battleHostName)))
|
||||||
|
return List.of(team1, team2);
|
||||||
|
if (team2.getAs2v2Team().getHosts().stream().anyMatch(user -> user.getName().equals(battleHostName)))
|
||||||
|
return List.of(team2, team1);
|
||||||
|
}
|
||||||
|
return List.of();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean is1v1() {
|
public boolean is1v1() {
|
||||||
return teams.get(0) instanceof Team1v1;
|
return team1.is1v1Team() || team2.is1v1Team();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean is2v2() {
|
public boolean is2v2() {
|
||||||
return teams.get(0) instanceof Team2v2;
|
return team1.is2v2Team() || team2.is2v2Team();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTie() {
|
public boolean isTie() {
|
||||||
return isFinished() && teams.get(0).getTotalPoints() == teams.get(1).getTotalPoints();
|
return isFinished() && team1.getTotalPoints() == team2.getTotalPoints();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,9 +35,15 @@ public class TikTokPreConnectionEvent extends TikTokLiveClientEvent
|
|||||||
private final LiveUserData.Response userData;
|
private final LiveUserData.Response userData;
|
||||||
private final LiveData.Response roomData;
|
private final LiveData.Response roomData;
|
||||||
@Setter boolean cancelConnection = false;
|
@Setter boolean cancelConnection = false;
|
||||||
|
@Setter String reason = "TikTokPreConnectionEvent cancelled connection!";
|
||||||
|
|
||||||
public TikTokPreConnectionEvent(LiveUserData.Response userData, LiveData.Response liveData) {
|
public TikTokPreConnectionEvent(LiveUserData.Response userData, LiveData.Response liveData) {
|
||||||
this.userData = userData;
|
this.userData = userData;
|
||||||
this.roomData = liveData;
|
this.roomData = liveData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCancelConnection(boolean cancelConnection, String reason) {
|
||||||
|
this.cancelConnection = cancelConnection;
|
||||||
|
this.reason = reason;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,6 @@ import io.github.jwdeveloper.tiktok.annotations.EventMeta;
|
|||||||
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLikeMessage;
|
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastMemberMessage;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastMemberMessage;
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastSocialMessage;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastSocialMessage;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|||||||
@@ -28,8 +28,6 @@ import io.github.jwdeveloper.tiktok.data.events.common.TikTokUnhandledEvent;
|
|||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@EventMeta(eventType = EventType.Debug)
|
@EventMeta(eventType = EventType.Debug)
|
||||||
public class TikTokWebsocketUnhandledMessageEvent extends TikTokUnhandledEvent<WebcastResponse.Message>
|
public class TikTokWebsocketUnhandledMessageEvent extends TikTokUnhandledEvent<WebcastResponse.Message>
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import java.awt.*;
|
|||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class Picture {
|
public class Picture {
|
||||||
@@ -85,8 +86,7 @@ public class Picture {
|
|||||||
throw new TikTokLiveException("Unable map downloaded image", e);
|
throw new TikTokLiveException("Unable map downloaded image", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
var bais = new ByteArrayInputStream(baos.toByteArray());
|
try (var bais = new ByteArrayInputStream(baos.toByteArray())) {
|
||||||
try {
|
|
||||||
return ImageIO.read(bais);
|
return ImageIO.read(bais);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new TikTokLiveException("Unable map downloaded image bytes to Image", e);
|
throw new TikTokLiveException("Unable map downloaded image bytes to Image", e);
|
||||||
@@ -97,8 +97,25 @@ public class Picture {
|
|||||||
return new Picture("");
|
return new Picture("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Picture asUnsigned() {
|
||||||
|
if (link == null || link.isEmpty())
|
||||||
|
return this;
|
||||||
|
// p16-sign-va.tiktokcdn.com -> p16-va.tiktokcdn.com || p16-sign.tiktokcdn.com -> p16.tiktokcdn.com
|
||||||
|
return new Picture(link.replace("-sign-", "-").replace("-sign.", "."));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Picture{link='" + link + "', image=" + image + "}";
|
return "Picture{link='" + link + "', image=" + image + "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final boolean equals(Object o) {
|
||||||
|
return o == this || o instanceof Picture picture && picture.link != null && picture.link.equals(link);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(link);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -48,7 +48,6 @@ public class Gift {
|
|||||||
this.properties = properties;
|
this.properties = properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Gift(int id, String name, int diamondCost, String pictureLink) {
|
public Gift(int id, String name, int diamondCost, String pictureLink) {
|
||||||
this(id, name, diamondCost, new Picture(pictureLink), new JsonObject());
|
this(id, name, diamondCost, new Picture(pictureLink), new JsonObject());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import java.util.*;
|
|||||||
public class User {
|
public class User {
|
||||||
private final Long id;
|
private final Long id;
|
||||||
private final String name;
|
private final String name;
|
||||||
|
private String signature;
|
||||||
private String profileName;
|
private String profileName;
|
||||||
private Picture picture;
|
private Picture picture;
|
||||||
private long following;
|
private long following;
|
||||||
@@ -106,6 +107,7 @@ public class User {
|
|||||||
public User(Long id,
|
public User(Long id,
|
||||||
String name,
|
String name,
|
||||||
String profileName,
|
String profileName,
|
||||||
|
String signature,
|
||||||
Picture picture,
|
Picture picture,
|
||||||
long following,
|
long following,
|
||||||
long followers,
|
long followers,
|
||||||
@@ -113,6 +115,7 @@ public class User {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.profileName = profileName;
|
this.profileName = profileName;
|
||||||
|
this.signature = signature;
|
||||||
this.picture = picture;
|
this.picture = picture;
|
||||||
this.following = following;
|
this.following = following;
|
||||||
this.followers = followers;
|
this.followers = followers;
|
||||||
@@ -133,7 +136,7 @@ public class User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public User(long id, String name, String profileId, Picture picture) {
|
public User(long id, String name, String profileId, Picture picture) {
|
||||||
this(id, name, profileId, picture, 0, 0, List.of(Badge.empty()));
|
this(id, name, profileId, null, picture, 0, 0, List.of(Badge.empty()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public User(WebcastLinkMicBattle.LinkMicBattleHost.HostGroup.Host host) {
|
public User(WebcastLinkMicBattle.LinkMicBattleHost.HostGroup.Host host) {
|
||||||
@@ -142,6 +145,7 @@ public class User {
|
|||||||
|
|
||||||
public User(io.github.jwdeveloper.tiktok.messages.data.User user) {
|
public User(io.github.jwdeveloper.tiktok.messages.data.User user) {
|
||||||
this(user.getId(), user.getDisplayId(), Picture.map(user.getAvatarThumb()));
|
this(user.getId(), user.getDisplayId(), Picture.map(user.getAvatarThumb()));
|
||||||
|
signature = user.getBioDescription();
|
||||||
profileName = user.getNickname();
|
profileName = user.getNickname();
|
||||||
following = user.getFollowInfo().getFollowingCount();
|
following = user.getFollowInfo().getFollowingCount();
|
||||||
followers = user.getFollowInfo().getFollowerCount();
|
followers = user.getFollowInfo().getFollowerCount();
|
||||||
|
|||||||
@@ -29,11 +29,11 @@ import java.util.List;
|
|||||||
|
|
||||||
public class GiftsData
|
public class GiftsData
|
||||||
{
|
{
|
||||||
@Getter
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public static final class Response
|
public static final class Response
|
||||||
{
|
{
|
||||||
private String json;
|
private final String json;
|
||||||
private List<Gift> gifts;
|
private final List<Gift> gifts;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,20 +28,19 @@ import lombok.Data;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.time.Duration;
|
|
||||||
|
|
||||||
public class LiveConnectionData {
|
public class LiveConnectionData {
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public static class Request {
|
public static class Request {
|
||||||
private String roomId;
|
private final String roomId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public static class Response {
|
public static class Response {
|
||||||
private String websocketCookies;
|
private final String websocketCookies;
|
||||||
private URI websocketUrl;
|
private final URI websocketUrl;
|
||||||
private WebcastResponse webcastResponse;
|
private final WebcastResponse webcastResponse;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,7 @@ public class LiveData {
|
|||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public static class Request {
|
public static class Request {
|
||||||
private String roomId;
|
private final String roomId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@@ -46,11 +46,7 @@ public class LiveData {
|
|||||||
private boolean ageRestricted;
|
private boolean ageRestricted;
|
||||||
private User host;
|
private User host;
|
||||||
private LiveType liveType;
|
private LiveType liveType;
|
||||||
public Response() {
|
public Response() {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum LiveStatus {
|
public enum LiveStatus {
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public class LiveUserData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public static class Response {
|
public static class Response {
|
||||||
private final String json;
|
private final String json;
|
||||||
|
|||||||
@@ -153,8 +153,8 @@ public class LiveClientSettings {
|
|||||||
clientParams.put("screen_height", 1152);
|
clientParams.put("screen_height", 1152);
|
||||||
clientParams.put("screen_width", 2048);
|
clientParams.put("screen_width", 2048);
|
||||||
clientParams.put("tz_name", "Europe/Berlin");
|
clientParams.put("tz_name", "Europe/Berlin");
|
||||||
clientParams.put("referer", "https, //www.tiktok.com/");
|
clientParams.put("referer", "https://www.tiktok.com/");
|
||||||
clientParams.put("root_referer", "https, //www.tiktok.com/");
|
clientParams.put("root_referer", "https://www.tiktok.com/");
|
||||||
clientParams.put("msToken", "");
|
clientParams.put("msToken", "");
|
||||||
clientParams.put("version_code", 180800);
|
clientParams.put("version_code", 180800);
|
||||||
clientParams.put("webcast_sdk_version", "1.3.0");
|
clientParams.put("webcast_sdk_version", "1.3.0");
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import java.util.function.Consumer;
|
|||||||
@Setter
|
@Setter
|
||||||
public class ProxyClientSettings implements Iterator<ProxyData>, Iterable<ProxyData>
|
public class ProxyClientSettings implements Iterator<ProxyData>, Iterable<ProxyData>
|
||||||
{
|
{
|
||||||
private boolean enabled, autoDiscard = true, fallback = true;
|
private boolean enabled, autoDiscard = true, fallback = true, allowWebsocket = true;
|
||||||
private Rotation rotation = Rotation.CONSECUTIVE;
|
private Rotation rotation = Rotation.CONSECUTIVE;
|
||||||
private final List<ProxyData> proxyList = new ArrayList<>();
|
private final List<ProxyData> proxyList = new ArrayList<>();
|
||||||
private int index;
|
private int index;
|
||||||
|
|||||||
@@ -22,9 +22,18 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.exceptions;
|
package io.github.jwdeveloper.tiktok.exceptions;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.data.requests.*;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class TikTokLiveOfflineHostException extends TikTokLiveException
|
public class TikTokLiveOfflineHostException extends TikTokLiveException
|
||||||
{
|
{
|
||||||
public TikTokLiveOfflineHostException(String message) {
|
private final LiveUserData.Response userData;
|
||||||
|
private final LiveData.Response liveData;
|
||||||
|
|
||||||
|
public TikTokLiveOfflineHostException(String message, LiveUserData.Response userData, LiveData.Response liveData) {
|
||||||
super(message);
|
super(message);
|
||||||
|
this.userData = userData;
|
||||||
|
this.liveData = liveData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023-2024 jwdeveloper jacekwoln@gmail.com
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package io.github.jwdeveloper.tiktok.exceptions;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.data.events.control.TikTokPreConnectionEvent;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class TikTokLivePreConnectionException extends TikTokLiveException
|
||||||
|
{
|
||||||
|
private final TikTokPreConnectionEvent preconnectEvent;
|
||||||
|
|
||||||
|
public TikTokLivePreConnectionException(TikTokPreConnectionEvent preconnectEvent) {
|
||||||
|
super(preconnectEvent.getReason());
|
||||||
|
this.preconnectEvent = preconnectEvent;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,9 +22,18 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.exceptions;
|
package io.github.jwdeveloper.tiktok.exceptions;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.data.requests.*;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class TikTokLiveUnknownHostException extends TikTokLiveException
|
public class TikTokLiveUnknownHostException extends TikTokLiveException
|
||||||
{
|
{
|
||||||
public TikTokLiveUnknownHostException(String message) {
|
private final LiveUserData.Response userData;
|
||||||
|
private final LiveData.Response liveData;
|
||||||
|
|
||||||
|
public TikTokLiveUnknownHostException(String message, LiveUserData.Response userData, LiveData.Response liveData) {
|
||||||
super(message);
|
super(message);
|
||||||
|
this.userData = userData;
|
||||||
|
this.liveData = liveData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -29,11 +29,6 @@ import io.github.jwdeveloper.tiktok.data.requests.LiveUserData;
|
|||||||
|
|
||||||
public interface LiveHttpClient
|
public interface LiveHttpClient
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @return {@link GiftsData.Response} list of gifts that are compiled and available on github
|
|
||||||
*/
|
|
||||||
GiftsData.Response fetchGiftsData();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {@link GiftsData.Response} list of gifts that are available in your region / livestream
|
* @return {@link GiftsData.Response} list of gifts that are available in your region / livestream
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,73 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2023-2024 jwdeveloper jacekwoln@gmail.com
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be
|
|
||||||
* included in all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
package io.github.jwdeveloper.tiktok.listener;
|
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ListenersManager
|
|
||||||
* <p>
|
|
||||||
* TikTokEventListener is an alternative way of handing TikTok events.
|
|
||||||
* <p>
|
|
||||||
* {@code TikTokLive.newClient("someuser").addListener(listener);}
|
|
||||||
* <p>
|
|
||||||
* After registertion, all listeners are kept in Listener manager - {@link LiveClient#getListenersManager()}
|
|
||||||
* <p>
|
|
||||||
* Method in TikTokEventListener should meet requirements below to be detected
|
|
||||||
* <p>- @TikTokEventObserver annotation
|
|
||||||
* <p>- 2 parameters of (LiveClient, Class extending TikTokEvent)
|
|
||||||
* <pre>
|
|
||||||
* {@code
|
|
||||||
* public static class CustomListener
|
|
||||||
* {
|
|
||||||
* @TikTokEventObserver
|
|
||||||
* public void onError(LiveClient liveClient, TikTokErrorEvent event)
|
|
||||||
* {
|
|
||||||
* System.out.println(event.getException().getMessage());
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* @TikTokEventObserver
|
|
||||||
* public void onCommentMessage(LiveClient liveClient, TikTokCommentEvent event)
|
|
||||||
* {
|
|
||||||
* System.out.println(event.getText());
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* @TikTokEventObserver
|
|
||||||
* public void onGiftMessage(LiveClient liveClient, TikTokGiftMessageEvent event)
|
|
||||||
* {
|
|
||||||
* System.out.println(event.getGift().getDescription());
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* @TikTokEventObserver
|
|
||||||
* public void onAnyEvent(LiveClient liveClient, TikTokEvent event)
|
|
||||||
* {
|
|
||||||
* System.out.println(event.getClass().getSimpleName());
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* </pre>
|
|
||||||
*/
|
|
||||||
@Deprecated(forRemoval = true, since = "1.8.1 (This interface is not longer needed, please remove it from your class) | Removing in 1.9.0")
|
|
||||||
public interface TikTokEventListener {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -22,12 +22,8 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.live;
|
package io.github.jwdeveloper.tiktok.live;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.gifts.*;
|
import io.github.jwdeveloper.tiktok.data.models.gifts.*;
|
||||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|||||||
@@ -22,16 +22,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.live;
|
package io.github.jwdeveloper.tiktok.live;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.dto.MessageMetaData;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.TikTokErrorEvent;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketMessageEvent;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketResponseEvent;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.websocket.TikTokWebsocketUnhandledMessageEvent;
|
|
||||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveMessageException;
|
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
||||||
import io.github.jwdeveloper.tiktok.utils.Stopwatch;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
|
|
||||||
public interface LiveMessagesHandler {
|
public interface LiveMessagesHandler {
|
||||||
void handle(LiveClient client, WebcastResponse webcastResponse);
|
void handle(LiveClient client, WebcastResponse webcastResponse);
|
||||||
|
|||||||
@@ -30,9 +30,8 @@ import io.github.jwdeveloper.tiktok.mappers.LiveMapper;
|
|||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public interface LiveClientBuilder extends EventsBuilder<LiveClientBuilder> {
|
public interface LiveClientBuilder extends EventsBuilder<LiveClientBuilder>
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is triggered after default mappings are registered
|
* This method is triggered after default mappings are registered
|
||||||
* It could be used to OVERRIDE behaviour of mappings and implement custom behaviour
|
* It could be used to OVERRIDE behaviour of mappings and implement custom behaviour
|
||||||
@@ -40,18 +39,15 @@ public interface LiveClientBuilder extends EventsBuilder<LiveClientBuilder> {
|
|||||||
* Be aware if for example you override WebcastGiftEvent, onGiftEvent() will not be working
|
* Be aware if for example you override WebcastGiftEvent, onGiftEvent() will not be working
|
||||||
*
|
*
|
||||||
* @param onCustomMappings lambda method
|
* @param onCustomMappings lambda method
|
||||||
* @return
|
* @return {@link LiveClientBuilder}
|
||||||
*/
|
*/
|
||||||
LiveClientBuilder mappings(Consumer<LiveMapper> onCustomMappings);
|
LiveClientBuilder mappings(Consumer<LiveMapper> onCustomMappings);
|
||||||
|
|
||||||
@Deprecated(forRemoval = true, since = "1.8.2 use `mappings` method instead")
|
|
||||||
LiveClientBuilder onMappings(Consumer<LiveMapper> onCustomMappings);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration of client settings
|
* Configuration of client settings
|
||||||
*
|
*
|
||||||
* @param onConfigure
|
* @param onConfigure Consumer for {@link LiveClientSettings}
|
||||||
* @return
|
* @return {@link LiveClientBuilder}
|
||||||
* @see LiveClientSettings
|
* @see LiveClientSettings
|
||||||
*/
|
*/
|
||||||
LiveClientBuilder configure(Consumer<LiveClientSettings> onConfigure);
|
LiveClientBuilder configure(Consumer<LiveClientSettings> onConfigure);
|
||||||
@@ -59,7 +55,7 @@ public interface LiveClientBuilder extends EventsBuilder<LiveClientBuilder> {
|
|||||||
/**
|
/**
|
||||||
* Adds events listener class, its fancy way to register events without using lamda method
|
* Adds events listener class, its fancy way to register events without using lamda method
|
||||||
*
|
*
|
||||||
* @return
|
* @return {@link LiveClientBuilder}
|
||||||
*/
|
*/
|
||||||
LiveClientBuilder addListener(Object listener);
|
LiveClientBuilder addListener(Object listener);
|
||||||
|
|
||||||
@@ -69,7 +65,7 @@ public interface LiveClientBuilder extends EventsBuilder<LiveClientBuilder> {
|
|||||||
* when the default implementation does not meet your needs
|
* when the default implementation does not meet your needs
|
||||||
*
|
*
|
||||||
* @param onCustomizeDependencies access to dependency container
|
* @param onCustomizeDependencies access to dependency container
|
||||||
* @return
|
* @return {@link LiveClientBuilder}
|
||||||
*/
|
*/
|
||||||
LiveClientBuilder customize(Consumer<DependanceContainerBuilder> onCustomizeDependencies);
|
LiveClientBuilder customize(Consumer<DependanceContainerBuilder> onCustomizeDependencies);
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<version>1.8.9-Release</version>
|
<version>1.9.1-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -22,20 +22,18 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok;
|
package io.github.jwdeveloper.tiktok;
|
||||||
|
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.settings.LiveClientSettings;
|
import io.github.jwdeveloper.tiktok.data.settings.LiveClientSettings;
|
||||||
import io.github.jwdeveloper.tiktok.gifts.TikTokGiftsManager;
|
|
||||||
import io.github.jwdeveloper.tiktok.http.LiveHttpClient;
|
import io.github.jwdeveloper.tiktok.http.LiveHttpClient;
|
||||||
import io.github.jwdeveloper.tiktok.live.GiftsManager;
|
|
||||||
import io.github.jwdeveloper.tiktok.live.builder.LiveClientBuilder;
|
import io.github.jwdeveloper.tiktok.live.builder.LiveClientBuilder;
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class TikTokLive {
|
public class TikTokLive
|
||||||
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
|
* Example: {@code https://www.tiktok.com/@dostawcavideo} - hostName would be 'dostawcavideo'
|
||||||
*
|
*
|
||||||
* @param hostName profile name of TikTok user could be found in profile link
|
* @param hostName profile name of TikTok user could be found in profile link
|
||||||
* @return LiveClientBuilder
|
* @return LiveClientBuilder
|
||||||
@@ -45,7 +43,7 @@ public class TikTokLive {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
|
* Example: {@code https://www.tiktok.com/@dostawcavideo} - hostName would be 'dostawcavideo'
|
||||||
*
|
*
|
||||||
* @param hostName profile name of TikTok user could be found in profile link
|
* @param hostName profile name of TikTok user could be found in profile link
|
||||||
* @return true if live is Online, false if is offline
|
* @return true if live is Online, false if is offline
|
||||||
@@ -55,17 +53,17 @@ public class TikTokLive {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
|
* Example: {@code https://www.tiktok.com/@dostawcavideo} - hostName would be 'dostawcavideo'
|
||||||
*
|
*
|
||||||
* @param hostName profile name of TikTok user could be found in profile link
|
* @param hostName profile name of TikTok user could be found in profile link
|
||||||
* @return true if live is Online, false if is offline
|
* @return {@link CompletableFuture} of true if live is Online, false if is offline
|
||||||
*/
|
*/
|
||||||
public static CompletableFuture<Boolean> isLiveOnlineAsync(String hostName) {
|
public static CompletableFuture<Boolean> isLiveOnlineAsync(String hostName) {
|
||||||
return CompletableFuture.supplyAsync(() -> isLiveOnline(hostName));
|
return CompletableFuture.supplyAsync(() -> isLiveOnline(hostName));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
|
* Example: {@code https://www.tiktok.com/@dostawcavideo} - hostName would be 'dostawcavideo'
|
||||||
*
|
*
|
||||||
* @param hostName profile name of TikTok user could be found in profile link
|
* @param hostName profile name of TikTok user could be found in profile link
|
||||||
* @return true is hostName name is valid and exists, false if not
|
* @return true is hostName name is valid and exists, false if not
|
||||||
@@ -75,7 +73,7 @@ public class TikTokLive {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Example: https://www.tiktok.com/@dostawcavideo - hostName would be 'dostawcavideo'
|
* Example: {@code https://www.tiktok.com/@dostawcavideo} - hostName would be 'dostawcavideo'
|
||||||
*
|
*
|
||||||
* @param hostName profile name of TikTok user could be found in profile link
|
* @param hostName profile name of TikTok user could be found in profile link
|
||||||
* @return true is hostName name is valid and exists, false if not
|
* @return true is hostName name is valid and exists, false if not
|
||||||
@@ -101,20 +99,4 @@ public class TikTokLive {
|
|||||||
public static LiveHttpClient requests() {
|
public static LiveHttpClient requests() {
|
||||||
return requests(liveClientSettings -> {});
|
return requests(liveClientSettings -> {});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static GiftsManager giftsManager;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch gifts from endpoint and returns GiftManager
|
|
||||||
*
|
|
||||||
* @return GiftsManager
|
|
||||||
*/
|
|
||||||
public static GiftsManager gifts() {
|
|
||||||
if (giftsManager == null) {
|
|
||||||
synchronized (GiftsManager.class) {
|
|
||||||
giftsManager = new TikTokGiftsManager(requests().fetchGiftsData().getGifts());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return giftsManager;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -83,7 +83,7 @@ public class TikTokLiveClient implements LiveClient
|
|||||||
} catch (TikTokLiveException e) {
|
} catch (TikTokLiveException e) {
|
||||||
setState(ConnectionState.DISCONNECTED);
|
setState(ConnectionState.DISCONNECTED);
|
||||||
tikTokEventHandler.publish(this, new TikTokErrorEvent(e));
|
tikTokEventHandler.publish(this, new TikTokErrorEvent(e));
|
||||||
tikTokEventHandler.publish(this, new TikTokDisconnectedEvent());
|
tikTokEventHandler.publish(this, new TikTokDisconnectedEvent("Exception: "+e.getMessage()));
|
||||||
|
|
||||||
if (e instanceof TikTokLiveOfflineHostException && clientSettings.isRetryOnConnectionFailure()) {
|
if (e instanceof TikTokLiveOfflineHostException && clientSettings.isRetryOnConnectionFailure()) {
|
||||||
try {
|
try {
|
||||||
@@ -114,10 +114,10 @@ public class TikTokLiveClient implements LiveClient
|
|||||||
roomInfo.setRoomId(userData.getRoomId());
|
roomInfo.setRoomId(userData.getRoomId());
|
||||||
|
|
||||||
if (userData.getUserStatus() == LiveUserData.UserStatus.Offline)
|
if (userData.getUserStatus() == LiveUserData.UserStatus.Offline)
|
||||||
throw new TikTokLiveOfflineHostException("User is offline: " + roomInfo.getHostName());
|
throw new TikTokLiveOfflineHostException("User is offline: " + roomInfo.getHostName(), userData, null);
|
||||||
|
|
||||||
if (userData.getUserStatus() == LiveUserData.UserStatus.NotFound)
|
if (userData.getUserStatus() == LiveUserData.UserStatus.NotFound)
|
||||||
throw new TikTokLiveUnknownHostException("User not found: " + roomInfo.getHostName());
|
throw new TikTokLiveUnknownHostException("User not found: " + roomInfo.getHostName(), userData, null);
|
||||||
|
|
||||||
var liveDataRequest = new LiveData.Request(userData.getRoomId());
|
var liveDataRequest = new LiveData.Request(userData.getRoomId());
|
||||||
var liveData = httpClient.fetchLiveData(liveDataRequest);
|
var liveData = httpClient.fetchLiveData(liveDataRequest);
|
||||||
@@ -126,10 +126,10 @@ public class TikTokLiveClient implements LiveClient
|
|||||||
throw new TikTokLiveException("Livestream for " + roomInfo.getHostName() + " is 18+ or age restricted!");
|
throw new TikTokLiveException("Livestream for " + roomInfo.getHostName() + " is 18+ or age restricted!");
|
||||||
|
|
||||||
if (liveData.getLiveStatus() == LiveData.LiveStatus.HostNotFound)
|
if (liveData.getLiveStatus() == LiveData.LiveStatus.HostNotFound)
|
||||||
throw new TikTokLiveUnknownHostException("LiveStream for " + roomInfo.getHostName() + " could not be found.");
|
throw new TikTokLiveUnknownHostException("LiveStream for " + roomInfo.getHostName() + " could not be found.", userData, liveData);
|
||||||
|
|
||||||
if (liveData.getLiveStatus() == LiveData.LiveStatus.HostOffline)
|
if (liveData.getLiveStatus() == LiveData.LiveStatus.HostOffline)
|
||||||
throw new TikTokLiveOfflineHostException("LiveStream for " + roomInfo.getHostName() + " not found, is the Host offline?");
|
throw new TikTokLiveOfflineHostException("LiveStream for " + roomInfo.getHostName() + " not found, is the Host offline?", userData, liveData);
|
||||||
|
|
||||||
roomInfo.setTitle(liveData.getTitle());
|
roomInfo.setTitle(liveData.getTitle());
|
||||||
roomInfo.setViewersCount(liveData.getViewers());
|
roomInfo.setViewersCount(liveData.getViewers());
|
||||||
@@ -140,7 +140,7 @@ public class TikTokLiveClient implements LiveClient
|
|||||||
var preconnectEvent = new TikTokPreConnectionEvent(userData, liveData);
|
var preconnectEvent = new TikTokPreConnectionEvent(userData, liveData);
|
||||||
tikTokEventHandler.publish(this, preconnectEvent);
|
tikTokEventHandler.publish(this, preconnectEvent);
|
||||||
if (preconnectEvent.isCancelConnection())
|
if (preconnectEvent.isCancelConnection())
|
||||||
throw new TikTokLiveException("TikTokPreConnectionEvent cancelled connection!");
|
throw new TikTokLivePreConnectionException(preconnectEvent);
|
||||||
|
|
||||||
if (clientSettings.isFetchGifts())
|
if (clientSettings.isFetchGifts())
|
||||||
giftManager.attachGiftsList(httpClient.fetchRoomGiftsData(userData.getRoomId()).getGifts());
|
giftManager.attachGiftsList(httpClient.fetchRoomGiftsData(userData.getRoomId()).getGifts());
|
||||||
|
|||||||
@@ -70,12 +70,6 @@ public class TikTokLiveClientBuilder implements LiveClientBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public LiveClientBuilder onMappings(Consumer<LiveMapper> onCustomMappings) {
|
|
||||||
mappings(onCustomMappings);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TikTokLiveClientBuilder configure(Consumer<LiveClientSettings> onConfigure) {
|
public TikTokLiveClientBuilder configure(Consumer<LiveClientSettings> onConfigure) {
|
||||||
onConfigure.accept(clientSettings);
|
onConfigure.accept(clientSettings);
|
||||||
return this;
|
return this;
|
||||||
@@ -155,11 +149,7 @@ public class TikTokLiveClientBuilder implements LiveClientBuilder {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
//gifts
|
//gifts
|
||||||
if (clientSettings.isFetchGifts()) {
|
|
||||||
dependance.registerSingleton(GiftsManager.class, TikTokLive.gifts());
|
|
||||||
} else {
|
|
||||||
dependance.registerSingleton(GiftsManager.class, new TikTokGiftsManager(List.of()));
|
dependance.registerSingleton(GiftsManager.class, new TikTokGiftsManager(List.of()));
|
||||||
}
|
|
||||||
|
|
||||||
//mapper
|
//mapper
|
||||||
dependance.registerSingleton(TikTokGenericEventMapper.class);
|
dependance.registerSingleton(TikTokGenericEventMapper.class);
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
private static final String TIKTOK_SIGN_API = "https://tiktok.eulerstream.com/webcast/fetch";
|
private static final String TIKTOK_SIGN_API = "https://tiktok.eulerstream.com/webcast/fetch";
|
||||||
private static final String TIKTOK_URL_WEB = "https://www.tiktok.com/";
|
private static final String TIKTOK_URL_WEB = "https://www.tiktok.com/";
|
||||||
private static final String TIKTOK_URL_WEBCAST = "https://webcast.tiktok.com/webcast/";
|
private static final String TIKTOK_URL_WEBCAST = "https://webcast.tiktok.com/webcast/";
|
||||||
public static final String TIKTOK_GIFTS_URL = "https://raw.githubusercontent.com/TikTok-LIVE-Private/GiftsGenerator/master/page/public/gifts.json";
|
|
||||||
public static final String TIKTOK_ROOM_GIFTS_URL = TIKTOK_URL_WEBCAST+"gift/list/";
|
public static final String TIKTOK_ROOM_GIFTS_URL = TIKTOK_URL_WEBCAST+"gift/list/";
|
||||||
public static final int TIKTOK_AGE_RESTRICTED_CODE = 4003110;
|
public static final int TIKTOK_AGE_RESTRICTED_CODE = 4003110;
|
||||||
|
|
||||||
@@ -95,31 +94,6 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
return giftsDataMapper.mapRoom(json);
|
return giftsDataMapper.mapRoom(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GiftsData.Response fetchGiftsData() {
|
|
||||||
var proxyClientSettings = clientSettings.getHttpSettings().getProxyClientSettings();
|
|
||||||
if (proxyClientSettings.isEnabled()) {
|
|
||||||
while (proxyClientSettings.hasNext()) {
|
|
||||||
try {
|
|
||||||
return getGiftsData();
|
|
||||||
} catch (TikTokProxyRequestException ignored) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return getGiftsData();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated(since = "1.8.6", forRemoval = true)
|
|
||||||
public GiftsData.Response getGiftsData() {
|
|
||||||
var result = httpFactory.client(TIKTOK_GIFTS_URL)
|
|
||||||
.build()
|
|
||||||
.toJsonResponse();
|
|
||||||
|
|
||||||
if (result.isFailure())
|
|
||||||
throw new TikTokLiveRequestException("Unable to fetch gifts information's - "+result);
|
|
||||||
|
|
||||||
var json = result.getContent();
|
|
||||||
return giftsDataMapper.map(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LiveUserData.Response fetchLiveUserData(LiveUserData.Request request) {
|
public LiveUserData.Response fetchLiveUserData(LiveUserData.Request request) {
|
||||||
var proxyClientSettings = clientSettings.getHttpSettings().getProxyClientSettings();
|
var proxyClientSettings = clientSettings.getHttpSettings().getProxyClientSettings();
|
||||||
@@ -138,6 +112,7 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
var result = httpFactory.client(url)
|
var result = httpFactory.client(url)
|
||||||
.withParam("uniqueId", request.getUserName())
|
.withParam("uniqueId", request.getUserName())
|
||||||
.withParam("sourceType", "54") //MAGIC NUMBER, WHAT 54 means?
|
.withParam("sourceType", "54") //MAGIC NUMBER, WHAT 54 means?
|
||||||
|
.withCookie("sessionid", clientSettings.getSessionId())
|
||||||
.build()
|
.build()
|
||||||
.toJsonResponse();
|
.toJsonResponse();
|
||||||
|
|
||||||
@@ -165,6 +140,7 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
var url = TIKTOK_URL_WEBCAST + "room/info";
|
var url = TIKTOK_URL_WEBCAST + "room/info";
|
||||||
var result = httpFactory.client(url)
|
var result = httpFactory.client(url)
|
||||||
.withParam("room_id", request.getRoomId())
|
.withParam("room_id", request.getRoomId())
|
||||||
|
.withCookie("sessionid", clientSettings.getSessionId())
|
||||||
.build()
|
.build()
|
||||||
.toJsonResponse();
|
.toJsonResponse();
|
||||||
|
|
||||||
@@ -219,13 +195,12 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
protected ActionResult<HttpResponse<byte[]>> getByteResponse(String room_id) {
|
protected ActionResult<HttpResponse<byte[]>> getByteResponse(String room_id) {
|
||||||
HttpClientBuilder builder = httpFactory.client(TIKTOK_SIGN_API)
|
HttpClientBuilder builder = httpFactory.client(TIKTOK_SIGN_API)
|
||||||
.withParam("client", "ttlive-java")
|
.withParam("client", "ttlive-java")
|
||||||
.withParam("uuc", "1") //MAGIC NUMBER!
|
|
||||||
.withParam("room_id", room_id);
|
.withParam("room_id", room_id);
|
||||||
|
|
||||||
if (clientSettings.getApiKey() != null)
|
if (clientSettings.getApiKey() != null)
|
||||||
builder.withParam("apiKey", clientSettings.getApiKey());
|
builder.withParam("apiKey", clientSettings.getApiKey());
|
||||||
|
|
||||||
var result = builder.build().toResponse();
|
var result = builder.build().toHttpResponse(HttpResponse.BodyHandlers.ofByteArray());
|
||||||
|
|
||||||
if (result.isFailure())
|
if (result.isFailure())
|
||||||
throw new TikTokSignServerException("Unable to get websocket connection credentials - "+result);
|
throw new TikTokSignServerException("Unable to get websocket connection credentials - "+result);
|
||||||
|
|||||||
@@ -35,11 +35,6 @@ import java.net.URI;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TikTokLiveHttpOfflineClient implements LiveHttpClient {
|
public class TikTokLiveHttpOfflineClient implements LiveHttpClient {
|
||||||
@Override
|
|
||||||
public GiftsData.Response fetchGiftsData() {
|
|
||||||
return new GiftsData.Response("", List.of());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GiftsData.Response fetchRoomGiftsData(String room_id) {
|
public GiftsData.Response fetchRoomGiftsData(String room_id) {
|
||||||
return new GiftsData.Response("", List.of());
|
return new GiftsData.Response("", List.of());
|
||||||
|
|||||||
@@ -42,11 +42,11 @@ public class HttpClient {
|
|||||||
protected final String url;
|
protected final String url;
|
||||||
private final Pattern pattern = Pattern.compile("charset=(.*?)(?=&|$)");
|
private final Pattern pattern = Pattern.compile("charset=(.*?)(?=&|$)");
|
||||||
|
|
||||||
public ActionResult<HttpResponse<byte[]>> toResponse() {
|
public <T> ActionResult<HttpResponse<T>> toHttpResponse(HttpResponse.BodyHandler<T> handler) {
|
||||||
var client = prepareClient();
|
var client = prepareClient();
|
||||||
var request = prepareGetRequest();
|
var request = prepareGetRequest();
|
||||||
try {
|
try {
|
||||||
var response = client.send(request, HttpResponse.BodyHandlers.ofByteArray());
|
var response = client.send(request, handler);
|
||||||
var result = ActionResult.of(response);
|
var result = ActionResult.of(response);
|
||||||
return switch (response.statusCode()) {
|
return switch (response.statusCode()) {
|
||||||
case 420 -> result.message("HttpResponse Code:", response.statusCode(), "| IP Cloudflare Blocked.").failure();
|
case 420 -> result.message("HttpResponse Code:", response.statusCode(), "| IP Cloudflare Blocked.").failure();
|
||||||
@@ -68,8 +68,12 @@ public class HttpClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <T> ActionResult<T> toResponse(HttpResponse.BodyHandler<T> handler) {
|
||||||
|
return toHttpResponse(handler).map(HttpResponse::body);
|
||||||
|
}
|
||||||
|
|
||||||
public ActionResult<String> toJsonResponse() {
|
public ActionResult<String> toJsonResponse() {
|
||||||
return toResponse().map(content -> new String(content.body(), charsetFrom(content.headers())));
|
return toResponse(HttpResponse.BodyHandlers.ofString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Charset charsetFrom(HttpHeaders headers) {
|
private Charset charsetFrom(HttpHeaders headers) {
|
||||||
@@ -87,7 +91,7 @@ public class HttpClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult<byte[]> toBinaryResponse() {
|
public ActionResult<byte[]> toBinaryResponse() {
|
||||||
return toResponse().map(HttpResponse::body);
|
return toResponse(HttpResponse.BodyHandlers.ofByteArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public URI toUri() {
|
public URI toUri() {
|
||||||
@@ -99,6 +103,10 @@ public class HttpClient {
|
|||||||
var requestBuilder = HttpRequest.newBuilder().GET();
|
var requestBuilder = HttpRequest.newBuilder().GET();
|
||||||
requestBuilder.uri(toUri());
|
requestBuilder.uri(toUri());
|
||||||
requestBuilder.timeout(httpClientSettings.getTimeout());
|
requestBuilder.timeout(httpClientSettings.getTimeout());
|
||||||
|
if (!httpClientSettings.getCookies().isEmpty()) {
|
||||||
|
String cookieString = httpClientSettings.getCookies().entrySet().stream().map(e -> e.getKey()+"="+e.getValue()).collect(Collectors.joining("; "));
|
||||||
|
httpClientSettings.getHeaders().put("Cookie", cookieString);
|
||||||
|
}
|
||||||
httpClientSettings.getHeaders().forEach(requestBuilder::setHeader);
|
httpClientSettings.getHeaders().forEach(requestBuilder::setHeader);
|
||||||
|
|
||||||
httpClientSettings.getOnRequestCreating().accept(requestBuilder);
|
httpClientSettings.getOnRequestCreating().accept(requestBuilder);
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ public class HttpClientBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public HttpClientBuilder withCookie(String name, String value) {
|
public HttpClientBuilder withCookie(String name, String value) {
|
||||||
|
if (name != null && value != null)
|
||||||
httpClientSettings.getCookies().put(name, value);
|
httpClientSettings.getCookies().put(name, value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public class HttpProxyClient extends HttpClient {
|
|||||||
throw new TikTokProxyRequestException(e);
|
throw new TikTokProxyRequestException(e);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (e.getMessage().contains("503") && proxySettings.isFallback()) // Indicates proxy protocol is not supported
|
if (e.getMessage().contains("503") && proxySettings.isFallback()) // Indicates proxy protocol is not supported
|
||||||
return super.toResponse();
|
return super.toHttpResponse(HttpResponse.BodyHandlers.ofByteArray());
|
||||||
throw new TikTokProxyRequestException(e);
|
throw new TikTokProxyRequestException(e);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new TikTokLiveRequestException(e);
|
throw new TikTokLiveRequestException(e);
|
||||||
@@ -122,7 +122,7 @@ public class HttpProxyClient extends HttpClient {
|
|||||||
return ActionResult.success(response);
|
return ActionResult.success(response);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (e.getMessage().contains("503") && proxySettings.isFallback()) // Indicates proxy protocol is not supported
|
if (e.getMessage().contains("503") && proxySettings.isFallback()) // Indicates proxy protocol is not supported
|
||||||
return super.toResponse();
|
return super.toHttpResponse(HttpResponse.BodyHandlers.ofByteArray());
|
||||||
if (proxySettings.isAutoDiscard())
|
if (proxySettings.isAutoDiscard())
|
||||||
proxySettings.remove();
|
proxySettings.remove();
|
||||||
throw new TikTokProxyRequestException(e);
|
throw new TikTokProxyRequestException(e);
|
||||||
|
|||||||
@@ -59,8 +59,7 @@ public class GiftsDataMapper {
|
|||||||
if (jsonObject.get("data") instanceof JsonObject data && data.get("gifts") instanceof JsonArray giftArray) {
|
if (jsonObject.get("data") instanceof JsonObject data && data.get("gifts") instanceof JsonArray giftArray) {
|
||||||
var gifts = new ArrayList<Gift>();
|
var gifts = new ArrayList<Gift>();
|
||||||
|
|
||||||
for(int i = 0; i < giftArray.size(); i++) {
|
for (JsonElement element : giftArray) {
|
||||||
JsonElement element = giftArray.get(i);
|
|
||||||
Gift gift = mapSingleRoomGift(element);
|
Gift gift = mapSingleRoomGift(element);
|
||||||
gifts.add(gift);
|
gifts.add(gift);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,6 +131,7 @@ public class LiveDataMapper {
|
|||||||
var id = jsonElement.get("id").getAsLong();
|
var id = jsonElement.get("id").getAsLong();
|
||||||
var name = jsonElement.get("display_id").getAsString();
|
var name = jsonElement.get("display_id").getAsString();
|
||||||
var profileName = jsonElement.get("nickname").getAsString();
|
var profileName = jsonElement.get("nickname").getAsString();
|
||||||
|
var signature = jsonElement.get("bio_description").getAsString();
|
||||||
|
|
||||||
|
|
||||||
var followElement = jsonElement.getAsJsonObject("follow_info");
|
var followElement = jsonElement.getAsJsonObject("follow_info");
|
||||||
@@ -142,7 +143,7 @@ public class LiveDataMapper {
|
|||||||
var link = pictureElement.getAsJsonArray("url_list").get(1).getAsString();
|
var link = pictureElement.getAsJsonArray("url_list").get(1).getAsString();
|
||||||
var picture = new Picture(link);
|
var picture = new Picture(link);
|
||||||
|
|
||||||
var user = new User(id, name, profileName, picture, followingCount, followers, new ArrayList<>());
|
var user = new User(id, name, profileName, signature, picture, followingCount, followers, new ArrayList<>());
|
||||||
user.addAttribute(UserAttribute.LiveHost);
|
user.addAttribute(UserAttribute.LiveHost);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ public class LiveUserDataMapper
|
|||||||
Long.parseLong(user.get("id").getAsString()),
|
Long.parseLong(user.get("id").getAsString()),
|
||||||
user.get("uniqueId").getAsString(),
|
user.get("uniqueId").getAsString(),
|
||||||
user.get("nickname").getAsString(),
|
user.get("nickname").getAsString(),
|
||||||
|
user.get("signature").getAsString(),
|
||||||
new Picture(user.get("avatarLarger").getAsString()),
|
new Picture(user.get("avatarLarger").getAsString()),
|
||||||
stats.get("followingCount").getAsLong(),
|
stats.get("followingCount").getAsLong(),
|
||||||
stats.get("followerCount").getAsLong(),
|
stats.get("followerCount").getAsLong(),
|
||||||
|
|||||||
@@ -74,10 +74,10 @@ public class TikTokWebSocketClient implements LiveSocketClient {
|
|||||||
tikTokEventHandler,
|
tikTokEventHandler,
|
||||||
liveClient);
|
liveClient);
|
||||||
|
|
||||||
// ProxyClientSettings proxyClientSettings = clientSettings.getHttpSettings().getProxyClientSettings();
|
ProxyClientSettings proxyClientSettings = clientSettings.getHttpSettings().getProxyClientSettings();
|
||||||
// if (proxyClientSettings.isEnabled())
|
if (proxyClientSettings.isEnabled() && proxyClientSettings.isAllowWebsocket())
|
||||||
// connectProxy(proxyClientSettings);
|
connectProxy(proxyClientSettings);
|
||||||
// else
|
else
|
||||||
connectDefault();
|
connectDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,15 +115,14 @@ public class TikTokWebSocketClient implements LiveSocketClient {
|
|||||||
}
|
}
|
||||||
while (proxySettings.hasNext()) {
|
while (proxySettings.hasNext()) {
|
||||||
ProxyData proxyData = proxySettings.next();
|
ProxyData proxyData = proxySettings.next();
|
||||||
if (!tryProxyConnection(proxySettings, proxyData)) {
|
if (tryProxyConnection(proxySettings, proxyData)) {
|
||||||
if (proxySettings.isAutoDiscard())
|
|
||||||
proxySettings.remove();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
heartbeatTask.run(webSocketClient, clientSettings.getPingInterval());
|
heartbeatTask.run(webSocketClient, clientSettings.getPingInterval());
|
||||||
isConnected = true;
|
isConnected = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (proxySettings.isAutoDiscard())
|
||||||
|
proxySettings.remove();
|
||||||
|
}
|
||||||
if (!isConnected)
|
if (!isConnected)
|
||||||
throw new TikTokLiveException("Failed to connect to the websocket");
|
throw new TikTokLiveException("Failed to connect to the websocket");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,6 @@ public class TikTokWebSocketOfflineClient implements LiveSocketClient {
|
|||||||
if (liveClient == null) {
|
if (liveClient == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
handler.publish(liveClient, new TikTokDisconnectedEvent());
|
handler.publish(liveClient, new TikTokDisconnectedEvent("Stopping"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -24,13 +24,15 @@ package io.github.jwdeveloper.tiktok.websocket;
|
|||||||
|
|
||||||
import org.java_websocket.WebSocket;
|
import org.java_websocket.WebSocket;
|
||||||
|
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
public class WebSocketHeartbeatTask
|
public class WebSocketHeartbeatTask
|
||||||
{
|
{
|
||||||
private Thread thread;
|
private Thread thread;
|
||||||
private boolean isRunning = false;
|
private boolean isRunning = false;
|
||||||
private final int MAX_TIMEOUT = 250;
|
private final int MAX_TIMEOUT = 250;
|
||||||
private final int SLEEP_TIME = 500;
|
private final int SLEEP_TIME = 500;
|
||||||
private final byte[] heartbeatBytes = {58, 2, 104, 98}; // Byte Array of "3A026862" which is TikTok's custom heartbeat value
|
private final byte[] heartbeatBytes = Base64.getDecoder().decode("MgJwYjoCaGI="); // Used to be '3A026862' aka ':\x02hb', now is '2\x02pb:\x02hb'.
|
||||||
|
|
||||||
public void run(WebSocket webSocket, long pingTaskTime) {
|
public void run(WebSocket webSocket, long pingTaskTime) {
|
||||||
stop();
|
stop();
|
||||||
@@ -58,6 +60,5 @@ public class WebSocketHeartbeatTask
|
|||||||
isRunning = false;
|
isRunning = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,7 @@ Maven
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.jwdeveloper.TikTok-Live-Java</groupId>
|
<groupId>com.github.jwdeveloper.TikTok-Live-Java</groupId>
|
||||||
<artifactId>Client</artifactId>
|
<artifactId>Client</artifactId>
|
||||||
<version>1.8.7-Release</version>
|
<version>1.9.1-Release</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
@@ -87,7 +87,7 @@ dependencyResolutionManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.github.jwdeveloper.TikTok-Live-Java:Client:1.8.5-Release'
|
implementation 'com.github.jwdeveloper.TikTok-Live-Java:Client:1.9.1-Release'
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -746,7 +746,6 @@ public static class CustomListener {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<version>1.8.9-Release</version>
|
<version>1.9.1-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -64,8 +64,7 @@ public class Events_And_Gifts_Testing_Example
|
|||||||
})
|
})
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
var gifts = TikTokLive.gifts();
|
var roseGift = client.getGiftManager().getByName("Rose");
|
||||||
var roseGift = gifts.getByName("Rose");
|
|
||||||
|
|
||||||
var fakeGift = TikTokGiftEvent.of(roseGift);
|
var fakeGift = TikTokGiftEvent.of(roseGift);
|
||||||
var fakeComboGift = TikTokGiftComboEvent.of(roseGift, 12, GiftComboStateType.Begin);
|
var fakeComboGift = TikTokGiftComboEvent.of(roseGift, 12, GiftComboStateType.Begin);
|
||||||
|
|||||||
@@ -1,61 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2023-2024 jwdeveloper jacekwoln@gmail.com
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be
|
|
||||||
* included in all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
package io.github.jwdeveloper.tiktok;
|
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
|
|
||||||
|
|
||||||
public class GiftsExample {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
var giftsManager = TikTokLive.gifts();
|
|
||||||
|
|
||||||
var giftsList = giftsManager.toList();
|
|
||||||
for (var gift : giftsList) {
|
|
||||||
System.out.println("Gift: " + gift);
|
|
||||||
}
|
|
||||||
|
|
||||||
var giftsMap = giftsManager.toMap();
|
|
||||||
for (var entry : giftsMap.entrySet()) {
|
|
||||||
System.out.println("GiftId: " + entry.getKey() + " Gift: " + entry.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println("total number of gifts: " + giftsManager.toList().size());
|
|
||||||
|
|
||||||
var giftRose = giftsManager.getById(5655);
|
|
||||||
var giftRoseByName = giftsManager.getByName("Rose");
|
|
||||||
var giftByFilter = giftsManager.getByFilter(e -> e.getDiamondCost() > 50);
|
|
||||||
|
|
||||||
var giftsByFilter = giftsManager.getManyByFilter(e -> e.getDiamondCost() > 100);
|
|
||||||
System.out.println("total number of gifts with cost higher then 100: " + giftsByFilter.size());
|
|
||||||
/**
|
|
||||||
* In case searched gift not exists getByName returns you Gift.UNDEFINED
|
|
||||||
*/
|
|
||||||
var undefiedGift = giftsManager.getByName("GIFT WITH WRONG NAME");
|
|
||||||
|
|
||||||
|
|
||||||
var customGift = new Gift(123213213, "Custom gift", 50, "https://images.pexels.com/photos/2071882/pexels-photo-2071882.jpeg?cs=srgb&dl=pexels-wojciech-kumpicki-2071882.jpg&fm=jpg");
|
|
||||||
giftsManager.attachGift(customGift);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<version>1.8.9-Release</version>
|
<version>1.9.1-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<artifactId>API</artifactId>
|
<artifactId>API</artifactId>
|
||||||
<version>1.8.9-Release</version>
|
<version>1.9.1-Release</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<version>1.8.9-Release</version>
|
<version>1.9.1-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>extension-recorder</artifactId>
|
<artifactId>extension-recorder</artifactId>
|
||||||
|
|||||||
@@ -66,9 +66,11 @@ public class RecorderListener implements LiveRecorder {
|
|||||||
settings.getPrepareDownloadData().apply(json) :
|
settings.getPrepareDownloadData().apply(json) :
|
||||||
mapToDownloadData(json);
|
mapToDownloadData(json);
|
||||||
|
|
||||||
if (downloadData.getDownloadLiveUrl().isEmpty())
|
if (downloadData.getDownloadLiveUrl().isEmpty()) {
|
||||||
liveClient.getLogger().warning("Unable to find download live url!");
|
liveClient.getLogger().warning("Unable to find download live url!");
|
||||||
else
|
if (settings.isCancelConnectionIfNotFound())
|
||||||
|
event.setCancelConnection(true, "Unable to find download live url!");
|
||||||
|
} else
|
||||||
liveClient.getLogger().info("Live download url found!");
|
liveClient.getLogger().info("Live download url found!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,6 @@ public class DownloadData {
|
|||||||
private String sessionId;
|
private String sessionId;
|
||||||
|
|
||||||
public String getFullUrl() {
|
public String getFullUrl() {
|
||||||
return downloadLiveUrl + (downloadLiveUrl.contains("?") ? "&" : "?") + "_webnoredir=1&session_id=" + sessionId;
|
return downloadLiveUrl + (downloadLiveUrl.contains("?") ? "&" : "?") + "_webnoredir=1&_session_id=" + sessionId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -40,6 +40,10 @@ public class RecorderSettings {
|
|||||||
private File outputFile;
|
private File outputFile;
|
||||||
private Function<String,DownloadData> prepareDownloadData;
|
private Function<String,DownloadData> prepareDownloadData;
|
||||||
private boolean stopOnDisconnect = true;
|
private boolean stopOnDisconnect = true;
|
||||||
|
/**
|
||||||
|
True to Cancel connection to live if the download url is not found
|
||||||
|
*/
|
||||||
|
private boolean cancelConnectionIfNotFound = false;
|
||||||
|
|
||||||
public static RecorderSettings DEFAULT() {
|
public static RecorderSettings DEFAULT() {
|
||||||
return new RecorderSettings();
|
return new RecorderSettings();
|
||||||
|
|||||||
2
pom.xml
2
pom.xml
@@ -7,7 +7,7 @@
|
|||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>1.8.9-Release</version>
|
<version>1.9.1-Release</version>
|
||||||
<modules>
|
<modules>
|
||||||
<module>API</module>
|
<module>API</module>
|
||||||
<module>Client</module>
|
<module>Client</module>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<version>1.8.9-Release</version>
|
<version>1.9.1-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user