Compare commits

...

11 Commits

Author SHA1 Message Date
Jacek W
9a66d240bc Merge pull request #85 from jwdeveloper/develop-1.7.2
Develop 1.7.2
2024-06-24 08:38:22 +02:00
kohlerpop1
d825803187 Added while loop condition so it does not exit when getConnectionState returns Disconnected and stopOnDisconnect is false! 2024-06-23 23:06:05 -04:00
kohlerpop1
77c9cd6b52 Converted Consumer to BiConsumer to also accept liveClient! 2024-06-20 16:51:42 -04:00
kohlerpop1
0329d3cfeb Removed useless imports and altered logger message! 2024-06-18 22:01:47 -04:00
kohlerpop1
26659bb37d Removed not needed/used RecorderSettings#startOnConnected 2024-06-18 15:36:03 -04:00
kohlerpop1
0b9852c4d4 Moved ActionResult#message to top of toJson() for easier reading
Change Recording settings to accept an output file instead of directory and filename
2024-06-18 15:21:05 -04:00
GitHub Action
31618a16ba Update version in pom.xml 2024-06-07 10:55:14 +00:00
GitHub Action
243791f6b8 Update version in pom.xml 2024-06-02 20:11:19 +00:00
David Kohler
4f74a0f1b7 MINOR 2024-06-02 16:09:45 -04:00
GitHub Action
d1eec34fca Update version in pom.xml 2024-06-02 20:07:58 +00:00
David Kohler
82196ef8e3 MINOR: Merge pull request #84 from jwdeveloper/develop-1.6.4
Develop 1.6.4
2024-06-02 16:06:24 -04:00
13 changed files with 35 additions and 40 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.6.3-Release</version> <version>1.7.1-Release</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>API</artifactId> <artifactId>API</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.6.3-Release</version> <version>1.7.1-Release</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@@ -100,8 +100,8 @@ public class ActionResult<T> {
public JsonObject toJson() { public JsonObject toJson() {
JsonObject map = new JsonObject(); JsonObject map = new JsonObject();
map.addProperty("success", success); map.addProperty("success", success);
map.add("content", gson.toJsonTree(content));
map.addProperty("message", message); map.addProperty("message", message);
map.add("content", gson.toJsonTree(content));
map.add("previous", hasPrevious() ? previous.toJson() : null); map.add("previous", hasPrevious() ? previous.toJson() : null);
return map; return map;
} }

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.6.3-Release</version> <version>1.7.1-Release</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -75,7 +75,7 @@
<dependency> <dependency>
<groupId>io.github.jwdeveloper.tiktok</groupId> <groupId>io.github.jwdeveloper.tiktok</groupId>
<artifactId>extension-collector</artifactId> <artifactId>extension-collector</artifactId>
<version>1.6.3-Release</version> <version>1.7.1-Release</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@@ -26,6 +26,8 @@ package io.github.jwdeveloper.tiktok;
import io.github.jwdeveloper.tiktok.extension.recorder.TikTokLiveRecorder; import io.github.jwdeveloper.tiktok.extension.recorder.TikTokLiveRecorder;
import io.github.jwdeveloper.tiktok.extension.recorder.impl.event.TikTokLiveRecorderStartedEvent; import io.github.jwdeveloper.tiktok.extension.recorder.impl.event.TikTokLiveRecorderStartedEvent;
import java.io.File;
public class RecorderExample { public class RecorderExample {
public static void main(String[] args) { public static void main(String[] args) {
@@ -39,11 +41,10 @@ public class RecorderExample {
{ {
event.getException().printStackTrace(); event.getException().printStackTrace();
}) })
.addListener(TikTokLiveRecorder.use(recorderSettings -> .addListener(TikTokLiveRecorder.use((recorderSettings, liveClient) ->
{ {
recorderSettings.setFfmpegPath("C:\\Users\\ja\\IdeaProjects\\TikTokLiveJava\\extension-recorder\\libs\\ffmpeg.exe"); recorderSettings.setFfmpegPath("C:\\Users\\ja\\IdeaProjects\\TikTokLiveJava\\extension-recorder\\libs\\ffmpeg.exe");
recorderSettings.setOutputPath("C:\\Users\\ja\\IdeaProjects\\TikTokLiveJava\\extension-recorder\\out"); recorderSettings.setOutputFile(new File("C:\\Users\\ja\\IdeaProjects\\TikTokLiveJava\\extension-recorder\\out", "test.flv"));
recorderSettings.setOutputFileName("test.flv");
})) }))
.onEvent(TikTokLiveRecorderStartedEvent.class, (liveClient, event) -> .onEvent(TikTokLiveRecorderStartedEvent.class, (liveClient, event) ->
{ {

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.6.0-Release</version> <version>1.7.0-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.6.3-Release</version> <version>1.7.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.6.3-Release</version> <version>1.7.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.6.3-Release</version> <version>1.7.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.6.3-Release</version> <version>1.7.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

@@ -25,18 +25,19 @@ package io.github.jwdeveloper.tiktok.extension.recorder;
import io.github.jwdeveloper.tiktok.extension.recorder.api.LiveRecorder; import io.github.jwdeveloper.tiktok.extension.recorder.api.LiveRecorder;
import io.github.jwdeveloper.tiktok.extension.recorder.impl.RecorderListener; import io.github.jwdeveloper.tiktok.extension.recorder.impl.RecorderListener;
import io.github.jwdeveloper.tiktok.extension.recorder.impl.data.RecorderSettings; import io.github.jwdeveloper.tiktok.extension.recorder.impl.data.RecorderSettings;
import io.github.jwdeveloper.tiktok.live.LiveClient;
import java.util.function.Consumer; import java.util.function.*;
public class TikTokLiveRecorder public class TikTokLiveRecorder
{ {
public static LiveRecorder use(Consumer<RecorderSettings> consumer) public static LiveRecorder use(BiConsumer<RecorderSettings, LiveClient> consumer)
{ {
return new RecorderListener(consumer); return new RecorderListener(consumer);
} }
public static LiveRecorder use() public static LiveRecorder use()
{ {
return use(x ->{}); return use((x,y) ->{});
} }
} }

View File

@@ -37,26 +37,23 @@ import io.github.jwdeveloper.tiktok.models.ConnectionState;
import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HttpsURLConnection;
import java.io.*; import java.io.*;
import java.net.URL; import java.net.URL;
import java.util.concurrent.TimeUnit; import java.util.function.*;
import java.util.function.Consumer;
import static java.nio.charset.StandardCharsets.UTF_8;
public class RecorderListener implements LiveRecorder { public class RecorderListener implements LiveRecorder {
private final Consumer<RecorderSettings> consumer; private final BiConsumer<RecorderSettings, LiveClient> consumer;
private RecorderSettings settings; private RecorderSettings settings;
private DownloadData downloadData; private DownloadData downloadData;
private Thread liveDownloadThread; private Thread liveDownloadThread;
public RecorderListener(Consumer<RecorderSettings> consumer) { public RecorderListener(BiConsumer<RecorderSettings, LiveClient> consumer) {
this.consumer = consumer; this.consumer = consumer;
} }
@TikTokEventObserver @TikTokEventObserver
private void onResponse(LiveClient liveClient, TikTokRoomDataResponseEvent event) { private void onResponse(LiveClient liveClient, TikTokRoomDataResponseEvent event) {
settings = RecorderSettings.DEFAULT(); settings = RecorderSettings.DEFAULT();
consumer.accept(settings); consumer.accept(settings, liveClient);
var json = event.getLiveData().getJson(); var json = event.getLiveData().getJson();
@@ -76,10 +73,9 @@ public class RecorderListener implements LiveRecorder {
if (isConnected()) if (isConnected())
return; return;
liveDownloadThread = new Thread(() -> { liveDownloadThread = new Thread(() -> {
try { try {
liveClient.getLogger().info("Recording started"); liveClient.getLogger().info("Recording started "+liveClient.getRoomInfo().getHostName());
var url = new URL(downloadData.getFullUrl()); var url = new URL(downloadData.getFullUrl());
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
var headers = LiveClientSettings.DefaultRequestHeaders(); var headers = LiveClientSettings.DefaultRequestHeaders();
@@ -87,8 +83,7 @@ public class RecorderListener implements LiveRecorder {
connection.setRequestProperty(entry.getKey(), entry.getValue()); connection.setRequestProperty(entry.getKey(), entry.getValue());
} }
var path = settings.getOutputPath() + File.separator + settings.getOutputFileName(); var file = settings.getOutputFile();
var file = new File(path);
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
file.createNewFile(); file.createNewFile();
@@ -98,7 +93,7 @@ public class RecorderListener implements LiveRecorder {
) { ) {
byte[] dataBuffer = new byte[1024]; byte[] dataBuffer = new byte[1024];
int bytesRead; int bytesRead;
while (liveClient.getRoomInfo().getConnectionState() == ConnectionState.CONNECTED && (bytesRead = in.read(dataBuffer)) != -1) { while ((!settings.isStopOnDisconnect() || liveClient.getRoomInfo().getConnectionState() == ConnectionState.CONNECTED) && (bytesRead = in.read(dataBuffer)) != -1) {
fos.write(dataBuffer, 0, bytesRead); fos.write(dataBuffer, 0, bytesRead);
fos.flush(); fos.flush();
} }
@@ -113,10 +108,9 @@ public class RecorderListener implements LiveRecorder {
var recordingStartedEvent = new TikTokLiveRecorderStartedEvent(downloadData); var recordingStartedEvent = new TikTokLiveRecorderStartedEvent(downloadData);
liveClient.publishEvent(recordingStartedEvent); liveClient.publishEvent(recordingStartedEvent);
if (recordingStartedEvent.isCanceled()) { if (recordingStartedEvent.isCanceled())
liveClient.getLogger().info("Recording cancelled"); liveClient.getLogger().info("Recording cancelled");
return; else
}
liveDownloadThread.start(); liveDownloadThread.start();
} }

View File

@@ -27,6 +27,7 @@ import io.github.jwdeveloper.tiktok.extension.recorder.impl.enums.LiveFormat;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import java.io.File;
import java.util.function.Function; import java.util.function.Function;
@Getter @Getter
@@ -36,10 +37,8 @@ public class RecorderSettings {
private String ffmpegPath; private String ffmpegPath;
private String quality; private String quality;
private String format; private String format;
private String outputPath; private File outputFile;
private String outputFileName;
private Function<String,DownloadData> prepareDownloadData; private Function<String,DownloadData> prepareDownloadData;
private boolean startOnConnected;
private boolean stopOnDisconnect = true; private boolean stopOnDisconnect = true;
public static RecorderSettings DEFAULT() { public static RecorderSettings DEFAULT() {

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