more work

This commit is contained in:
minster586
2026-01-14 03:27:15 -05:00
parent 5512f6fa7f
commit 61eda7f6e7
11 changed files with 153 additions and 40 deletions

14
.vscode/tasks.json vendored Normal file
View File

@@ -0,0 +1,14 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Maven: clean package",
"type": "shell",
"command": "mvn clean package",
"problemMatcher": [
"$maven"
],
"group": "build"
}
]
}

Binary file not shown.

14
pom.xml
View File

@@ -28,14 +28,14 @@
<artifactId>slf4j-simple</artifactId> <artifactId>slf4j-simple</artifactId>
<version>2.0.12</version> <version>2.0.12</version>
</dependency> </dependency>
<!-- TikTok-Live-Connector: User must provide/download the JAR and place in lib/ --> <!-- TikTokLiveJava: User must provide/download the JAR and place in lib/ -->
<!-- <dependency> <dependency>
<groupId>com.github.zerodytrash</groupId> <groupId>com.github.jwdeveloper</groupId>
<artifactId>TikTok-Live-Connector</artifactId> <artifactId>TikTokLiveJava</artifactId>
<version>latest</version> <version>1.11.9</version>
<scope>system</scope> <scope>system</scope>
<systemPath>${project.basedir}/lib/TikTok-Live-Connector.jar</systemPath> <systemPath>${project.basedir}/lib/Client-1.11.9-Release-all.jar</systemPath>
</dependency> --> </dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>

View File

@@ -24,11 +24,9 @@ public class Main {
System.out.println("WebSocket server running on port " + port); System.out.println("WebSocket server running on port " + port);
// Initialize TikTok event listener (placeholder) // Initialize TikTok event listener (placeholder)
TikTokEventListener tiktokListener = new TikTokEventListener();
// TODO: Connect TikTok-Live-Connector and wire up event callbacks
// Placeholder: Simulate event TikTokEventListener tiktokListener = new TikTokEventListener(config, format, wsServer);
tiktokListener.onFollow("@exampleuser"); // TODO: Connect TikTokLiveJava and wire up event callbacks to tiktokListener
} catch (Exception e) { } catch (Exception e) {
System.err.println("Failed to load config or start server: " + e.getMessage()); System.err.println("Failed to load config or start server: " + e.getMessage());
@@ -36,31 +34,32 @@ public class Main {
} }
private static void firstTimeSetup() { private static void firstTimeSetup() {
Scanner scanner = new Scanner(System.in); try (Scanner scanner = new Scanner(System.in)) {
String username; String username;
do { do {
System.out.print("Enter the TikTok username to follow (include @): "); System.out.print("Enter the TikTok username to follow (include @): ");
username = scanner.nextLine(); username = scanner.nextLine();
} while (!username.startsWith("@")); } while (!username.startsWith("@"));
System.out.print("Enter websocket port (default 3000): "); System.out.print("Enter websocket port (default 3000): ");
String portInput = scanner.nextLine(); String portInput = scanner.nextLine();
int port = 3000; int port = 3000;
if (!portInput.isBlank()) { if (!portInput.isBlank()) {
try { try {
port = Integer.parseInt(portInput); port = Integer.parseInt(portInput);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
System.out.println("Invalid port. Using default 3000."); System.out.println("Invalid port. Using default 3000.");
}
} }
}
// Write config.yml // Write config.yml
String config = "TIKTOK_USERNAME: '" + username + "'\nwebsocket_port: " + port + "\n"; String config = "TIKTOK_USERNAME: '" + username + "'\nwebsocket_port: " + port + "\n";
try { try {
Files.writeString(Paths.get("config.yml"), config); Files.writeString(Paths.get("config.yml"), config);
System.out.println("config.yml created. Please edit it for more options as needed."); System.out.println("config.yml created. Please edit it for more options as needed.");
} catch (IOException e) { } catch (IOException e) {
System.err.println("Failed to write config.yml: " + e.getMessage()); System.err.println("Failed to write config.yml: " + e.getMessage());
}
} }
} }
} }

View File

