mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 16:59:39 -05:00
Changes:
`TikTokEventListener` new method of listening events see it at TestApplication/ListenerExample.java Bugs: - Fixed bug: Websocket was sending ping after it was closed
This commit is contained in:
28
Tools-ReadmeGenerator/pom.xml
Normal file
28
Tools-ReadmeGenerator/pom.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>TikTokLiveJava</artifactId>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<version>0.0.14-Release</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>Tools-ReadmeGenerator</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>16</maven.compiler.source>
|
||||
<maven.compiler.target>16</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||
<artifactId>Tools</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,75 @@
|
||||
package io.github.jwdeveloper.tiktok;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.annotations.EventMeta;
|
||||
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
||||
import io.github.jwdeveloper.tiktok.events.TikTokEvent;
|
||||
import org.reflections.Reflections;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class EventsListGenerator
|
||||
{
|
||||
|
||||
|
||||
//[a](https://github.com/jwdeveloper/TikTok-Live-Java/blob/master/API/src/main/java/io/github/jwdeveloper/tiktok/events/messages/TikTokBarrageMessageEvent.java)
|
||||
//Message Events:
|
||||
//- [member](#member)
|
||||
|
||||
public static String GetEventsList()
|
||||
{
|
||||
var classes = getClasses();
|
||||
var builder = new StringBuilder();
|
||||
for(var entry : classes.entrySet())
|
||||
{
|
||||
builder.append(System.lineSeparator());
|
||||
builder.append(" **"+entry.getKey().name()+"**:").append(System.lineSeparator());
|
||||
|
||||
for(var clazz : entry.getValue())
|
||||
{
|
||||
var name = clazz.getSimpleName();
|
||||
var baseUrl ="https://github.com/jwdeveloper/TikTok-Live-Java/blob/master/API/src/main/java/io/github/jwdeveloper/tiktok/events/messages/"+name+".java";
|
||||
builder.append("- [").append(name).append("](").append(baseUrl).append(")").append(System.lineSeparator());
|
||||
}
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
private static Map<EventType, List<Class<?>>> getClasses()
|
||||
{
|
||||
Reflections reflections = new Reflections("io.github.jwdeveloper.tiktok.events.messages");
|
||||
var classes = reflections.getSubTypesOf(TikTokEvent.class).stream().toList();
|
||||
Map<EventType, List<Class<?>>> classMap = new HashMap<>();
|
||||
// Group classes by EventType
|
||||
for (Class<?> clazz : classes) {
|
||||
EventType eventType = getEventType(clazz);
|
||||
classMap.computeIfAbsent(eventType, k -> new ArrayList<>()).add(clazz);
|
||||
}
|
||||
return classMap;
|
||||
}
|
||||
|
||||
private static EventType getEventType(Class<?> clazz) {
|
||||
EventMeta annotation = clazz.getAnnotation(EventMeta.class);
|
||||
if (annotation != null) {
|
||||
return annotation.eventType();
|
||||
}
|
||||
return EventType.Custom; // Default value if annotation not present
|
||||
}
|
||||
private class EventTypeComparator implements Comparator<Class<?>> {
|
||||
@Override
|
||||
public int compare(Class<?> class1, Class<?> class2) {
|
||||
EventType eventType1 = getEventType(class1);
|
||||
EventType eventType2 = getEventType(class2);
|
||||
return eventType1.compareTo(eventType2);
|
||||
}
|
||||
|
||||
private EventType getEventType(Class<?> clazz) {
|
||||
EventMeta annotation = clazz.getAnnotation(EventMeta.class);
|
||||
if (annotation != null) {
|
||||
return annotation.eventType();
|
||||
}
|
||||
return EventType.Custom;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package io.github.jwdeveloper.tiktok;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.utils.FilesUtility;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class LiveClientMethodsGenerator
|
||||
{
|
||||
|
||||
|
||||
|
||||
//| Method Name | Description |
|
||||
//| ----------- | ----------- |
|
||||
|
||||
|
||||
public static String generate(String path)
|
||||
{
|
||||
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.append("| Method Name | Description |");
|
||||
sb.append(System.lineSeparator());
|
||||
sb.append("| ----------- | ----------- |");
|
||||
|
||||
var content = FilesUtility.loadFileContent(path);
|
||||
var pattern = "// \\s*(.*?)\\n\\s*(\\w+)\\s*\\(.*?\\)";
|
||||
|
||||
// Create a Pattern object
|
||||
var regex = Pattern.compile(pattern);
|
||||
|
||||
// Create a Matcher object
|
||||
var matcher = regex.matcher(content);
|
||||
|
||||
// Find and print method names and comments
|
||||
while (matcher.find()) {
|
||||
String comment = matcher.group(1);
|
||||
String methodName = matcher.group(2);
|
||||
sb.append(System.lineSeparator());
|
||||
sb.append("| ").append(methodName).append(" | ").append(comment).append(" |");
|
||||
}
|
||||
sb.append(System.lineSeparator());
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package io.github.jwdeveloper.tiktok;
|
||||
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args)
|
||||
{
|
||||
var generator = new ReadmeGenerator();
|
||||
generator.generate();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package io.github.jwdeveloper.tiktok;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.utils.FilesUtility;
|
||||
import io.github.jwdeveloper.tiktok.utils.TemplateUtility;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ReadmeGenerator
|
||||
{
|
||||
|
||||
public void generate()
|
||||
{
|
||||
var template = FilesUtility.getFileFromResource(Main.class,"template.md");
|
||||
var variables = new HashMap<String,Object>();
|
||||
|
||||
var pomPath = "C:\\Users\\ja\\IdeaProjects\\TikTokLiveJava\\Tools-ReadmeGenerator\\pom.xml";
|
||||
|
||||
variables.put("version", getCurrentVersion(pomPath));
|
||||
|
||||
|
||||
var exampleCodePath = "C:\\Users\\ja\\IdeaProjects\\TikTokLiveJava\\TestApplication\\src\\main\\java\\io\\github\\jwdeveloper\\tiktok\\SimpleExample.java";
|
||||
variables.put("Code-Example", getCodeExample(exampleCodePath));
|
||||
|
||||
|
||||
var exampleConfigurationPath = "C:\\Users\\ja\\IdeaProjects\\TikTokLiveJava\\TestApplication\\src\\main\\java\\io\\github\\jwdeveloper\\tiktok\\ConfigurationExample.java";
|
||||
variables.put("Configuration-Example", getCodeExample(exampleConfigurationPath));
|
||||
|
||||
variables.put("Events", EventsListGenerator.GetEventsList());
|
||||
|
||||
var listenerExamplePath = "C:\\Users\\ja\\IdeaProjects\\TikTokLiveJava\\TestApplication\\src\\main\\java\\io\\github\\jwdeveloper\\tiktok\\ListenerExample.java";
|
||||
variables.put("Listener-Example", getCodeExample(listenerExamplePath));
|
||||
|
||||
// var liveClientPath = "C:\\Users\\ja\\IdeaProjects\\TikTokLiveJava\\API\\src\\main\\java\\io\\github\\jwdeveloper\\tiktok\\live\\LiveClient.java";
|
||||
// variables.put("methods", LiveClientMethodsGenerator.generate(liveClientPath));
|
||||
|
||||
template = TemplateUtility.generateTemplate(template, variables);
|
||||
var outputPath = "C:\\Users\\ja\\IdeaProjects\\TikTokLiveJava\\Tools-ReadmeGenerator\\src\\main\\resources\\output.md";
|
||||
FilesUtility.saveFile(outputPath, template);
|
||||
}
|
||||
|
||||
public String getCurrentVersion(String path)
|
||||
{
|
||||
var content = FilesUtility.loadFileContent(path);
|
||||
var pattern = "<version>(.*?)<\\/version>";
|
||||
|
||||
// Create a Pattern object
|
||||
var regex = Pattern.compile(pattern);
|
||||
|
||||
// Create a Matcher object
|
||||
var matcher = regex.matcher(content);
|
||||
|
||||
// Find the first match
|
||||
if (matcher.find()) {
|
||||
// Extract and print the version
|
||||
return matcher.group(1);
|
||||
}
|
||||
return "VERSION NOT FOUND";
|
||||
}
|
||||
|
||||
public String getCodeExample(String path)
|
||||
{
|
||||
return FilesUtility.loadFileContent(path);
|
||||
}
|
||||
|
||||
}
|
||||
89
Tools-ReadmeGenerator/src/main/resources/template.md
Normal file
89
Tools-ReadmeGenerator/src/main/resources/template.md
Normal file
@@ -0,0 +1,89 @@
|
||||
[](https://jitpack.io/#jwdeveloper/TikTok-Live-Java)
|
||||
|
||||
|
||||
# TikTokLive Java
|
||||
A Java library based on [TikTokLive](https://github.com/isaackogan/TikTokLive) and [TikTokLiveSharp](https://github.com/sebheron/TikTokLiveSharp). Use it to receive live stream events such as comments and gifts in realtime from [TikTok LIVE](https://www.tiktok.com/live) by connecting to TikTok's internal WebCast push service. The package includes a wrapper that connects to the WebCast service using just the username (`uniqueId`). This allows you to connect to your own live chat as well as the live chat of other streamers. No credentials are required. Besides [Chat Comments](#chat), other events such as [Members Joining](#member), [Gifts](#gift), [Subscriptions](#subscribe), [Viewers](#roomuser), [Follows](#social), [Shares](#social), [Questions](#questionnew), [Likes](#like) and [Battles](#linkmicbattle) can be tracked. You can also send [automatic messages](#send-chat-messages) into the chat by providing your Session ID.
|
||||
|
||||
Join the support [discord](https://discord.gg/e2XwPNTBBr) and visit the `#java-support` channel for questions, contributions and ideas. Feel free to make pull requests with missing/new features, fixes, etc
|
||||
|
||||
Do you prefer other programming languages?
|
||||
- **Node** orginal: [TikTok-Live-Connector](https://github.com/isaackogan/TikTok-Live-Connector) by [@zerodytrash](https://github.com/zerodytrash)
|
||||
- **Python** rewrite: [TikTokLive](https://github.com/isaackogan/TikTokLive) by [@isaackogan](https://github.com/isaackogan)
|
||||
- **Go** rewrite: [GoTikTokLive](https://github.com/Davincible/gotiktoklive) by [@Davincible](https://github.com/Davincible)
|
||||
- **C#** rewrite: [TikTokLiveSharp](https://github.com/frankvHoof93/TikTokLiveSharp) by [@frankvHoof93](https://github.com/frankvHoof93)
|
||||
|
||||
**NOTE:** This is not an official API. It's a reverse engineering project.
|
||||
|
||||
#### Overview
|
||||
- [Getting started](#getting-started)
|
||||
- [Configuration](#configuration)
|
||||
- [Methods](#methods)
|
||||
- [Events](#events)
|
||||
- [Contributing](#contributing)
|
||||
|
||||
## Getting started
|
||||
|
||||
1. Install the package via Maven
|
||||
|
||||
```xml
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.jwdeveloper.TikTok-Live-Java</groupId>
|
||||
<artifactId>Client</artifactId>
|
||||
<version>{{version}}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.10.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
```
|
||||
|
||||
2. Create your first chat connection
|
||||
|
||||
```java
|
||||
{{Code-Example}}
|
||||
```
|
||||
## Configuration
|
||||
|
||||
```java
|
||||
{{Configuration-Example}}
|
||||
```
|
||||
## Listener Example
|
||||
|
||||
```java
|
||||
{{Listener-Example}}
|
||||
```
|
||||
|
||||
## Methods
|
||||
A `client (LiveClient)` object contains the following methods.
|
||||
|
||||
{{methods}}
|
||||
|
||||
| Method Name | Description |
|
||||
|---------------------| ----------- |
|
||||
| connect | Connects to the live stream. |
|
||||
| disconnect | Disconnects the connection. |
|
||||
| getGiftManager | Gets the meta informations about all gifts. |
|
||||
| getRoomInfo | Gets the current room info from TikTok API including streamer info, room status and statistics. |
|
||||
| getListenersManager | Gets and manage TikTokEventListeners |
|
||||
|
||||
## Events
|
||||
|
||||
A `TikTokLive` object has the following events
|
||||
|
||||
{{Events}}
|
||||
|
||||
<br><br>
|
||||
|
||||
## Contributing
|
||||
Your improvements are welcome! Feel free to open an <a href="https://github.com/jwdeveloper/TikTok-Live-Java/issues">issue</a> or <a href="https://github.com/jwdeveloper/TikTok-Live-Java/pulls">pull request</a>.
|
||||
Reference in New Issue
Block a user