mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-28 01:09:40 -05:00
Compare commits
14 Commits
1.0.12-Rel
...
1.0.14-Rel
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3231924f8f | ||
|
|
ea525470e2 | ||
|
|
b0bf4ac606 | ||
|
|
0b9f1570d0 | ||
|
|
7a4c7fecbd | ||
|
|
0ae9068858 | ||
|
|
8905958207 | ||
|
|
c12f3cc4dc | ||
|
|
7402899f52 | ||
|
|
1b8b150d61 | ||
|
|
b2305b7bed | ||
|
|
7b911838a2 | ||
|
|
e44cb71869 | ||
|
|
af8c689417 |
@@ -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.0.11-Release</version>
|
<version>1.0.13-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>API</artifactId>
|
<artifactId>API</artifactId>
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ public class TikTokUserInfo
|
|||||||
|
|
||||||
String roomId;
|
String roomId;
|
||||||
|
|
||||||
|
long startTime;
|
||||||
|
|
||||||
public enum UserStatus
|
public enum UserStatus
|
||||||
{
|
{
|
||||||
NotFound,
|
NotFound,
|
||||||
|
|||||||
@@ -24,19 +24,22 @@ package io.github.jwdeveloper.tiktok.data.models.badges;
|
|||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
import io.github.jwdeveloper.tiktok.messages.data.BadgeStruct;
|
import io.github.jwdeveloper.tiktok.messages.data.BadgeStruct;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class CombineBadge extends Badge {
|
public class CombineBadge extends Badge {
|
||||||
private final Picture picture;
|
private final Picture picture;
|
||||||
private final String text;
|
private final String text;
|
||||||
private final String subText;
|
private final String subText;
|
||||||
|
|
||||||
|
|
||||||
public CombineBadge(BadgeStruct.CombineBadge combineBadge) {
|
public CombineBadge(BadgeStruct.CombineBadge combineBadge) {
|
||||||
|
|
||||||
picture = Picture.map(combineBadge.getIcon());
|
picture = Picture.map(combineBadge.getIcon());
|
||||||
text = combineBadge.getText().getDefaultPattern();
|
text = combineBadge.getText().getDefaultPattern();
|
||||||
subText = combineBadge.getStr();
|
subText = combineBadge.getStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "CombineBadge{picture=" + picture +", text='" + text + "', subText='" + subText + "'}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -24,12 +24,18 @@ package io.github.jwdeveloper.tiktok.data.models.badges;
|
|||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
import io.github.jwdeveloper.tiktok.messages.data.BadgeStruct;
|
import io.github.jwdeveloper.tiktok.messages.data.BadgeStruct;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class PictureBadge extends Badge {
|
public class PictureBadge extends Badge {
|
||||||
|
|
||||||
private final Picture picture;
|
private final Picture picture;
|
||||||
public PictureBadge(BadgeStruct.ImageBadge imageBadge) {
|
|
||||||
|
|
||||||
|
public PictureBadge(BadgeStruct.ImageBadge imageBadge) {
|
||||||
picture = Picture.map(imageBadge.getImage());
|
picture = Picture.map(imageBadge.getImage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "PictureBadge{picture=" + picture + "}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -23,12 +23,18 @@
|
|||||||
package io.github.jwdeveloper.tiktok.data.models.badges;
|
package io.github.jwdeveloper.tiktok.data.models.badges;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.messages.data.BadgeStruct;
|
import io.github.jwdeveloper.tiktok.messages.data.BadgeStruct;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class StringBadge extends Badge {
|
public class StringBadge extends Badge {
|
||||||
|
private final String text;
|
||||||
|
|
||||||
public String text;
|
|
||||||
public StringBadge(BadgeStruct.StringBadge stringBadge) {
|
public StringBadge(BadgeStruct.StringBadge stringBadge) {
|
||||||
|
|
||||||
this.text = stringBadge.getStr();
|
this.text = stringBadge.getStr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "StringBadge{text='" + text + "'}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -23,13 +23,18 @@
|
|||||||
package io.github.jwdeveloper.tiktok.data.models.badges;
|
package io.github.jwdeveloper.tiktok.data.models.badges;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.messages.data.BadgeStruct;
|
import io.github.jwdeveloper.tiktok.messages.data.BadgeStruct;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
public class TextBadge extends Badge
|
@Getter
|
||||||
{
|
public class TextBadge extends Badge {
|
||||||
private final String text;
|
private final String text;
|
||||||
|
|
||||||
public TextBadge(BadgeStruct.TextBadge textBadge)
|
public TextBadge(BadgeStruct.TextBadge textBadge) {
|
||||||
{
|
|
||||||
this.text = textBadge.getDefaultPattern();
|
this.text = textBadge.getDefaultPattern();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "TextBadge{text='" + text + "'}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -42,6 +42,7 @@ public interface LiveRoomInfo
|
|||||||
*/
|
*/
|
||||||
int getTotalViewersCount();
|
int getTotalViewersCount();
|
||||||
int getLikesCount();
|
int getLikesCount();
|
||||||
|
long getStartTime();
|
||||||
boolean isAgeRestricted();
|
boolean isAgeRestricted();
|
||||||
String getRoomId();
|
String getRoomId();
|
||||||
String getHostName();
|
String getHostName();
|
||||||
|
|||||||
@@ -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.0.11-Release</version>
|
<version>1.0.13-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok;
|
package io.github.jwdeveloper.tiktok;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.data.dto.TikTokUserInfo;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.TikTokDisconnectedEvent;
|
import io.github.jwdeveloper.tiktok.data.events.TikTokDisconnectedEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.TikTokErrorEvent;
|
import io.github.jwdeveloper.tiktok.data.events.TikTokErrorEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.TikTokReconnectingEvent;
|
import io.github.jwdeveloper.tiktok.data.events.TikTokReconnectingEvent;
|
||||||
@@ -135,13 +136,15 @@ public class TikTokLiveClient implements LiveClient {
|
|||||||
|
|
||||||
apiService.updateSessionId();
|
apiService.updateSessionId();
|
||||||
|
|
||||||
|
TikTokUserInfo info = apiService.fetchUserInfoFromTikTokApi(liveRoomInfo.getHostName());
|
||||||
|
liveRoomInfo.setStartTime(info.getStartTime());
|
||||||
if (clientSettings.getRoomId() != null) {
|
if (clientSettings.getRoomId() != null) {
|
||||||
liveRoomInfo.setRoomId(clientSettings.getRoomId());
|
liveRoomInfo.setRoomId(clientSettings.getRoomId());
|
||||||
logger.info("Using roomID from settings: " + clientSettings.getRoomId());
|
logger.info("Using roomID from settings: " + clientSettings.getRoomId());
|
||||||
} else {
|
} else {
|
||||||
var roomId = apiService.fetchRoomId(liveRoomInfo.getHostName());
|
liveRoomInfo.setRoomId(info.getRoomId());
|
||||||
liveRoomInfo.setRoomId(roomId);
|
|
||||||
}
|
}
|
||||||
|
apiService.updateRoomId(liveRoomInfo.getRoomId());
|
||||||
|
|
||||||
|
|
||||||
var liveRoomMeta = apiService.fetchRoomInfo();
|
var liveRoomMeta = apiService.fetchRoomInfo();
|
||||||
|
|||||||
@@ -113,12 +113,12 @@ public class TikTokLiveClientBuilder implements LiveClientBuilder {
|
|||||||
clientSettings.setTimeout(Duration.ofSeconds(Constants.DEFAULT_TIMEOUT));
|
clientSettings.setTimeout(Duration.ofSeconds(Constants.DEFAULT_TIMEOUT));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clientSettings.getClientLanguage() == null || clientSettings.getClientLanguage().equals("")) {
|
if (clientSettings.getClientLanguage() == null || clientSettings.getClientLanguage().isEmpty()) {
|
||||||
clientSettings.setClientLanguage(Constants.DefaultClientSettings().getClientLanguage());
|
clientSettings.setClientLanguage(Constants.DefaultClientSettings().getClientLanguage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (clientSettings.getHostName() == null || clientSettings.getHostName().equals("")) {
|
if (clientSettings.getHostName() == null || clientSettings.getHostName().isEmpty()) {
|
||||||
throw new TikTokLiveException("HostName can not be null");
|
throw new TikTokLiveException("HostName can not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -553,10 +553,3 @@ public class TikTokLiveClientBuilder implements LiveClientBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,11 +22,10 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok;
|
package io.github.jwdeveloper.tiktok;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.RankingUser;
|
import io.github.jwdeveloper.tiktok.data.models.RankingUser;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||||
import io.github.jwdeveloper.tiktok.models.ConnectionState;
|
|
||||||
import io.github.jwdeveloper.tiktok.live.LiveRoomInfo;
|
import io.github.jwdeveloper.tiktok.live.LiveRoomInfo;
|
||||||
|
import io.github.jwdeveloper.tiktok.models.ConnectionState;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
@@ -42,6 +41,8 @@ public class TikTokRoomInfo implements LiveRoomInfo {
|
|||||||
|
|
||||||
private int totalViewersCount;
|
private int totalViewersCount;
|
||||||
|
|
||||||
|
private long startTime;
|
||||||
|
|
||||||
private boolean ageRestricted;
|
private boolean ageRestricted;
|
||||||
|
|
||||||
private User host;
|
private User host;
|
||||||
@@ -69,5 +70,4 @@ public class TikTokRoomInfo implements LiveRoomInfo {
|
|||||||
usersRanking.clear();
|
usersRanking.clear();
|
||||||
usersRanking.addAll(rankingUsers);
|
usersRanking.addAll(rankingUsers);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -22,58 +22,30 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.http;
|
package io.github.jwdeveloper.tiktok.http;
|
||||||
|
|
||||||
import lombok.SneakyThrows;
|
|
||||||
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class HttpUtils
|
public class HttpUtils
|
||||||
{
|
{
|
||||||
public static String parseParameters(String url, Map<String,Object> parameters)
|
public static String parseParameters(String url, Map<String,Object> parameters)
|
||||||
{
|
{
|
||||||
var parameterString = "";
|
if (parameters.isEmpty())
|
||||||
if (!parameters.isEmpty()) {
|
return url;
|
||||||
var builder = new StringBuilder();
|
|
||||||
builder.append("?");
|
|
||||||
var first = false;
|
|
||||||
for (var param : parameters.entrySet()) {
|
|
||||||
|
|
||||||
if (first) {
|
return url+ "?" + parameters.entrySet().stream().map(entry -> entry.getKey()+"="+entry.getValue()).collect(Collectors.joining("&"));
|
||||||
builder.append("&");
|
|
||||||
}
|
|
||||||
builder.append(param.getKey()).append("=").append(param.getValue());
|
|
||||||
first = true;
|
|
||||||
}
|
|
||||||
parameterString = builder.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return url+parameterString;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SneakyThrows
|
|
||||||
public static String parseParametersEncode(String url, Map<String,Object> parameters)
|
public static String parseParametersEncode(String url, Map<String,Object> parameters)
|
||||||
{
|
{
|
||||||
|
if (parameters.isEmpty())
|
||||||
|
return url;
|
||||||
|
|
||||||
var parameterString = "";
|
return url+ "?" + parameters.entrySet().stream().map(entry -> {
|
||||||
if (!parameters.isEmpty()) {
|
String encodedKey = URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8);
|
||||||
var builder = new StringBuilder();
|
String encodedValue = URLEncoder.encode(entry.getValue().toString(), StandardCharsets.UTF_8);
|
||||||
builder.append("?");
|
return encodedKey+"="+encodedValue;
|
||||||
var first = false;
|
}).collect(Collectors.joining("&"));
|
||||||
for (var param : parameters.entrySet()) {
|
|
||||||
|
|
||||||
if (first) {
|
|
||||||
builder.append("&");
|
|
||||||
}
|
|
||||||
|
|
||||||
final String encodedKey = URLEncoder.encode(param.getKey(), StandardCharsets.UTF_8);
|
|
||||||
final String encodedValue = URLEncoder.encode(param.getValue().toString(), StandardCharsets.UTF_8);
|
|
||||||
builder.append(encodedKey).append("=").append(encodedValue);
|
|
||||||
first = true;
|
|
||||||
}
|
|
||||||
parameterString = builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
return url+parameterString;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,12 +22,9 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.http;
|
package io.github.jwdeveloper.tiktok.http;
|
||||||
|
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.*;
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
import io.github.jwdeveloper.tiktok.ClientSettings;
|
import io.github.jwdeveloper.tiktok.ClientSettings;
|
||||||
import io.github.jwdeveloper.tiktok.data.dto.TikTokUserInfo;
|
import io.github.jwdeveloper.tiktok.data.dto.TikTokUserInfo;
|
||||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveOfflineHostException;
|
|
||||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveRequestException;
|
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveRequestException;
|
||||||
import io.github.jwdeveloper.tiktok.live.LiveRoomMeta;
|
import io.github.jwdeveloper.tiktok.live.LiveRoomMeta;
|
||||||
import io.github.jwdeveloper.tiktok.mappers.LiveRoomMetaMapper;
|
import io.github.jwdeveloper.tiktok.mappers.LiveRoomMetaMapper;
|
||||||
@@ -35,7 +32,6 @@ import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class TikTokApiService {
|
public class TikTokApiService {
|
||||||
private final TikTokHttpClient tiktokHttpClient;
|
private final TikTokHttpClient tiktokHttpClient;
|
||||||
@@ -48,7 +44,6 @@ public class TikTokApiService {
|
|||||||
this.clientSettings = clientSettings;
|
this.clientSettings = clientSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void updateSessionId() {
|
public void updateSessionId() {
|
||||||
if (clientSettings.getSessionId() == null) {
|
if (clientSettings.getSessionId() == null) {
|
||||||
return;
|
return;
|
||||||
@@ -59,43 +54,45 @@ public class TikTokApiService {
|
|||||||
tiktokHttpClient.setSessionId(clientSettings.getSessionId());
|
tiktokHttpClient.setSessionId(clientSettings.getSessionId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String fetchRoomId(String userName) {
|
public void updateRoomId(String roomId)
|
||||||
var userInfo = fetchUserInfoFromTikTokApi(userName);
|
{
|
||||||
clientSettings.getClientParameters().put("room_id", userInfo.getRoomId());
|
clientSettings.getClientParameters().put("room_id", roomId);
|
||||||
logger.info("RoomID -> " + userInfo.getRoomId());
|
|
||||||
return userInfo.getRoomId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TikTokUserInfo fetchUserInfoFromTikTokApi(String userName) {
|
public TikTokUserInfo fetchUserInfoFromTikTokApi(String userName) {
|
||||||
|
|
||||||
var params = new HashMap<>(clientSettings.getClientParameters());
|
var params = new HashMap<>(clientSettings.getClientParameters());
|
||||||
params.put("uniqueId", userName);
|
params.put("uniqueId", userName);
|
||||||
params.put("sourceType", 54);
|
params.put("sourceType", 54);
|
||||||
JsonObject roomData = null;
|
JsonObject roomData;
|
||||||
try {
|
try {
|
||||||
roomData = tiktokHttpClient.getJsonFromTikTokApi("api-live/user/room/", params);
|
roomData = tiktokHttpClient.getJsonFromTikTokApi("api-live/user/room/", params);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
|
||||||
throw new TikTokLiveRequestException("Failed to fetch pre connection room information, it happens when TikTok temporary blocks you. Try to connect again in few minutes");
|
throw new TikTokLiveRequestException("Failed to fetch pre connection room information, it happens when TikTok temporary blocks you. Try to connect again in few minutes");
|
||||||
}
|
}
|
||||||
|
|
||||||
var message = roomData.get("message").getAsString();
|
var message = roomData.get("message").getAsString();
|
||||||
|
|
||||||
if (message.equals("params_error")) {
|
if (message.equals("params_error")) {
|
||||||
throw new TikTokLiveRequestException("fetchRoomIdFromTiktokApi -> Unable to fetch roomID, contact with developer");
|
throw new TikTokLiveRequestException("fetchRoomIdFromTiktokApi -> Unable to fetch roomID, contact the developer");
|
||||||
}
|
}
|
||||||
if (message.equals("user_not_found")) {
|
if (message.equals("user_not_found")) {
|
||||||
return new TikTokUserInfo(TikTokUserInfo.UserStatus.NotFound, "");
|
return new TikTokUserInfo(TikTokUserInfo.UserStatus.NotFound, "", -1);
|
||||||
}
|
}
|
||||||
//live -> status 2
|
//live -> status 2
|
||||||
//live paused -> 3
|
//live paused -> 3
|
||||||
//not live -> status 4
|
//not live -> status 4
|
||||||
var data = roomData.getAsJsonObject("data");
|
var element = roomData.get("data");
|
||||||
|
if (element.isJsonNull()) {
|
||||||
|
return new TikTokUserInfo(TikTokUserInfo.UserStatus.NotFound, "", -1);
|
||||||
|
}
|
||||||
|
var data = element.getAsJsonObject();
|
||||||
var user = data.getAsJsonObject("user");
|
var user = data.getAsJsonObject("user");
|
||||||
var roomId = user.get("roomId").getAsString();
|
var roomId = user.get("roomId").getAsString();
|
||||||
var status = user.get("status").getAsInt();
|
var status = user.get("status").getAsInt();
|
||||||
|
|
||||||
|
var liveRoom = data.getAsJsonObject("liveRoom");
|
||||||
|
long startTime = liveRoom.get("startTime").getAsLong();
|
||||||
|
|
||||||
var statusEnum = switch (status) {
|
var statusEnum = switch (status) {
|
||||||
case 2 -> TikTokUserInfo.UserStatus.Live;
|
case 2 -> TikTokUserInfo.UserStatus.Live;
|
||||||
case 3 -> TikTokUserInfo.UserStatus.LivePaused;
|
case 3 -> TikTokUserInfo.UserStatus.LivePaused;
|
||||||
@@ -103,7 +100,7 @@ public class TikTokApiService {
|
|||||||
default -> TikTokUserInfo.UserStatus.NotFound;
|
default -> TikTokUserInfo.UserStatus.NotFound;
|
||||||
};
|
};
|
||||||
|
|
||||||
return new TikTokUserInfo(statusEnum, roomId);
|
return new TikTokUserInfo(statusEnum, roomId, startTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,9 +22,8 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.http;
|
package io.github.jwdeveloper.tiktok.http;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
import java.util.stream.Collectors;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class TikTokCookieJar {
|
public class TikTokCookieJar {
|
||||||
private final Map<String, String> cookies;
|
private final Map<String, String> cookies;
|
||||||
@@ -40,13 +39,10 @@ public class TikTokCookieJar {
|
|||||||
cookies.put(key, value);
|
cookies.put(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String parseCookies()
|
public String parseCookies() {
|
||||||
{
|
return cookies.entrySet()
|
||||||
var sb = new StringBuilder();
|
.stream()
|
||||||
for(var entry : cookies.entrySet())
|
.map(entry -> entry.getKey()+"="+entry.getValue()+";")
|
||||||
{
|
.collect(Collectors.joining());
|
||||||
sb.append(entry.getKey()).append("=").append(entry.getValue()).append(";");
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,8 +45,7 @@ public class TikTokHttpClient {
|
|||||||
this.tikTokCookieJar = tikTokCookieJar;
|
this.tikTokCookieJar = tikTokCookieJar;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSessionId(String sessionId)
|
public void setSessionId(String sessionId) {
|
||||||
{
|
|
||||||
tikTokCookieJar.set("sessionid", sessionId);
|
tikTokCookieJar.set("sessionid", sessionId);
|
||||||
tikTokCookieJar.set("sessionid_ss", sessionId);
|
tikTokCookieJar.set("sessionid_ss", sessionId);
|
||||||
tikTokCookieJar.set("sid_tt", sessionId);
|
tikTokCookieJar.set("sid_tt", sessionId);
|
||||||
@@ -54,14 +53,12 @@ public class TikTokHttpClient {
|
|||||||
|
|
||||||
|
|
||||||
public String getLivestreamPage(String userName) {
|
public String getLivestreamPage(String userName) {
|
||||||
|
|
||||||
var url = Constants.TIKTOK_URL_WEB + "@" + userName + "/live/";
|
var url = Constants.TIKTOK_URL_WEB + "@" + userName + "/live/";
|
||||||
var get = getRequest(url, null);
|
var get = getRequest(url, null);
|
||||||
return get;
|
return get;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonObject getJsonFromTikTokApi(String path, Map<String,Object> params)
|
public JsonObject getJsonFromTikTokApi(String path, Map<String,Object> params) {
|
||||||
{
|
|
||||||
var get = getRequest(Constants.TIKTOK_URL_WEB + path, params);
|
var get = getRequest(Constants.TIKTOK_URL_WEB + path, params);
|
||||||
var json = JsonParser.parseString(get);
|
var json = JsonParser.parseString(get);
|
||||||
var jsonObject = json.getAsJsonObject();
|
var jsonObject = json.getAsJsonObject();
|
||||||
@@ -117,7 +114,6 @@ public class TikTokHttpClient {
|
|||||||
{
|
{
|
||||||
var split = cookie.split(";")[0].split("=");
|
var split = cookie.split(";")[0].split("=");
|
||||||
|
|
||||||
|
|
||||||
var key = split[0];
|
var key = split[0];
|
||||||
var value = split[1];
|
var value = split[1];
|
||||||
tikTokCookieJar.set(key, value);
|
tikTokCookieJar.set(key, value);
|
||||||
@@ -133,7 +129,6 @@ public class TikTokHttpClient {
|
|||||||
|
|
||||||
|
|
||||||
private String getSignedUrl(String url, Map<String, Object> parameters) {
|
private String getSignedUrl(String url, Map<String, Object> parameters) {
|
||||||
|
|
||||||
var fullUrl = HttpUtils.parseParameters(url,parameters);
|
var fullUrl = HttpUtils.parseParameters(url,parameters);
|
||||||
var signParams = new TreeMap<String,Object>();
|
var signParams = new TreeMap<String,Object>();
|
||||||
signParams.put("client", "ttlive-java");
|
signParams.put("client", "ttlive-java");
|
||||||
@@ -143,7 +138,6 @@ public class TikTokHttpClient {
|
|||||||
var request = requestFactory.setQueries(signParams);
|
var request = requestFactory.setQueries(signParams);
|
||||||
var content = request.get(Constants.TIKTOK_SIGN_API);
|
var content = request.get(Constants.TIKTOK_SIGN_API);
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var json = JsonParser.parseString(content);
|
var json = JsonParser.parseString(content);
|
||||||
var jsonObject = json.getAsJsonObject();
|
var jsonObject = json.getAsJsonObject();
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class TikTokHttpRequestFactory implements TikTokHttpRequest {
|
public class TikTokHttpRequestFactory implements TikTokHttpRequest {
|
||||||
private final CookieManager cookieManager;
|
private final CookieManager cookieManager;
|
||||||
@@ -122,18 +123,16 @@ public class TikTokHttpRequestFactory implements TikTokHttpRequest {
|
|||||||
public TikTokHttpRequest setQueries(Map<String, Object> queries) {
|
public TikTokHttpRequest setQueries(Map<String, Object> queries) {
|
||||||
if (queries == null)
|
if (queries == null)
|
||||||
return this;
|
return this;
|
||||||
var testMap = new TreeMap<String, Object>(queries);
|
var testMap = new TreeMap<>(queries);
|
||||||
query = String.join("&", testMap.entrySet().stream().map(x ->
|
query = testMap.entrySet().stream().map(x -> {
|
||||||
{
|
|
||||||
var key = x.getKey();
|
var key = x.getKey();
|
||||||
var value = "";
|
|
||||||
try {
|
try {
|
||||||
value = URLEncoder.encode(x.getValue().toString(), StandardCharsets.UTF_8);
|
return key+"="+URLEncoder.encode(x.getValue().toString(), StandardCharsets.UTF_8);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
return key + "=";
|
||||||
}
|
}
|
||||||
return key + "=" + value;
|
}).collect(Collectors.joining("&"));
|
||||||
}).toList());
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,10 +161,7 @@ public class TikTokHttpRequestFactory implements TikTokHttpRequest {
|
|||||||
var map = new HashMap<String, List<String>>();
|
var map = new HashMap<String, List<String>>();
|
||||||
map.put(key, List.of(value));
|
map.put(key, List.of(value));
|
||||||
cookieManager.put(uri, map);
|
cookieManager.put(uri, map);
|
||||||
|
|
||||||
}
|
}
|
||||||
return response.body();
|
return response.body();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -115,7 +115,7 @@ public class TikTokListenersManager implements ListenersManager {
|
|||||||
throw new TikTokEventListenerMethodException(e);
|
throw new TikTokEventListenerMethodException(e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
eventsMap.computeIfAbsent(eventClazz, (a) -> new ArrayList<EventConsumer<?>>()).add(eventMethodRef);
|
eventsMap.computeIfAbsent(eventClazz, (a) -> new ArrayList<>()).add(eventMethodRef);
|
||||||
}
|
}
|
||||||
return new ListenerBindingModel(listener, eventsMap);
|
return new ListenerBindingModel(listener, eventsMap);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.mappers;
|
package io.github.jwdeveloper.tiktok.mappers;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package io.github.jwdeveloper.tiktok.http;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class HttpUtilsTest
|
||||||
|
{
|
||||||
|
@Test
|
||||||
|
public void parseParameters_EmptyParameters_ShouldHaveNoParameters()
|
||||||
|
{
|
||||||
|
String parsed = HttpUtils.parseParameters("https://webcast.tiktok.com/webcast/im/fetch/", new HashMap<>());
|
||||||
|
|
||||||
|
Assertions.assertEquals("https://webcast.tiktok.com/webcast/im/fetch/", parsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void parseParameters_ValidParameters_ShouldConstructValidURL()
|
||||||
|
{
|
||||||
|
LinkedHashMap<String, Object> testMap = new LinkedHashMap<>();
|
||||||
|
testMap.put("room_id", 1);
|
||||||
|
testMap.put("uniqueId", "randomName");
|
||||||
|
String parsed = HttpUtils.parseParameters("https://webcast.tiktok.com/webcast/im/fetch/", testMap);
|
||||||
|
|
||||||
|
Assertions.assertEquals("https://webcast.tiktok.com/webcast/im/fetch/?room_id=1&uniqueId=randomName", parsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void parseParametersEncode_EmptyParameters_ShouldHaveNoParameters()
|
||||||
|
{
|
||||||
|
String parsed = HttpUtils.parseParametersEncode("https://webcast.tiktok.com/webcast/im/fetch/", new HashMap<>());
|
||||||
|
|
||||||
|
Assertions.assertEquals("https://webcast.tiktok.com/webcast/im/fetch/", parsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void parseParametersEncode_ValidParameters_ShouldConstructValidURL()
|
||||||
|
{
|
||||||
|
LinkedHashMap<String, Object> testMap = new LinkedHashMap<>();
|
||||||
|
testMap.put("room_id", 1);
|
||||||
|
testMap.put("root_referer", "https://www.tiktok.com/");
|
||||||
|
String parsed = HttpUtils.parseParametersEncode("https://webcast.tiktok.com/webcast/im/fetch/", testMap);
|
||||||
|
|
||||||
|
Assertions.assertEquals("https://webcast.tiktok.com/webcast/im/fetch/?room_id=1&root_referer=https%3A%2F%2Fwww.tiktok.com%2F", parsed);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,7 +24,6 @@ package io.github.jwdeveloper.tiktok.http;
|
|||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import io.github.jwdeveloper.tiktok.ClientSettings;
|
import io.github.jwdeveloper.tiktok.ClientSettings;
|
||||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException;
|
|
||||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveRequestException;
|
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveRequestException;
|
||||||
import io.github.jwdeveloper.tiktok.live.LiveRoomMeta;
|
import io.github.jwdeveloper.tiktok.live.LiveRoomMeta;
|
||||||
import io.github.jwdeveloper.tiktok.mappers.LiveRoomMetaMapper;
|
import io.github.jwdeveloper.tiktok.mappers.LiveRoomMetaMapper;
|
||||||
@@ -84,28 +83,6 @@ public class TikTokApiServiceTest
|
|||||||
verify(tiktokHttpClient, times(1)).setSessionId("validSessionId");
|
verify(tiktokHttpClient, times(1)).setSessionId("validSessionId");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// @Test
|
|
||||||
void fetchRoomId_ValidResponse_ReturnsRoomId() throws Exception {
|
|
||||||
String expectedRoomId = "123456";
|
|
||||||
String htmlResponse = "room_id=" + expectedRoomId ;
|
|
||||||
when(tiktokHttpClient.getLivestreamPage(anyString())).thenReturn(htmlResponse);
|
|
||||||
|
|
||||||
String roomId = tikTokApiService.fetchRoomId("username");
|
|
||||||
|
|
||||||
assertEquals(expectedRoomId, roomId);
|
|
||||||
verify(clientSettings.getClientParameters()).put("room_id", expectedRoomId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Test
|
|
||||||
void fetchRoomId_ExceptionThrown_ThrowsTikTokLiveRequestException() throws Exception {
|
|
||||||
when(tiktokHttpClient.getLivestreamPage(anyString())).thenThrow(new Exception("some exception"));
|
|
||||||
|
|
||||||
assertThrows(TikTokLiveRequestException.class, () -> {
|
|
||||||
tikTokApiService.fetchRoomId("username");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//@Test
|
//@Test
|
||||||
void fetchRoomInfo_ValidResponse_ReturnsLiveRoomMeta() throws Exception {
|
void fetchRoomInfo_ValidResponse_ReturnsLiveRoomMeta() throws Exception {
|
||||||
HashMap<String, Object> clientParameters = new HashMap<>();
|
HashMap<String, Object> clientParameters = new HashMap<>();
|
||||||
|
|||||||
@@ -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.0.11-Release</version>
|
<version>1.0.13-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -69,7 +69,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.0.11-Release</version>
|
<version>1.0.12-Release</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
@@ -86,7 +86,7 @@ dependencyResolutionManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.github.jwdeveloper.TikTok-Live-Java:Client:1.0.11-Release'
|
implementation 'com.github.jwdeveloper.TikTok-Live-Java:Client:1.0.12-Release'
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -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.0.11-Release</version>
|
<version>1.0.13-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -55,9 +55,4 @@ public class ApiServiceMock extends TikTokApiService {
|
|||||||
return WebcastResponse.newBuilder().build();
|
return WebcastResponse.newBuilder().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String fetchRoomId(String userName) {
|
|
||||||
return "mock-room-id";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.0.11-Release</version>
|
<version>1.0.13-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>Tools-EventsWebViewer</artifactId>
|
<artifactId>Tools-EventsWebViewer</artifactId>
|
||||||
|
|||||||
@@ -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.0.11-Release</version>
|
<version>1.0.13-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -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.0.11-Release</version>
|
<version>1.0.13-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
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.0.11-Release</version>
|
<version>1.0.13-Release</version>
|
||||||
<modules>
|
<modules>
|
||||||
<module>API</module>
|
<module>API</module>
|
||||||
<module>Client</module>
|
<module>Client</module>
|
||||||
|
|||||||
Reference in New Issue
Block a user