@@ -2,22 +2,105 @@
// The actual implementation will require the TikTok-Live-Connector JAR in the lib folder. // The actual implementation will require the TikTok-Live-Connector JAR in the lib folder.
// At test time, you will be provided with the download link and instructions. // At test time, you will be provided with the download link and instructions.
import java.util.Map;
@SuppressWarnings("unchecked")
public class TikTokEventListener { public class TikTokEventListener {
// TODO: Integrate with TikTok-Live-Connector and handle events private final Map<String, Object> config;
// Example methods for event callbacks: private final Map<String, Object> format;
private final WebSocketServerApp wsServer;
public TikTokEventListener(Map<String, Object> config, Map<String, Object> format, WebSocketServerApp wsServer) {
this.config = config;
this.format = format;
this.wsServer = wsServer;
}
private String formatEvent(String eventType, String target, Map<String, String> vars) {
try {
Map<String, Object> events = (Map<String, Object>) format.get("events");
Map<String, Object> event = (Map<String, Object>) events.get(eventType);
Map<String, Object> fmt = (Map<String, Object>) event.get(target);
String text = (String) ((Map<String, Object>) fmt).get("text");
for (Map.Entry<String, String> entry : vars.entrySet()) {
text = text.replace("$" + entry.getKey(), entry.getValue());
}
return text;
} catch (Exception e) {
return "[Format error]";
}
}
private void output(String eventType, Map<String, String> vars, String filePath) {
String date = java.time.LocalDate.now().toString();
String time = java.time.LocalTime.now().withNano(0).toString();
vars.put("date", date);
vars.put("time", time);
// Console output
String cliMsg = formatEvent(eventType, "cli_format", vars);
System.out.println(cliMsg);
// File output
if (filePath != null && !filePath.isEmpty()) {
String fileMsg = formatEvent(eventType, "file_format", vars);
EventLogger.logToFile(filePath, fileMsg);
}
// WebSocket output
if (wsServer != null) {
wsServer.broadcastEvent(cliMsg);
}
}
public void onFollow(String userInfo) { public void onFollow(String userInfo) {
// Handle follow event Map<String, String> vars = new java.util.HashMap<>();
vars.put("userinfo", userInfo);
String filePath = getOutputPath("follow");
output("follow", vars, filePath);
} }
public void onLike(String userInfo, int amount) { public void onLike(String userInfo, int amount) {
// Handle like event Map<String, String> vars = new java.util.HashMap<>();
vars.put("userinfo", userInfo);
vars.put("amount", String.valueOf(amount));
String filePath = getOutputPath("likes");
output("likes", vars, filePath);
} }
public void onShare(String userInfo) { public void onShare(String userInfo) {
// Handle share event Map<String, String> vars = new java.util.HashMap<>();
vars.put("userinfo", userInfo);
String filePath = getOutputPath("shares");
output("shares", vars, filePath);
} }
public void onGift(String userInfo, String giftName, int amount) { public void onGift(String userInfo, String giftName, int amount) {
// Handle gift event Map<String, String> vars = new java.util.HashMap<>();
vars.put("userinfo", userInfo);
vars.put("gift_name", giftName);
vars.put("amount", String.valueOf(amount));
String filePath = getOutputPath("gifts");
output("gifts", vars, filePath);
} }
public void onChat(String userInfo, String message) { public void onChat(String userInfo, String message) {
// Handle chat event Map<String, String> vars = new java.util.HashMap<>();
vars.put("userinfo", userInfo);
vars.put("msg", message);
String filePath = getOutputPath("chat");
output("chat", vars, filePath);
}
private String getOutputPath(String eventType) {
try {
Map<String, Object> events = (Map<String, Object>) config.get("events");
Map<String, Object> event = (Map<String, Object>) events.get(eventType);
Map<String, Object> fileEnable = (Map<String, Object>) event.get("file_enable");
if (fileEnable != null && fileEnable.containsKey("output_path")) {
return (String) fileEnable.get("output_path");
}
} catch (Exception ignored) {}
return null;
} }
} }

Binary file not shown.

View File

@@ -0,0 +1,3 @@
artifactId=tiktok-live-event-stream-data
groupId=com.smartcraftmedia
version=1.0-SNAPSHOT

View File

@@ -0,0 +1,7 @@
Main.class
TikTokEventListener.class
WebSocketServerApp.class
ConfigLoader.class
EventLogger.class
EventType.class
FormatLoader.class

View File

@@ -0,0 +1,7 @@
G:\github\Smartcraft-media\tiktok-live-event-stream-data\src\main\java\EventLogger.java
G:\github\Smartcraft-media\tiktok-live-event-stream-data\src\main\java\FormatLoader.java
G:\github\Smartcraft-media\tiktok-live-event-stream-data\src\main\java\Main.java
G:\github\Smartcraft-media\tiktok-live-event-stream-data\src\main\java\ConfigLoader.java
G:\github\Smartcraft-media\tiktok-live-event-stream-data\src\main\java\EventType.java
G:\github\Smartcraft-media\tiktok-live-event-stream-data\src\main\java\TikTokEventListener.java
G:\github\Smartcraft-media\tiktok-live-event-stream-data\src\main\java\WebSocketServerApp.java

Binary file not shown.