mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 16:59:39 -05:00
Compare commits
11 Commits
develop-1.
...
1.7.2-Rele
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a66d240bc | ||
|
|
d825803187 | ||
|
|
77c9cd6b52 | ||
|
|
0329d3cfeb | ||
|
|
26659bb37d | ||
|
|
0b9852c4d4 | ||
|
|
31618a16ba | ||
|
|
243791f6b8 | ||
|
|
4f74a0f1b7 | ||
|
|
d1eec34fca | ||
|
|
82196ef8e3 |
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>TikTokLiveJava</artifactId>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<version>1.6.3-Release</version>
|
||||
<version>1.7.1-Release</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>API</artifactId>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>TikTokLiveJava</artifactId>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<version>1.6.3-Release</version>
|
||||
<version>1.7.1-Release</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -100,8 +100,8 @@ public class ActionResult<T> {
|
||||
public JsonObject toJson() {
|
||||
JsonObject map = new JsonObject();
|
||||
map.addProperty("success", success);
|
||||
map.add("content", gson.toJsonTree(content));
|
||||
map.addProperty("message", message);
|
||||
map.add("content", gson.toJsonTree(content));
|
||||
map.add("previous", hasPrevious() ? previous.toJson() : null);
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
<parent>
|
||||
<artifactId>TikTokLiveJava</artifactId>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<version>1.6.3-Release</version>
|
||||
<version>1.7.1-Release</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@@ -75,7 +75,7 @@
|
||||
<dependency>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<artifactId>extension-collector</artifactId>
|
||||
<version>1.6.3-Release</version>
|
||||
<version>1.7.1-Release</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -26,6 +26,8 @@ package io.github.jwdeveloper.tiktok;
|
||||
import io.github.jwdeveloper.tiktok.extension.recorder.TikTokLiveRecorder;
|
||||
import io.github.jwdeveloper.tiktok.extension.recorder.impl.event.TikTokLiveRecorderStartedEvent;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class RecorderExample {
|
||||
|
||||
public static void main(String[] args) {
|
||||
@@ -39,11 +41,10 @@ public class RecorderExample {
|
||||
{
|
||||
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.setOutputPath("C:\\Users\\ja\\IdeaProjects\\TikTokLiveJava\\extension-recorder\\out");
|
||||
recorderSettings.setOutputFileName("test.flv");
|
||||
recorderSettings.setOutputFile(new File("C:\\Users\\ja\\IdeaProjects\\TikTokLiveJava\\extension-recorder\\out", "test.flv"));
|
||||
}))
|
||||
.onEvent(TikTokLiveRecorderStartedEvent.class, (liveClient, event) ->
|
||||
{
|
||||
|
||||
@@ -70,7 +70,7 @@ Maven
|
||||
<dependency>
|
||||
<groupId>com.github.jwdeveloper.TikTok-Live-Java</groupId>
|
||||
<artifactId>Client</artifactId>
|
||||
<version>1.6.0-Release</version>
|
||||
<version>1.7.0-Release</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>TikTokLiveJava</artifactId>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<version>1.6.3-Release</version>
|
||||
<version>1.7.1-Release</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<artifactId>TikTokLiveJava</artifactId>
|
||||
<version>1.6.3-Release</version>
|
||||
<version>1.7.1-Release</version>
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<dependency>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<artifactId>API</artifactId>
|
||||
<version>1.6.3-Release</version>
|
||||
<version>1.7.1-Release</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>TikTokLiveJava</artifactId>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<version>1.6.3-Release</version>
|
||||
<version>1.7.1-Release</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>extension-recorder</artifactId>
|
||||
|
||||
@@ -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.impl.RecorderListener;
|
||||
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 static LiveRecorder use(Consumer<RecorderSettings> consumer)
|
||||
public static LiveRecorder use(BiConsumer<RecorderSettings, LiveClient> consumer)
|
||||
{
|
||||
return new RecorderListener(consumer);
|
||||
}
|
||||
|
||||
public static LiveRecorder use()
|
||||
{
|
||||
return use(x ->{});
|
||||
return use((x,y) ->{});
|
||||
}
|
||||
}
|
||||
@@ -37,26 +37,23 @@ import io.github.jwdeveloper.tiktok.models.ConnectionState;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import java.util.function.*;
|
||||
|
||||
public class RecorderListener implements LiveRecorder {
|
||||
|
||||
private final Consumer<RecorderSettings> consumer;
|
||||
private final BiConsumer<RecorderSettings, LiveClient> consumer;
|
||||
private RecorderSettings settings;
|
||||
private DownloadData downloadData;
|
||||
private Thread liveDownloadThread;
|
||||
|
||||
public RecorderListener(Consumer<RecorderSettings> consumer) {
|
||||
public RecorderListener(BiConsumer<RecorderSettings, LiveClient> consumer) {
|
||||
this.consumer = consumer;
|
||||
}
|
||||
|
||||
@TikTokEventObserver
|
||||
private void onResponse(LiveClient liveClient, TikTokRoomDataResponseEvent event) {
|
||||
settings = RecorderSettings.DEFAULT();
|
||||
consumer.accept(settings);
|
||||
consumer.accept(settings, liveClient);
|
||||
|
||||
var json = event.getLiveData().getJson();
|
||||
|
||||
@@ -76,10 +73,9 @@ public class RecorderListener implements LiveRecorder {
|
||||
if (isConnected())
|
||||
return;
|
||||
|
||||
|
||||
liveDownloadThread = new Thread(() -> {
|
||||
try {
|
||||
liveClient.getLogger().info("Recording started");
|
||||
liveClient.getLogger().info("Recording started "+liveClient.getRoomInfo().getHostName());
|
||||
var url = new URL(downloadData.getFullUrl());
|
||||
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
||||
var headers = LiveClientSettings.DefaultRequestHeaders();
|
||||
@@ -87,8 +83,7 @@ public class RecorderListener implements LiveRecorder {
|
||||
connection.setRequestProperty(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
var path = settings.getOutputPath() + File.separator + settings.getOutputFileName();
|
||||
var file = new File(path);
|
||||
var file = settings.getOutputFile();
|
||||
file.getParentFile().mkdirs();
|
||||
file.createNewFile();
|
||||
|
||||
@@ -98,7 +93,7 @@ public class RecorderListener implements LiveRecorder {
|
||||
) {
|
||||
byte[] dataBuffer = new byte[1024];
|
||||
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.flush();
|
||||
}
|
||||
@@ -113,10 +108,9 @@ public class RecorderListener implements LiveRecorder {
|
||||
|
||||
var recordingStartedEvent = new TikTokLiveRecorderStartedEvent(downloadData);
|
||||
liveClient.publishEvent(recordingStartedEvent);
|
||||
if (recordingStartedEvent.isCanceled()) {
|
||||
if (recordingStartedEvent.isCanceled())
|
||||
liveClient.getLogger().info("Recording cancelled");
|
||||
return;
|
||||
}
|
||||
else
|
||||
liveDownloadThread.start();
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import io.github.jwdeveloper.tiktok.extension.recorder.impl.enums.LiveFormat;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Getter
|
||||
@@ -36,10 +37,8 @@ public class RecorderSettings {
|
||||
private String ffmpegPath;
|
||||
private String quality;
|
||||
private String format;
|
||||
private String outputPath;
|
||||
private String outputFileName;
|
||||
private File outputFile;
|
||||
private Function<String,DownloadData> prepareDownloadData;
|
||||
private boolean startOnConnected;
|
||||
private boolean stopOnDisconnect = true;
|
||||
|
||||
public static RecorderSettings DEFAULT() {
|
||||
|
||||
Reference in New Issue
Block a user