mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 16:59:39 -05:00
Compare commits
6 Commits
1.5.2-Rele
...
1.5.4-Rele
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
498d34a90b | ||
|
|
103ed7e3ed | ||
|
|
67e70c34bc | ||
|
|
786c24d267 | ||
|
|
966d2f65d8 | ||
|
|
7ba7143f5a |
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>TikTokLiveJava</artifactId>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<version>1.5.1-Release</version>
|
||||
<version>1.5.3-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.5.1-Release</version>
|
||||
<version>1.5.3-Release</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ public class TikTokWebSocketListener extends WebSocketClient {
|
||||
} catch (Exception e) {
|
||||
tikTokEventHandler.publish(tikTokLiveClient, new TikTokErrorEvent(e));
|
||||
}
|
||||
if (isNotClosing()) {
|
||||
if (isOpen()) {
|
||||
sendPing();
|
||||
}
|
||||
}
|
||||
@@ -79,8 +79,7 @@ public class TikTokWebSocketListener extends WebSocketClient {
|
||||
pushFrameBuilder.setPayloadType("ack");
|
||||
pushFrameBuilder.setLogId(websocketPushFrame.getLogId());
|
||||
pushFrameBuilder.setPayload(webcastResponse.getInternalExtBytes());
|
||||
if (isNotClosing())
|
||||
{
|
||||
if (isOpen()) {
|
||||
this.send(pushFrameBuilder.build().toByteArray());
|
||||
}
|
||||
}
|
||||
@@ -90,7 +89,7 @@ public class TikTokWebSocketListener extends WebSocketClient {
|
||||
@Override
|
||||
public void onOpen(ServerHandshake serverHandshake) {
|
||||
tikTokEventHandler.publish(tikTokLiveClient, new TikTokConnectedEvent());
|
||||
if (isNotClosing()) {
|
||||
if (isOpen()) {
|
||||
sendPing();
|
||||
}
|
||||
}
|
||||
@@ -104,7 +103,7 @@ public class TikTokWebSocketListener extends WebSocketClient {
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
tikTokEventHandler.publish(tikTokLiveClient, new TikTokErrorEvent(error));
|
||||
if (isNotClosing()) {
|
||||
if (isOpen()) {
|
||||
sendPing();
|
||||
}
|
||||
}
|
||||
@@ -129,10 +128,6 @@ public class TikTokWebSocketListener extends WebSocketClient {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isNotClosing() {
|
||||
return !isClosed() && !isClosing();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(String s) {
|
||||
// System.err.println(s);
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
<parent>
|
||||
<artifactId>TikTokLiveJava</artifactId>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<version>1.5.1-Release</version>
|
||||
<version>1.5.3-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.5.1-Release</version>
|
||||
<version>1.5.3-Release</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>TikTokLiveJava</artifactId>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<version>1.5.1-Release</version>
|
||||
<version>1.5.3-Release</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<artifactId>TikTokLiveJava</artifactId>
|
||||
<version>1.5.1-Release</version>
|
||||
<version>1.5.3-Release</version>
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<dependency>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<artifactId>API</artifactId>
|
||||
<version>1.5.1-Release</version>
|
||||
<version>1.5.3-Release</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>TikTokLiveJava</artifactId>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<version>1.5.1-Release</version>
|
||||
<version>1.5.3-Release</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>extension-recorder</artifactId>
|
||||
|
||||
@@ -30,6 +30,7 @@ import io.github.jwdeveloper.tiktok.data.settings.LiveClientSettings;
|
||||
import io.github.jwdeveloper.tiktok.extension.recorder.api.LiveRecorder;
|
||||
import io.github.jwdeveloper.tiktok.extension.recorder.impl.data.*;
|
||||
import io.github.jwdeveloper.tiktok.extension.recorder.impl.enums.LiveQuality;
|
||||
import io.github.jwdeveloper.tiktok.extension.recorder.impl.event.TikTokLiveRecorderStartedEvent;
|
||||
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||
import io.github.jwdeveloper.tiktok.models.ConnectionState;
|
||||
|
||||
@@ -60,7 +61,9 @@ public class RecorderListener implements LiveRecorder {
|
||||
var json = event.getLiveData().getJson();
|
||||
|
||||
liveClient.getLogger().info("Searching for live download url");
|
||||
downloadData = settings.getPrepareDownloadData() != null ? settings.getPrepareDownloadData().apply(json) : mapToDownloadData(json);
|
||||
downloadData = settings.getPrepareDownloadData() != null ?
|
||||
settings.getPrepareDownloadData().apply(json) :
|
||||
mapToDownloadData(json);
|
||||
|
||||
if (downloadData.getDownloadLiveUrl().isEmpty())
|
||||
liveClient.getLogger().warning("Unable to find download live url!");
|
||||
@@ -72,8 +75,11 @@ public class RecorderListener implements LiveRecorder {
|
||||
private void onConnected(LiveClient liveClient, TikTokConnectedEvent event) {
|
||||
if (isConnected())
|
||||
return;
|
||||
|
||||
|
||||
liveDownloadThread = new Thread(() -> {
|
||||
try {
|
||||
liveClient.getLogger().info("Recording started");
|
||||
var url = new URL(downloadData.getFullUrl());
|
||||
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
||||
var headers = LiveClientSettings.DefaultRequestHeaders();
|
||||
@@ -87,8 +93,8 @@ public class RecorderListener implements LiveRecorder {
|
||||
file.createNewFile();
|
||||
|
||||
try (
|
||||
var in = connection.getInputStream();
|
||||
var fos = new FileOutputStream(file)
|
||||
var in = connection.getInputStream();
|
||||
var fos = new FileOutputStream(file)
|
||||
) {
|
||||
byte[] dataBuffer = new byte[1024];
|
||||
int bytesRead;
|
||||
@@ -98,13 +104,19 @@ public class RecorderListener implements LiveRecorder {
|
||||
}
|
||||
} catch (IOException ignored) {
|
||||
} finally {
|
||||
liveClient.getLogger().severe("Stopped recording "+liveClient.getRoomInfo().getHostName());
|
||||
liveClient.getLogger().severe("Stopped recording " + liveClient.getRoomInfo().getHostName());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
var recordingStartedEvent = new TikTokLiveRecorderStartedEvent(downloadData);
|
||||
liveClient.publishEvent(recordingStartedEvent);
|
||||
if (recordingStartedEvent.isCanceled()) {
|
||||
liveClient.getLogger().info("Recording cancelled");
|
||||
return;
|
||||
}
|
||||
liveDownloadThread.start();
|
||||
}
|
||||
|
||||
@@ -120,32 +132,6 @@ public class RecorderListener implements LiveRecorder {
|
||||
liveDownloadThread.interrupt();
|
||||
}
|
||||
|
||||
private int terminateFfmpeg(final Process process) {
|
||||
if (!process.isAlive()) {
|
||||
// ffmpeg -version, do nothing
|
||||
return process.exitValue();
|
||||
}
|
||||
|
||||
// ffmpeg -f x11grab
|
||||
System.out.println("About to destroy the child process...");
|
||||
try (final OutputStreamWriter out = new OutputStreamWriter(process.getOutputStream(), UTF_8)) {
|
||||
out.write('q');
|
||||
} catch (final IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
try {
|
||||
if (!process.waitFor(5L, TimeUnit.SECONDS)) {
|
||||
process.destroy();
|
||||
process.waitFor();
|
||||
}
|
||||
return process.exitValue();
|
||||
} catch (InterruptedException ie) {
|
||||
System.out.println("Interrupted");
|
||||
ie.printStackTrace();
|
||||
Thread.currentThread().interrupt();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private DownloadData mapToDownloadData(String json) {
|
||||
|
||||
|
||||
@@ -26,10 +26,18 @@ import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||
import io.github.jwdeveloper.tiktok.extension.recorder.impl.data.DownloadData;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Data
|
||||
public class TikTokLiveRecorderStartedEvent extends TikTokEvent
|
||||
{
|
||||
@Getter
|
||||
public class TikTokLiveRecorderStartedEvent extends TikTokEvent {
|
||||
DownloadData downloadData;
|
||||
|
||||
@Setter
|
||||
boolean canceled;
|
||||
|
||||
public TikTokLiveRecorderStartedEvent(DownloadData downloadData) {
|
||||
this.downloadData = downloadData;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user