Compare commits

..

7 Commits

Author SHA1 Message Date
JW
c12f3cc4dc . 2023-12-20 20:24:33 +01:00
Jacek W
b2305b7bed Merge pull request #39 from kohlerpop1/kohlerpop1-fixes-updates
Added startTime to LiveRoomInfo to determine when the stream started!
2023-12-20 20:17:00 +01:00
kohlerpop1
7b911838a2 Added startTime to LiveRoomInfo to determine when the stream started! 2023-12-20 14:07:53 -05:00
Jacek W
e44cb71869 Update README.md 2023-12-19 21:57:24 +01:00
GitHub Action
af8c689417 Update version in pom.xml 2023-12-19 20:53:26 +00:00
Jacek W
81ac92fb33 Merge pull request #37 from jwdeveloper/develop-1-0-12
Including toUser in TikTokGiftEvent
2023-12-19 21:51:06 +01:00
Jacek W
534cb7906d Merge pull request #36 from jwdeveloper/develop-1-0-12
Develop 1 0 12
2023-12-19 21:43:07 +01:00
18 changed files with 40 additions and 77 deletions

View File

@@ -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.12-Release</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>API</artifactId> <artifactId>API</artifactId>

View File

@@ -33,6 +33,8 @@ public class TikTokUserInfo
String roomId; String roomId;
long startTime;
public enum UserStatus public enum UserStatus
{ {
NotFound, NotFound,

View File

@@ -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();

View File

@@ -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.12-Release</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@@ -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();

View File

@@ -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;
} }
} }

View File

@@ -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);
} }
} }

View File

@@ -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,24 +54,19 @@ 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");
} }
@@ -86,7 +76,7 @@ public class TikTokApiService {
throw new TikTokLiveRequestException("fetchRoomIdFromTiktokApi -> Unable to fetch roomID, contact with developer"); throw new TikTokLiveRequestException("fetchRoomIdFromTiktokApi -> Unable to fetch roomID, contact with 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
@@ -96,6 +86,9 @@ public class TikTokApiService {
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 +96,7 @@ public class TikTokApiService {
default -> TikTokUserInfo.UserStatus.NotFound; default -> TikTokUserInfo.UserStatus.NotFound;
}; };
return new TikTokUserInfo(statusEnum, roomId); return new TikTokUserInfo(statusEnum, roomId, startTime);
} }

View File

@@ -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;

View File

@@ -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<>();

View File

@@ -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.12-Release</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@@ -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'
} }
``` ```

View File

@@ -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.12-Release</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@@ -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";
}
} }

View File

@@ -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.12-Release</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>Tools-EventsWebViewer</artifactId> <artifactId>Tools-EventsWebViewer</artifactId>

View File

@@ -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.12-Release</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@@ -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.12-Release</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@@ -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.12-Release</version>
<modules> <modules>
<module>API</module> <module>API</module>
<module>Client</module> <module>Client</module>