more work
This commit is contained in:
14
.vscode/tasks.json
vendored
Normal file
14
.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "Maven: clean package",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "mvn clean package",
|
||||||
|
"problemMatcher": [
|
||||||
|
"$maven"
|
||||||
|
],
|
||||||
|
"group": "build"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
BIN
lib/Client-1.11.9-Release-all.jar
Normal file
BIN
lib/Client-1.11.9-Release-all.jar
Normal file
Binary file not shown.
14
pom.xml
14
pom.xml
@@ -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>
|
||||||
|
|||||||
@@ -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,7 +34,7 @@ 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 @): ");
|
||||||
@@ -63,4 +61,5 @@ public class Main {
|
|||||||
System.err.println("Failed to write config.yml: " + e.getMessage());
|
System.err.println("Failed to write config.yml: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.
Binary file not shown.
3
target/maven-archiver/pom.properties
Normal file
3
target/maven-archiver/pom.properties
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
artifactId=tiktok-live-event-stream-data
|
||||||
|
groupId=com.smartcraftmedia
|
||||||
|
version=1.0-SNAPSHOT
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
Main.class
|
||||||
|
TikTokEventListener.class
|
||||||
|
WebSocketServerApp.class
|
||||||
|
ConfigLoader.class
|
||||||
|
EventLogger.class
|
||||||
|
EventType.class
|
||||||
|
FormatLoader.class
|
||||||
@@ -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
|
||||||
BIN
target/tiktok-live-event-stream-data-1.0-SNAPSHOT.jar
Normal file
BIN
target/tiktok-live-event-stream-data-1.0-SNAPSHOT.jar
Normal file
Binary file not shown.
Reference in New Issue
Block a user