Compare commits

...

6 Commits

Author SHA1 Message Date
kohlerpop1
735bdfbb10 Clarify Priority calling order
Altered pre-connection logic to make reason settable
Optionally cancel connection if recorder is used and fails to find record url!
2025-02-19 13:18:25 -05:00
GitHub Action
28ef3562b6 Update version in pom.xml 2025-02-15 00:52:55 +00:00
David Kohler
3b6b381e31 Update README.md 2025-02-14 19:51:18 -05:00
David Kohler
86a79d687e Merge pull request #120 from jwdeveloper/develop-1.9.1
Fix clientParams and send cookies when present and not null to specific requests for 18+ livestreams.
2025-02-14 19:50:34 -05:00
kohlerpop1
65a651d4b8 Fix clientParams and send cookies when present and not null to specific requests for 18+ livestreams. 2025-02-14 19:44:32 -05:00
GitHub Action
8bda5d789c Update version in pom.xml 2025-02-11 22:09:28 +00:00
18 changed files with 81 additions and 24 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.8.14-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>

View File

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

View File

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

View File

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

View File

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

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.8.14-Release</version> <version>1.9.1-Release</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

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

View File

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

View File

@@ -103,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);

View File

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

View File

@@ -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.9.0-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.9.0-Release' implementation 'com.github.jwdeveloper.TikTok-Live-Java:Client:1.9.1-Release'
} }
``` ```

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.8.14-Release</version> <version>1.9.1-Release</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@@ -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.14-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.14-Release</version> <version>1.9.1-Release</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>

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.8.14-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>

View File

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

View File

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

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

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.8.14-Release</version> <version>1.9.1-Release</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>