mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-27 16:59:39 -05:00
Compare commits
22 Commits
develop-1.
...
1.6.3-Rele
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c3a7a27948 | ||
|
|
af52e15a45 | ||
|
|
5577df7c9c | ||
|
|
2c68fe3421 | ||
|
|
5abfd95c89 | ||
|
|
5c715bfd52 | ||
|
|
b153afb332 | ||
|
|
d2ea00bcae | ||
|
|
4297af1349 | ||
|
|
d09c90ef54 | ||
|
|
9c96c8899a | ||
|
|
301df6392d | ||
|
|
fb9fc04ee5 | ||
|
|
43a8ba4225 | ||
|
|
dffccf1f0b | ||
|
|
6dcccccb78 | ||
|
|
0d467d79c3 | ||
|
|
33c98508c0 | ||
|
|
67948b14cc | ||
|
|
22e11a7822 | ||
|
|
4545503441 | ||
|
|
498d34a90b |
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<version>1.5.3-Release</version>
|
<version>1.6.2-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>API</artifactId>
|
<artifactId>API</artifactId>
|
||||||
|
|||||||
@@ -27,12 +27,12 @@ import io.github.jwdeveloper.tiktok.annotations.EventType;
|
|||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.LinkMicArmy;
|
import io.github.jwdeveloper.tiktok.data.models.LinkMicArmy;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.enums.LinkMicBattleStatus;
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicArmies;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicArmies;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Triggered every time a battle participant receives points. Contains the current status of the battle and the army that suported the group.
|
* Triggered every time a battle participant receives points. Contains the current status of the battle and the army that suported the group.
|
||||||
*/
|
*/
|
||||||
@@ -40,8 +40,10 @@ import java.util.List;
|
|||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokLinkMicArmiesEvent extends TikTokHeaderEvent {
|
public class TikTokLinkMicArmiesEvent extends TikTokHeaderEvent {
|
||||||
private final Long battleId;
|
private final Long battleId;
|
||||||
|
/**
|
||||||
private final Integer battleStatus;
|
true if battle is finished otherwise false
|
||||||
|
*/
|
||||||
|
private final boolean finished;
|
||||||
|
|
||||||
private final Picture picture;
|
private final Picture picture;
|
||||||
|
|
||||||
@@ -52,6 +54,6 @@ public class TikTokLinkMicArmiesEvent extends TikTokHeaderEvent {
|
|||||||
battleId = msg.getId();
|
battleId = msg.getId();
|
||||||
armies = msg.getBattleItemsList().stream().map(LinkMicArmy::new).toList();
|
armies = msg.getBattleItemsList().stream().map(LinkMicArmy::new).toList();
|
||||||
picture = Picture.map(msg.getImage());
|
picture = Picture.map(msg.getImage());
|
||||||
battleStatus = msg.getBattleStatus();
|
finished = msg.getBattleStatus() == LinkMicBattleStatus.ARMY_FINISHED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,29 +22,62 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.data.events;
|
package io.github.jwdeveloper.tiktok.data.events;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.annotations.EventMeta;
|
import io.github.jwdeveloper.tiktok.annotations.*;
|
||||||
import io.github.jwdeveloper.tiktok.annotations.EventType;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokHeaderEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.LinkMicBattleTeam;
|
import io.github.jwdeveloper.tiktok.data.models.battles.*;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.enums.LinkMicBattleStatus;
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicBattle;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicBattle;
|
||||||
import lombok.Getter;
|
import lombok.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Triggered every time a battle starts.
|
* Triggered every time a battle starts & ends
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@EventMeta(eventType = EventType.Message)
|
@EventMeta(eventType = EventType.Message)
|
||||||
public class TikTokLinkMicBattleEvent extends TikTokHeaderEvent {
|
public class TikTokLinkMicBattleEvent extends TikTokHeaderEvent
|
||||||
private final Long battleId;
|
{
|
||||||
private final List<LinkMicBattleTeam> team1;
|
private final Long battleId;
|
||||||
private final List<LinkMicBattleTeam> team2;
|
/**
|
||||||
|
true if battle is finished otherwise false
|
||||||
|
*/
|
||||||
|
private final boolean finished;
|
||||||
|
@Getter(AccessLevel.NONE)
|
||||||
|
private final boolean oneVsOne;
|
||||||
|
private final List<Team> teams;
|
||||||
|
|
||||||
public TikTokLinkMicBattleEvent(WebcastLinkMicBattle msg) {
|
public TikTokLinkMicBattleEvent(WebcastLinkMicBattle msg) {
|
||||||
super(msg.getCommon());
|
super(msg.getCommon());
|
||||||
battleId = msg.getId();
|
battleId = msg.getId();
|
||||||
team1 = msg.getTeams1List().stream().map(LinkMicBattleTeam::new).toList();
|
finished = msg.getBattleStatus() == LinkMicBattleStatus.BATTLE_FINISHED;
|
||||||
team2 = msg.getTeams2List().stream().map(LinkMicBattleTeam::new).toList();
|
teams = new ArrayList<>();
|
||||||
}
|
if (msg.getHostTeamCount() == 2) { // 1v1 battle
|
||||||
}
|
teams.add(new Team1v1(msg.getHostTeam(0), msg));
|
||||||
|
teams.add(new Team1v1(msg.getHostTeam(1), msg));
|
||||||
|
oneVsOne = true;
|
||||||
|
} else { // 2v2 battle
|
||||||
|
if (isFinished()) {
|
||||||
|
teams.add(new Team2v2(msg.getHostData2V2List().stream().filter(data -> data.getTeamNumber() == 1).findFirst().orElse(null), msg));
|
||||||
|
teams.add(new Team2v2(msg.getHostData2V2List().stream().filter(data -> data.getTeamNumber() == 2).findFirst().orElse(null), msg));
|
||||||
|
} else {
|
||||||
|
teams.add(new Team2v2(msg.getHostTeam(0), msg.getHostTeam(1), msg));
|
||||||
|
teams.add(new Team2v2(msg.getHostTeam(2), msg.getHostTeam(3), msg));
|
||||||
|
}
|
||||||
|
oneVsOne = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Info:
|
||||||
|
// - msg.getDetailsList() & msg.getViewerTeamList() both only have content when battle is finished
|
||||||
|
// - msg.getDetailsCount() & msg.getViewerTeamCount() always is 2 only when battle is finished
|
||||||
|
// - msg.getHostTeamCount() always is 2 for 1v1 or 4 for 2v2
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean is1v1() {
|
||||||
|
return oneVsOne;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean is2v2() {
|
||||||
|
return !oneVsOne;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -46,4 +46,4 @@ public class LinkMicArmy {
|
|||||||
List<User> Users;
|
List<User> Users;
|
||||||
Integer Points;
|
Integer Points;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2023-2023 jwdeveloper jacekwoln@gmail.com
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
|
||||||
* a copy of this software and associated documentation files (the
|
|
||||||
* "Software"), to deal in the Software without restriction, including
|
|
||||||
* without limitation the rights to use, copy, modify, merge, publish,
|
|
||||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
||||||
* permit persons to whom the Software is furnished to do so, subject to
|
|
||||||
* the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be
|
|
||||||
* included in all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
||||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
||||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
||||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
||||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
package io.github.jwdeveloper.tiktok.data.models;
|
|
||||||
|
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicBattle;
|
|
||||||
import lombok.Value;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Value
|
|
||||||
public class LinkMicBattleTeam {
|
|
||||||
Long teamId;
|
|
||||||
List<User> users;
|
|
||||||
|
|
||||||
public LinkMicBattleTeam(WebcastLinkMicBattle.LinkMicBattleTeam team) {
|
|
||||||
this.teamId = team.getId();
|
|
||||||
this.users = team.getUsersList().stream().map(User::new).toList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -44,11 +44,11 @@ public class Picture {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Picture map(io.github.jwdeveloper.tiktok.messages.data.Image profilePicture) {
|
public static Picture map(io.github.jwdeveloper.tiktok.messages.data.Image profilePicture) {
|
||||||
var index = profilePicture.getUrlListCount() - 1;
|
var index = profilePicture.getUrlCount() - 1;
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
return new Picture("");
|
return new Picture("");
|
||||||
}
|
}
|
||||||
var url = profilePicture.getUrlList(index);
|
var url = profilePicture.getUrl(index);
|
||||||
return new Picture(url);
|
return new Picture(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ public class Picture {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Picture Empty() {
|
public static Picture empty() {
|
||||||
return new Picture("");
|
return new Picture("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package io.github.jwdeveloper.tiktok.data.models.battles;
|
||||||
|
|
||||||
|
public abstract class Team {
|
||||||
|
/**
|
||||||
|
* Provides a check for verifying if this team represents a 1v1 Team.
|
||||||
|
* @return true if this team is of type {@link Team1v1}, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean is1v1Team() {
|
||||||
|
return this instanceof Team1v1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides a check for verifying if this team represents a 1v1 Team.
|
||||||
|
* @return true if this team is of type {@link Team1v1}, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean is2v2Team() {
|
||||||
|
return this instanceof Team2v2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience method to get this team as a {@link Team1v1}. If this team is of some
|
||||||
|
* other type, an {@link IllegalStateException} will result. Hence it is best to use this method
|
||||||
|
* after ensuring that this element is of the desired type by calling {@link #is1v1Team()} first.
|
||||||
|
*
|
||||||
|
* @return this team as a {@link Team1v1}.
|
||||||
|
* @throws IllegalStateException if this team is of another type.
|
||||||
|
*/
|
||||||
|
public Team1v1 getAs1v1Team() {
|
||||||
|
if (is1v1Team())
|
||||||
|
return (Team1v1) this;
|
||||||
|
throw new IllegalStateException("Not a 1v1Team: " + this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience method to get this team as a {@link Team2v2}. If this team is of some
|
||||||
|
* other type, an {@link IllegalStateException} will result. Hence it is best to use this method
|
||||||
|
* after ensuring that this element is of the desired type by calling {@link #is2v2Team()} first.
|
||||||
|
*
|
||||||
|
* @return this team as a {@link Team2v2}.
|
||||||
|
* @throws IllegalStateException if this team is of another type.
|
||||||
|
*/
|
||||||
|
public Team2v2 getAs2v2Team() {
|
||||||
|
if (is2v2Team())
|
||||||
|
return (Team2v2) this;
|
||||||
|
throw new IllegalStateException("Not a 2v2Team: " + this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package io.github.jwdeveloper.tiktok.data.models.battles;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicBattle;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class Team1v1 extends Team
|
||||||
|
{
|
||||||
|
/** Value >= 0 when finished otherwise -1 */
|
||||||
|
private final int totalPoints;
|
||||||
|
private final int winStreak;
|
||||||
|
private final User host;
|
||||||
|
private final List<Viewer> viewers;
|
||||||
|
|
||||||
|
public Team1v1(WebcastLinkMicBattle.LinkMicBattleHost hostTeam, WebcastLinkMicBattle msg) {
|
||||||
|
long hostId = hostTeam.getId();
|
||||||
|
this.winStreak = msg.getTeamDataList().stream().filter(data -> data.getTeamId() == hostId).map(data -> data.getData().getWinStreak()).findFirst().orElse(-1);
|
||||||
|
this.totalPoints = msg.getDetailsList().stream().filter(dets -> dets.getId() == hostId).map(dets -> dets.getSummary().getPoints()).findFirst().orElse(-1);
|
||||||
|
this.host = new User(hostTeam.getHostGroup(0).getHost(0));
|
||||||
|
this.viewers = msg.getViewerTeamList().stream().filter(team -> team.getId() == hostId).findFirst().map(topViewers ->
|
||||||
|
topViewers.getViewerGroup(0).getViewerList().stream().map(Viewer::new).toList()).orElseGet(ArrayList::new);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package io.github.jwdeveloper.tiktok.data.models.battles;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicBattle;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class Team2v2 extends Team {
|
||||||
|
/** Value >= 0 when finished otherwise -1 */
|
||||||
|
private final int totalPoints;
|
||||||
|
|
||||||
|
private final List<User> hosts;
|
||||||
|
private final List<Viewer> viewers;
|
||||||
|
|
||||||
|
public Team2v2(WebcastLinkMicBattle.LinkMicBattleHost hostTeam1, WebcastLinkMicBattle.LinkMicBattleHost hostTeam2, WebcastLinkMicBattle msg) {
|
||||||
|
this.totalPoints = -1;
|
||||||
|
this.hosts = List.of(new User(hostTeam1.getHostGroup(0).getHost(0)), new User(hostTeam2.getHostGroup(0).getHost(0)));
|
||||||
|
this.viewers = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Team2v2(WebcastLinkMicBattle.Host2v2Data hd, WebcastLinkMicBattle msg) {
|
||||||
|
this.totalPoints = hd.getTotalPoints();
|
||||||
|
var host = new User(msg.getHostTeamList().stream().filter(data -> data.getId() == hd.getHostdata(0).getHostId()).findFirst().orElseThrow().getHostGroup(0).getHost(0));
|
||||||
|
var cohost = new User(msg.getHostTeamList().stream().filter(data -> data.getId() == hd.getHostdata(1).getHostId()).findFirst().orElseThrow().getHostGroup(0).getHost(0));
|
||||||
|
this.hosts = List.of(host, cohost);
|
||||||
|
this.viewers = msg.getViewerTeamList().stream().filter(team -> team.getId() == host.getId() || team.getId() == cohost.getId()).findFirst().map(topViewers ->
|
||||||
|
topViewers.getViewerGroup(0).getViewerList().stream().map(Viewer::new).toList()).orElseGet(ArrayList::new);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package io.github.jwdeveloper.tiktok.data.models.battles;
|
||||||
|
|
||||||
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
|
import io.github.jwdeveloper.tiktok.data.models.users.User;
|
||||||
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastLinkMicBattle;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class Viewer {
|
||||||
|
private final User user;
|
||||||
|
private final int points;
|
||||||
|
|
||||||
|
public Viewer(WebcastLinkMicBattle.LinkMicBattleTopViewers.TopViewerGroup.TopViewer topViewer) {
|
||||||
|
this.user = new User(topViewer.getId(), null, topViewer.getProfileId(), Picture.map(topViewer.getImages(0)));
|
||||||
|
this.points = topViewer.getPoints();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,9 +2,7 @@ package io.github.jwdeveloper.tiktok.data.models.gifts;
|
|||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
import lombok.*;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class Gift {
|
public class Gift {
|
||||||
@@ -16,7 +14,7 @@ public class Gift {
|
|||||||
|
|
||||||
private final int diamondCost;
|
private final int diamondCost;
|
||||||
|
|
||||||
private final Picture picture;
|
private Picture picture;
|
||||||
|
|
||||||
private final JsonObject properties;
|
private final JsonObject properties;
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ package io.github.jwdeveloper.tiktok.data.models.users;
|
|||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.badges.Badge;
|
import io.github.jwdeveloper.tiktok.data.models.badges.Badge;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastEnvelopeMessage;
|
import io.github.jwdeveloper.tiktok.messages.webcast.*;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@@ -136,6 +136,14 @@ public class User {
|
|||||||
this.picture = picture;
|
this.picture = picture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public User(long id, String name, String profileId, Picture picture) {
|
||||||
|
this(id, name, profileId, picture, 0, 0, List.of(Badge.empty()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public User(WebcastLinkMicBattle.LinkMicBattleHost.HostGroup.Host host) {
|
||||||
|
this(host.getId(), host.getName(), host.getProfileId(), Picture.map(host.getImages(0)));
|
||||||
|
}
|
||||||
|
|
||||||
public User(io.github.jwdeveloper.tiktok.messages.data.User user) {
|
public User(io.github.jwdeveloper.tiktok.messages.data.User user) {
|
||||||
this(user.getId(), user.getDisplayId(), Picture.map(user.getAvatarThumb()));
|
this(user.getId(), user.getDisplayId(), Picture.map(user.getAvatarThumb()));
|
||||||
profileName = user.getNickname();
|
profileName = user.getNickname();
|
||||||
@@ -159,10 +167,9 @@ public class User {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static User EMPTY = new User(0L,
|
public static User EMPTY = new User(0L,
|
||||||
"",
|
"",
|
||||||
Picture.Empty(),
|
Picture.empty(),
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
List.of(Badge.empty()));
|
List.of(Badge.empty()));
|
||||||
@@ -209,4 +216,18 @@ public class User {
|
|||||||
0,
|
0,
|
||||||
List.of(Badge.empty()));
|
List.of(Badge.empty()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "User{" +
|
||||||
|
"id=" + id +
|
||||||
|
", name='" + name + "'" +
|
||||||
|
", profileName='" + profileName + "'" +
|
||||||
|
", picture=" + picture +
|
||||||
|
", following=" + following +
|
||||||
|
", followers=" + followers +
|
||||||
|
", badges=" + badges +
|
||||||
|
", attributes=" + attributes +
|
||||||
|
"}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -34,30 +34,24 @@ import java.util.TreeMap;
|
|||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class HttpClientSettings {
|
public class HttpClientSettings {
|
||||||
|
|
||||||
@Getter
|
private final Map<String, Object> params;
|
||||||
final Map<String, Object> params;
|
|
||||||
|
|
||||||
@Getter
|
private final Map<String, String> headers;
|
||||||
final Map<String, String> headers;
|
|
||||||
|
|
||||||
@Getter
|
private final Map<String, String> cookies;
|
||||||
final Map<String, String> cookies;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
ProxyClientSettings proxyClientSettings;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
Consumer<HttpClient.Builder> onClientCreating;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
Consumer<HttpRequest.Builder> onRequestCreating;
|
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
@Getter
|
private ProxyClientSettings proxyClientSettings;
|
||||||
Duration timeout;
|
|
||||||
|
private Consumer<HttpClient.Builder> onClientCreating;
|
||||||
|
|
||||||
|
private Consumer<HttpRequest.Builder> onRequestCreating;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
private Duration timeout;
|
||||||
|
|
||||||
public HttpClientSettings() {
|
public HttpClientSettings() {
|
||||||
this.params = new TreeMap<>();
|
this.params = new TreeMap<>();
|
||||||
@@ -65,10 +59,8 @@ public class HttpClientSettings {
|
|||||||
this.cookies = new HashMap<>();
|
this.cookies = new HashMap<>();
|
||||||
this.timeout = Duration.ofSeconds(2);
|
this.timeout = Duration.ofSeconds(2);
|
||||||
this.proxyClientSettings = new ProxyClientSettings();
|
this.proxyClientSettings = new ProxyClientSettings();
|
||||||
this.onClientCreating = (x) -> {
|
this.onClientCreating = (x) -> {};
|
||||||
};
|
this.onRequestCreating = (x) -> {};
|
||||||
this.onRequestCreating = (x) -> {
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -33,20 +33,15 @@ import java.util.logging.Level;
|
|||||||
@Data
|
@Data
|
||||||
public class LiveClientSettings {
|
public class LiveClientSettings {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: give better description
|
* Sets client to offline mode, prohibits connection to TikTok servers
|
||||||
* <p>
|
* @apiNote Useful when testing client with custom events
|
||||||
* sets client in the offline mode, so it do not connects to TikTok servers
|
|
||||||
* it makes sense to use it when you are testing client with your custom events
|
|
||||||
*/
|
*/
|
||||||
private boolean offline;
|
private boolean offline;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: give better description
|
* Fetch and download gifts data before TikTokLive starts
|
||||||
* <p>
|
* @apiNote If `false`, client.giftManager() does not contain initial gifts
|
||||||
* Determines if gifts data is downloaded before TikTokLive starts,
|
|
||||||
* when `false` then client.giftManager() does not contain initial gifts
|
|
||||||
*/
|
*/
|
||||||
private boolean fetchGifts = true;
|
private boolean fetchGifts = true;
|
||||||
|
|
||||||
@@ -91,6 +86,9 @@ public class LiveClientSettings {
|
|||||||
*/
|
*/
|
||||||
private long pingInterval = 5000;
|
private long pingInterval = 5000;
|
||||||
|
|
||||||
|
/** Throw an exception on 18+ Age Restriction */
|
||||||
|
private boolean throwOnAgeRestriction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optional: Sometimes not every messages from chat are send to TikTokLiveJava to fix this issue you can set sessionId
|
* Optional: Sometimes not every messages from chat are send to TikTokLiveJava to fix this issue you can set sessionId
|
||||||
* @see <a href="https://github.com/isaackogan/TikTok-Live-Connector#send-chat-messages">Documentation: How to obtain sessionId</a>
|
* @see <a href="https://github.com/isaackogan/TikTok-Live-Connector#send-chat-messages">Documentation: How to obtain sessionId</a>
|
||||||
|
|||||||
@@ -30,10 +30,14 @@ import io.github.jwdeveloper.tiktok.data.requests.LiveUserData;
|
|||||||
public interface LiveHttpClient
|
public interface LiveHttpClient
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @return list of gifts that are available in your country
|
* @return {@link GiftsData.Response} list of gifts that are compiled and available on github
|
||||||
*/
|
*/
|
||||||
GiftsData.Response fetchGiftsData();
|
GiftsData.Response fetchGiftsData();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {@link GiftsData.Response} list of gifts that are available in your region / livestream
|
||||||
|
*/
|
||||||
|
GiftsData.Response fetchRoomGiftsData(String room_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns information about user that is having a livestream
|
* Returns information about user that is having a livestream
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public interface LiveRoomInfo
|
|||||||
String getRoomId();
|
String getRoomId();
|
||||||
String getHostName();
|
String getHostName();
|
||||||
String getTitle();
|
String getTitle();
|
||||||
User getHostUser();
|
User getHost();
|
||||||
List<RankingUser> getUsersRanking();
|
List<RankingUser> getUsersRanking();
|
||||||
ConnectionState getConnectionState();
|
ConnectionState getConnectionState();
|
||||||
}
|
}
|
||||||
@@ -102,7 +102,8 @@ message Text {
|
|||||||
|
|
||||||
// @Image
|
// @Image
|
||||||
message Image {
|
message Image {
|
||||||
repeated string urlList = 1;
|
repeated string url = 1;
|
||||||
|
string extras = 2;
|
||||||
bool isAnimated = 9;
|
bool isAnimated = 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,14 @@ enum LinkmicApplierSortSetting {
|
|||||||
LINKMIC_APPLIER_SORT_SETTING_BY_GIFT_SCORE = 1;
|
LINKMIC_APPLIER_SORT_SETTING_BY_GIFT_SCORE = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum LinkMicBattleStatus {
|
||||||
|
BATTLE_ARMY_UNKNOWN = 0;
|
||||||
|
ARMY_ONGOING = 1;
|
||||||
|
ARMY_FINISHED = 2;
|
||||||
|
BATTLE_ONGOING = 4;
|
||||||
|
BATTLE_FINISHED = 5;
|
||||||
|
}
|
||||||
|
|
||||||
enum HashtagNamespace {
|
enum HashtagNamespace {
|
||||||
GLOBAL = 0;
|
GLOBAL = 0;
|
||||||
GAMING = 1;
|
GAMING = 1;
|
||||||
|
|||||||
@@ -521,7 +521,7 @@ message WebcastLinkMicArmies {
|
|||||||
uint64 id2 = 4;
|
uint64 id2 = 4;
|
||||||
uint64 timeStamp1 = 5;
|
uint64 timeStamp1 = 5;
|
||||||
uint64 timeStamp2 = 6;
|
uint64 timeStamp2 = 6;
|
||||||
int32 battleStatus = 7; // SHOULD BE AN ENUM
|
LinkMicBattleStatus battleStatus = 7;
|
||||||
uint64 data1 = 8;
|
uint64 data1 = 8;
|
||||||
uint64 data2 = 9;
|
uint64 data2 = 9;
|
||||||
uint32 data3 = 10;
|
uint32 data3 = 10;
|
||||||
@@ -574,11 +574,26 @@ message WebcastLinkMicBattle {
|
|||||||
Common common = 1;
|
Common common = 1;
|
||||||
uint64 id = 2;
|
uint64 id = 2;
|
||||||
LinkMicBattleConfig battleConfig = 3;
|
LinkMicBattleConfig battleConfig = 3;
|
||||||
uint32 data2 = 4;
|
LinkMicBattleStatus battleStatus = 4;
|
||||||
repeated LinkMicBattleDetails details = 5;
|
repeated LinkMicBattleDetails details = 5;
|
||||||
repeated LinkMicBattleTeam teams1 = 9;
|
repeated LinkMicBattleTopViewers viewerTeam = 9;
|
||||||
repeated LinkMicBattleTeam teams2 = 10;
|
repeated LinkMicBattleHost hostTeam = 10;
|
||||||
repeated LinkMicBattleTeamData teamData = 13;
|
repeated LinkMicBattleTeamData teamData = 13;
|
||||||
|
uint64 unknownData16 = 16;
|
||||||
|
repeated Host2v2Data hostData2v2 = 17;
|
||||||
|
|
||||||
|
message Host2v2Data {
|
||||||
|
uint32 teamNumber = 1;
|
||||||
|
repeated HostData hostdata = 2;
|
||||||
|
uint32 unknownData3 = 3;
|
||||||
|
uint32 totalPoints = 4;
|
||||||
|
|
||||||
|
message HostData {
|
||||||
|
uint64 hostId = 1;
|
||||||
|
uint32 points = 2;
|
||||||
|
string hostIdStr = 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
message LinkMicBattleConfig {
|
message LinkMicBattleConfig {
|
||||||
uint64 id1 = 1;
|
uint64 id1 = 1;
|
||||||
@@ -586,29 +601,69 @@ message WebcastLinkMicBattle {
|
|||||||
uint32 data1 = 3;
|
uint32 data1 = 3;
|
||||||
uint64 id2 = 4;
|
uint64 id2 = 4;
|
||||||
uint32 data2 = 5;
|
uint32 data2 = 5;
|
||||||
|
uint32 data3 = 6;
|
||||||
|
uint32 data4 = 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
message LinkMicBattleTeamData {
|
||||||
|
uint64 teamId = 1;
|
||||||
|
LinkMicBattleData data = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message LinkMicBattleData {
|
message LinkMicBattleData {
|
||||||
uint64 id = 1;
|
uint64 id = 1;
|
||||||
uint32 data1 = 2;
|
uint32 data1 = 2;
|
||||||
uint32 data2 = 3;
|
uint32 winStreak = 3;
|
||||||
uint32 data3 = 5;
|
uint32 data3 = 5;
|
||||||
string url = 6;
|
string url = 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
message LinkMicBattleDetails {
|
message LinkMicBattleDetails {
|
||||||
uint64 id = 1;
|
uint64 id = 1;
|
||||||
LinkMicBattleData details = 2;
|
LinkMicBattleDetailsSummary summary = 2;
|
||||||
|
|
||||||
|
message LinkMicBattleDetailsSummary {
|
||||||
|
uint64 id = 1;
|
||||||
|
uint32 unknownData2 = 2;
|
||||||
|
uint32 points = 3;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
message LinkMicBattleTeam {
|
message LinkMicBattleTopViewers {
|
||||||
uint64 id = 1;
|
uint64 id = 1;
|
||||||
repeated User users = 2;
|
repeated TopViewerGroup viewerGroup = 2;
|
||||||
|
|
||||||
|
message TopViewerGroup {
|
||||||
|
repeated TopViewer viewer = 1;
|
||||||
|
uint32 points = 2;
|
||||||
|
string hostIdOrTeamNum = 3; // 1v1 Battle = HostId | 2v2 Battle = Team # - 1 & 2
|
||||||
|
|
||||||
|
message TopViewer {
|
||||||
|
uint64 id = 1;
|
||||||
|
uint32 points = 2;
|
||||||
|
string profileId = 3;
|
||||||
|
repeated Image images = 4;
|
||||||
|
string stringId = 6;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
message LinkMicBattleTeamData {
|
message LinkMicBattleHost {
|
||||||
uint64 teamId = 1;
|
uint64 id = 1;
|
||||||
LinkMicBattleData data = 2;
|
repeated HostGroup hostGroup = 2;
|
||||||
|
|
||||||
|
message HostGroup {
|
||||||
|
repeated Host host = 1;
|
||||||
|
uint32 points = 2;
|
||||||
|
string hostId = 3;
|
||||||
|
|
||||||
|
message Host {
|
||||||
|
uint64 id = 1;
|
||||||
|
string profileId = 2;
|
||||||
|
repeated Image images = 3;
|
||||||
|
string name = 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -792,6 +847,4 @@ message RoomVerifyMessage {
|
|||||||
string content = 3;
|
string content = 3;
|
||||||
int64 noticeType = 4;
|
int64 noticeType = 4;
|
||||||
bool closeRoom = 5;
|
bool closeRoom = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<version>1.5.3-Release</version>
|
<version>1.6.2-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,6 @@ public class TikTokLive {
|
|||||||
return new TikTokLiveHttpClient();
|
return new TikTokLiveHttpClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//I don't like it, but it is reasonable for now
|
//I don't like it, but it is reasonable for now
|
||||||
private static GiftsManager giftsManager;
|
private static GiftsManager giftsManager;
|
||||||
|
|
||||||
@@ -108,6 +107,4 @@ public class TikTokLive {
|
|||||||
}
|
}
|
||||||
return giftsManager;
|
return giftsManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -23,26 +23,19 @@
|
|||||||
package io.github.jwdeveloper.tiktok;
|
package io.github.jwdeveloper.tiktok;
|
||||||
|
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.TikTokDisconnectedEvent;
|
import io.github.jwdeveloper.tiktok.data.events.*;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.TikTokErrorEvent;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.TikTokReconnectingEvent;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.control.*;
|
import io.github.jwdeveloper.tiktok.data.events.control.*;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.http.TikTokRoomDataResponseEvent;
|
import io.github.jwdeveloper.tiktok.data.events.http.TikTokRoomDataResponseEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.events.room.TikTokRoomInfoEvent;
|
import io.github.jwdeveloper.tiktok.data.events.room.TikTokRoomInfoEvent;
|
||||||
import io.github.jwdeveloper.tiktok.data.requests.LiveConnectionData;
|
import io.github.jwdeveloper.tiktok.data.requests.*;
|
||||||
import io.github.jwdeveloper.tiktok.data.requests.LiveData;
|
import io.github.jwdeveloper.tiktok.data.settings.LiveClientSettings;
|
||||||
import io.github.jwdeveloper.tiktok.data.requests.LiveUserData;
|
|
||||||
import io.github.jwdeveloper.tiktok.exceptions.*;
|
import io.github.jwdeveloper.tiktok.exceptions.*;
|
||||||
import io.github.jwdeveloper.tiktok.http.LiveHttpClient;
|
import io.github.jwdeveloper.tiktok.http.LiveHttpClient;
|
||||||
import io.github.jwdeveloper.tiktok.listener.ListenersManager;
|
import io.github.jwdeveloper.tiktok.listener.*;
|
||||||
import io.github.jwdeveloper.tiktok.listener.TikTokListenersManager;
|
import io.github.jwdeveloper.tiktok.live.*;
|
||||||
import io.github.jwdeveloper.tiktok.live.GiftsManager;
|
|
||||||
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
|
||||||
import io.github.jwdeveloper.tiktok.live.LiveRoomInfo;
|
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastResponse;
|
||||||
import io.github.jwdeveloper.tiktok.models.ConnectionState;
|
import io.github.jwdeveloper.tiktok.models.ConnectionState;
|
||||||
import io.github.jwdeveloper.tiktok.data.settings.LiveClientSettings;
|
|
||||||
import io.github.jwdeveloper.tiktok.websocket.SocketClient;
|
import io.github.jwdeveloper.tiktok.websocket.SocketClient;
|
||||||
|
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
@@ -135,6 +128,9 @@ public class TikTokLiveClient implements LiveClient {
|
|||||||
liveRoomInfo.setStartTime(userData.getStartedAtTimeStamp());
|
liveRoomInfo.setStartTime(userData.getStartedAtTimeStamp());
|
||||||
liveRoomInfo.setRoomId(userData.getRoomId());
|
liveRoomInfo.setRoomId(userData.getRoomId());
|
||||||
|
|
||||||
|
if (clientSettings.isFetchGifts())
|
||||||
|
giftsManager.attachGiftsList(httpClient.fetchRoomGiftsData(userData.getRoomId()).getGifts());
|
||||||
|
|
||||||
if (userData.getUserStatus() == LiveUserData.UserStatus.Offline)
|
if (userData.getUserStatus() == LiveUserData.UserStatus.Offline)
|
||||||
throw new TikTokLiveOfflineHostException("User is offline: " + liveRoomInfo.getHostName());
|
throw new TikTokLiveOfflineHostException("User is offline: " + liveRoomInfo.getHostName());
|
||||||
|
|
||||||
@@ -144,7 +140,7 @@ public class TikTokLiveClient implements LiveClient {
|
|||||||
var liveDataRequest = new LiveData.Request(userData.getRoomId());
|
var liveDataRequest = new LiveData.Request(userData.getRoomId());
|
||||||
var liveData = httpClient.fetchLiveData(liveDataRequest);
|
var liveData = httpClient.fetchLiveData(liveDataRequest);
|
||||||
|
|
||||||
if (liveData.isAgeRestricted())
|
if (liveData.isAgeRestricted() && clientSettings.isThrowOnAgeRestriction())
|
||||||
throw new TikTokLiveException("Livestream for " + liveRoomInfo.getHostName() + " is 18+ or age restricted!");
|
throw new TikTokLiveException("Livestream for " + liveRoomInfo.getHostName() + " is 18+ or age restricted!");
|
||||||
|
|
||||||
if (liveData.getLiveStatus() == LiveData.LiveStatus.HostNotFound)
|
if (liveData.getLiveStatus() == LiveData.LiveStatus.HostNotFound)
|
||||||
|
|||||||
@@ -207,9 +207,15 @@ public class TikTokLiveClientBuilder implements LiveClientBuilder {
|
|||||||
|
|
||||||
|
|
||||||
//LinkMic events
|
//LinkMic events
|
||||||
// mapper.webcastObjectToConstructor(WebcastLinkMicBattle.class, TikTokLinkMicBattleEvent.class);
|
mapper.forMessage(WebcastLinkMicBattle.class, (inputBytes, messageName, mapperHelper) -> {
|
||||||
// mapper.webcastObjectToConstructor(WebcastLinkMicArmies.class, TikTokLinkMicArmiesEvent.class);
|
var message = mapperHelper.bytesToWebcastObject(inputBytes, WebcastLinkMicBattle.class);
|
||||||
// mapper.webcastObjectToConstructor(WebcastLinkMicMethod.class, TikTokLinkMicMethodEvent.class);
|
return MappingResult.of(message, new TikTokLinkMicBattleEvent(message));
|
||||||
|
});
|
||||||
|
mapper.forMessage(WebcastLinkMicArmies.class, (inputBytes, messageName, mapperHelper) -> {
|
||||||
|
var message = mapperHelper.bytesToWebcastObject(inputBytes, WebcastLinkMicArmies.class);
|
||||||
|
return MappingResult.of(message, new TikTokLinkMicArmiesEvent(message));
|
||||||
|
});
|
||||||
|
// mapper.webcastObjectToConstructor(WebcastLinkMicMethod.class, TikTokLinkMicMethodEvent.class);
|
||||||
// mapper.webcastObjectToConstructor(WebcastLinkMicFanTicketMethod.class, TikTokLinkMicFanTicketEvent.class);
|
// mapper.webcastObjectToConstructor(WebcastLinkMicFanTicketMethod.class, TikTokLinkMicFanTicketEvent.class);
|
||||||
|
|
||||||
//Rank events
|
//Rank events
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
private static final String TIKTOK_URL_WEB = "https://www.tiktok.com/";
|
private static final String TIKTOK_URL_WEB = "https://www.tiktok.com/";
|
||||||
private static final String TIKTOK_URL_WEBCAST = "https://webcast.tiktok.com/webcast/";
|
private static final String TIKTOK_URL_WEBCAST = "https://webcast.tiktok.com/webcast/";
|
||||||
public static final String TIKTOK_GIFTS_URL = "https://raw.githubusercontent.com/TikTok-LIVE-Private/GiftsGenerator/master/page/public/gifts.json";
|
public static final String TIKTOK_GIFTS_URL = "https://raw.githubusercontent.com/TikTok-LIVE-Private/GiftsGenerator/master/page/public/gifts.json";
|
||||||
|
public static final String TIKTOK_ROOM_GIFTS_URL = TIKTOK_URL_WEBCAST+"gift/list/";
|
||||||
public static final int TIKTOK_AGE_RESTRICTED_CODE = 4003110;
|
public static final int TIKTOK_AGE_RESTRICTED_CODE = 4003110;
|
||||||
|
|
||||||
private final HttpClientFactory httpFactory;
|
private final HttpClientFactory httpFactory;
|
||||||
@@ -65,6 +66,31 @@ public class TikTokLiveHttpClient implements LiveHttpClient
|
|||||||
this(new HttpClientFactory(LiveClientSettings.createDefault()), LiveClientSettings.createDefault());
|
this(new HttpClientFactory(LiveClientSettings.createDefault()), LiveClientSettings.createDefault());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GiftsData.Response fetchRoomGiftsData(String room_id) {
|
||||||
|
var proxyClientSettings = clientSettings.getHttpSettings().getProxyClientSettings();
|
||||||
|
if (proxyClientSettings.isEnabled()) {
|
||||||
|
while (proxyClientSettings.hasNext()) {
|
||||||
|
try {
|
||||||
|
return getRoomGiftsData(room_id);
|
||||||
|
} catch (TikTokProxyRequestException ignored) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return getRoomGiftsData(room_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GiftsData.Response getRoomGiftsData(String room_id) {
|
||||||
|
var result = httpFactory.client(TIKTOK_ROOM_GIFTS_URL)
|
||||||
|
.withParam("room_id", room_id)
|
||||||
|
.build()
|
||||||
|
.toJsonResponse();
|
||||||
|
|
||||||
|
if (result.isFailure())
|
||||||
|
throw new TikTokLiveRequestException("Unable to fetch gifts information's - "+result);
|
||||||
|
|
||||||
|
var json = result.getContent();
|
||||||
|
return giftsDataMapper.mapRoom(json);
|
||||||
|
}
|
||||||
|
|
||||||
public GiftsData.Response fetchGiftsData() {
|
public GiftsData.Response fetchGiftsData() {
|
||||||
var proxyClientSettings = clientSettings.getHttpSettings().getProxyClientSettings();
|
var proxyClientSettings = clientSettings.getHttpSettings().getProxyClientSettings();
|
||||||
if (proxyClientSettings.isEnabled()) {
|
if (proxyClientSettings.isEnabled()) {
|
||||||
|
|||||||
@@ -18,6 +18,11 @@ public class TikTokLiveHttpOfflineClient implements LiveHttpClient {
|
|||||||
return new GiftsData.Response("", List.of());
|
return new GiftsData.Response("", List.of());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GiftsData.Response fetchRoomGiftsData(String room_id) {
|
||||||
|
return new GiftsData.Response("", List.of());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LiveUserData.Response fetchLiveUserData(LiveUserData.Request request) {
|
public LiveUserData.Response fetchLiveUserData(LiveUserData.Request request) {
|
||||||
return new LiveUserData.Response("", LiveUserData.UserStatus.Live, "offline_room_id", 0);
|
return new LiveUserData.Response("", LiveUserData.UserStatus.Live, "offline_room_id", 0);
|
||||||
@@ -42,4 +47,4 @@ public class TikTokLiveHttpOfflineClient implements LiveHttpClient {
|
|||||||
URI.create("https://example.live"),
|
URI.create("https://example.live"),
|
||||||
WebcastResponse.newBuilder().build());
|
WebcastResponse.newBuilder().build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -61,11 +61,6 @@ public class TikTokRoomInfo implements LiveRoomInfo {
|
|||||||
return connectionState == state;
|
return connectionState == state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public User getHostUser() {
|
|
||||||
return host;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateRanking(List<RankingUser> rankingUsers) {
|
public void updateRanking(List<RankingUser> rankingUsers) {
|
||||||
usersRanking.clear();
|
usersRanking.clear();
|
||||||
usersRanking.addAll(rankingUsers);
|
usersRanking.addAll(rankingUsers);
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
package io.github.jwdeveloper.tiktok.gifts;
|
package io.github.jwdeveloper.tiktok.gifts;
|
||||||
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
|
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
|
||||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException;
|
|
||||||
import io.github.jwdeveloper.tiktok.live.GiftsManager;
|
import io.github.jwdeveloper.tiktok.live.GiftsManager;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.function.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.function.Predicate;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class TikTokGiftsManager implements GiftsManager {
|
public class TikTokGiftsManager implements GiftsManager {
|
||||||
@@ -16,7 +12,7 @@ public class TikTokGiftsManager implements GiftsManager {
|
|||||||
|
|
||||||
public TikTokGiftsManager(List<Gift> giftList)
|
public TikTokGiftsManager(List<Gift> giftList)
|
||||||
{
|
{
|
||||||
giftsByIdIndex = giftList.stream().collect(Collectors.toConcurrentMap(Gift::getId, e -> e));
|
giftsByIdIndex = giftList.stream().collect(Collectors.toConcurrentMap(Gift::getId, Function.identity()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void attachGift(Gift gift) {
|
public void attachGift(Gift gift) {
|
||||||
@@ -32,11 +28,7 @@ public class TikTokGiftsManager implements GiftsManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Gift getById(int giftId) {
|
public Gift getById(int giftId) {
|
||||||
if (!giftsByIdIndex.containsKey(giftId)) {
|
return giftsByIdIndex.getOrDefault(giftId, Gift.UNDEFINED);
|
||||||
return Gift.UNDEFINED;
|
|
||||||
}
|
|
||||||
|
|
||||||
return giftsByIdIndex.get(giftId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Gift getByFilter(Predicate<Gift> filter) {
|
public Gift getByFilter(Predicate<Gift> filter) {
|
||||||
@@ -44,7 +36,7 @@ public class TikTokGiftsManager implements GiftsManager {
|
|||||||
.stream()
|
.stream()
|
||||||
.filter(filter)
|
.filter(filter)
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElseGet(() -> Gift.UNDEFINED);
|
.orElse(Gift.UNDEFINED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -62,4 +54,4 @@ public class TikTokGiftsManager implements GiftsManager {
|
|||||||
public Map<Integer, Gift> toMap() {
|
public Map<Integer, Gift> toMap() {
|
||||||
return Collections.unmodifiableMap(giftsByIdIndex);
|
return Collections.unmodifiableMap(giftsByIdIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,15 +22,15 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.jwdeveloper.tiktok.http.mappers;
|
package io.github.jwdeveloper.tiktok.http.mappers;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.*;
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
|
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
|
||||||
import io.github.jwdeveloper.tiktok.data.requests.GiftsData;
|
import io.github.jwdeveloper.tiktok.data.requests.GiftsData;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.List;
|
||||||
|
|
||||||
public class GiftsDataMapper {
|
public class GiftsDataMapper {
|
||||||
|
|
||||||
public GiftsData.Response map(String json) {
|
public GiftsData.Response map(String json) {
|
||||||
var parsedJson = JsonParser.parseString(json);
|
var parsedJson = JsonParser.parseString(json);
|
||||||
var jsonObject = parsedJson.getAsJsonObject();
|
var jsonObject = parsedJson.getAsJsonObject();
|
||||||
@@ -42,7 +42,6 @@ public class GiftsDataMapper {
|
|||||||
return new GiftsData.Response(json, gifts);
|
return new GiftsData.Response(json, gifts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Gift mapSingleGift(JsonElement jsonElement) {
|
private Gift mapSingleGift(JsonElement jsonElement) {
|
||||||
var jsonObject = jsonElement.getAsJsonObject();
|
var jsonObject = jsonElement.getAsJsonObject();
|
||||||
|
|
||||||
@@ -52,4 +51,34 @@ public class GiftsDataMapper {
|
|||||||
var image = jsonObject.get("image").getAsString();
|
var image = jsonObject.get("image").getAsString();
|
||||||
return new Gift(id, name, diamondCost, new Picture(image), jsonObject);
|
return new Gift(id, name, diamondCost, new Picture(image), jsonObject);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public GiftsData.Response mapRoom(String json) {
|
||||||
|
var parsedJson = JsonParser.parseString(json);
|
||||||
|
var jsonObject = parsedJson.getAsJsonObject();
|
||||||
|
if (jsonObject.get("data") instanceof JsonObject data && data.get("gifts") instanceof JsonArray giftArray) {
|
||||||
|
var gifts = giftArray.asList().parallelStream()
|
||||||
|
.map(this::mapSingleRoomGift)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
return new GiftsData.Response(json, gifts);
|
||||||
|
}
|
||||||
|
return new GiftsData.Response("", List.of());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Gift mapSingleRoomGift(JsonElement jsonElement) {
|
||||||
|
var jsonObject = jsonElement.getAsJsonObject();
|
||||||
|
|
||||||
|
var id = jsonObject.get("id").getAsInt();
|
||||||
|
var name = jsonObject.get("name").getAsString();
|
||||||
|
var diamondCost = jsonObject.get("diamond_count").getAsInt();
|
||||||
|
Picture picture;
|
||||||
|
if (jsonObject.get("image") instanceof JsonObject image && image.get("url_list") instanceof JsonArray urls && !urls.isEmpty()) {
|
||||||
|
String url = urls.get(0).getAsString();
|
||||||
|
if (url.endsWith(".webp"))
|
||||||
|
url = url.substring(0, url.length()-4)+"png";
|
||||||
|
picture = new Picture(url);
|
||||||
|
} else
|
||||||
|
picture = Picture.empty();
|
||||||
|
return new Gift(id, name, diamondCost, picture, jsonObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -65,8 +65,7 @@ public class LiveDataMapper {
|
|||||||
default -> LiveData.LiveStatus.HostNotFound;
|
default -> LiveData.LiveStatus.HostNotFound;
|
||||||
};
|
};
|
||||||
response.setLiveStatus(statusValue);
|
response.setLiveStatus(statusValue);
|
||||||
} else if (data.has("prompts") && jsonObject.has("status_code") &&
|
} else if (data.has("prompts") && data.get("prompts").getAsString().isEmpty() && jsonObject.has("status_code")) {
|
||||||
data.get("prompts").getAsString().isEmpty() && jsonObject.get("status_code").isJsonPrimitive()) {
|
|
||||||
response.setAgeRestricted(jsonObject.get("status_code").getAsInt() == TikTokLiveHttpClient.TIKTOK_AGE_RESTRICTED_CODE);
|
response.setAgeRestricted(jsonObject.get("status_code").getAsInt() == TikTokLiveHttpClient.TIKTOK_AGE_RESTRICTED_CODE);
|
||||||
} else {
|
} else {
|
||||||
response.setLiveStatus(LiveData.LiveStatus.HostNotFound);
|
response.setLiveStatus(LiveData.LiveStatus.HostNotFound);
|
||||||
|
|||||||
@@ -27,13 +27,11 @@ import io.github.jwdeveloper.tiktok.data.events.common.TikTokEvent;
|
|||||||
import io.github.jwdeveloper.tiktok.data.events.gift.*;
|
import io.github.jwdeveloper.tiktok.data.events.gift.*;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||||
import io.github.jwdeveloper.tiktok.data.models.gifts.*;
|
import io.github.jwdeveloper.tiktok.data.models.gifts.*;
|
||||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveException;
|
|
||||||
import io.github.jwdeveloper.tiktok.live.GiftsManager;
|
import io.github.jwdeveloper.tiktok.live.GiftsManager;
|
||||||
import io.github.jwdeveloper.tiktok.mappers.TikTokMapperHelper;
|
import io.github.jwdeveloper.tiktok.mappers.TikTokMapperHelper;
|
||||||
import io.github.jwdeveloper.tiktok.mappers.data.MappingResult;
|
import io.github.jwdeveloper.tiktok.mappers.data.MappingResult;
|
||||||
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastGiftMessage;
|
import io.github.jwdeveloper.tiktok.messages.webcast.WebcastGiftMessage;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import sun.misc.Unsafe;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -124,36 +122,8 @@ public class TikTokGiftEventHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (gift.getPicture().getLink().endsWith(".webp"))
|
if (gift.getPicture().getLink().endsWith(".webp"))
|
||||||
{
|
gift.setPicture(Picture.map(giftMessage.getGift().getImage()));
|
||||||
updatePicture(gift, giftMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
return gift;
|
return gift;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO-kohlerpop1: I do not think this method is needed for any reason?
|
|
||||||
// TODO response:
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Some generated gifts in JSON file contains .webp image format,
|
|
||||||
* that's bad since java by the defult is not supporing .webp and when URL is
|
|
||||||
* converted to Java.io.Image then image is null
|
|
||||||
*
|
|
||||||
* However, TikTok in GiftWebcast event always has image in .jpg format,
|
|
||||||
* so I take advantage of it and swap .webp url with .jpg url
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
private void updatePicture(Gift gift, WebcastGiftMessage webcastGiftMessage) {
|
|
||||||
try {
|
|
||||||
var picture = Picture.map(webcastGiftMessage.getGift().getImage());
|
|
||||||
var constructor = Unsafe.class.getDeclaredConstructors()[0];
|
|
||||||
constructor.setAccessible(true);
|
|
||||||
var field = Gift.class.getDeclaredField("picture");
|
|
||||||
field.setAccessible(true);
|
|
||||||
field.set(gift, picture);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new TikTokLiveException("Unable to update picture in gift: " + gift.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ public class TikTokWebSocketClient implements SocketClient {
|
|||||||
|
|
||||||
messageHandler.handle(liveClient, connectionData.getWebcastResponse());
|
messageHandler.handle(liveClient, connectionData.getWebcastResponse());
|
||||||
|
|
||||||
var headers = new HashMap<String, String>();
|
var headers = new HashMap<>(clientSettings.getHttpSettings().getHeaders());
|
||||||
headers.put("Cookie", connectionData.getWebsocketCookies());
|
headers.put("Cookie", connectionData.getWebsocketCookies());
|
||||||
webSocketClient = new TikTokWebSocketListener(connectionData.getWebsocketUrl(),
|
webSocketClient = new TikTokWebSocketListener(connectionData.getWebsocketUrl(),
|
||||||
headers,
|
headers,
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ class TikTokGiftEventHandlerTest {
|
|||||||
|
|
||||||
giftBuilder.setId(giftId);
|
giftBuilder.setId(giftId);
|
||||||
giftBuilder.setName(giftName);
|
giftBuilder.setName(giftName);
|
||||||
giftBuilder.setImage(Image.newBuilder().addUrlList(giftImage).build());
|
giftBuilder.setImage(Image.newBuilder().addUrl(giftImage).build());
|
||||||
giftBuilder.setType(streakable ? 1 : 0);
|
giftBuilder.setType(streakable ? 1 : 0);
|
||||||
userBuilder.setId(userId);
|
userBuilder.setId(userId);
|
||||||
|
|
||||||
@@ -129,4 +129,4 @@ class TikTokGiftEventHandlerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<version>1.5.3-Release</version>
|
<version>1.6.2-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
@@ -75,7 +75,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<artifactId>extension-collector</artifactId>
|
<artifactId>extension-collector</artifactId>
|
||||||
<version>1.5.3-Release</version>
|
<version>1.6.2-Release</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ Maven
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.jwdeveloper.TikTok-Live-Java</groupId>
|
<groupId>com.github.jwdeveloper.TikTok-Live-Java</groupId>
|
||||||
<artifactId>Client</artifactId>
|
<artifactId>Client</artifactId>
|
||||||
<version>1.5.0-Release</version>
|
<version>1.6.0-Release</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<version>1.5.3-Release</version>
|
<version>1.6.2-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<version>1.5.3-Release</version>
|
<version>1.6.2-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<artifactId>API</artifactId>
|
<artifactId>API</artifactId>
|
||||||
<version>1.5.3-Release</version>
|
<version>1.6.2-Release</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -25,9 +25,14 @@ package io.github.jwdeveloper.tiktok.extension.collector.api.settings;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.function.*;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class FileDataCollectorSettings {
|
public class FileDataCollectorSettings {
|
||||||
|
|
||||||
private File parentFile;
|
private File parentFile;
|
||||||
|
private BiPredicate<String, String> typeFilter = (dataType, dataTypeName) -> true;
|
||||||
|
private Predicate<String> userFilter = (tiktokUser) -> true;
|
||||||
|
private boolean useFileLocks = false;
|
||||||
|
private boolean appendUserName = false;
|
||||||
}
|
}
|
||||||
@@ -5,17 +5,20 @@ import io.github.jwdeveloper.tiktok.extension.collector.api.settings.FileDataCol
|
|||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
import org.bson.json.JsonWriterSettings;
|
import org.bson.json.JsonWriterSettings;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
import java.nio.file.*;
|
||||||
import java.nio.file.Files;
|
import java.util.*;
|
||||||
import java.nio.file.StandardOpenOption;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.locks.*;
|
||||||
|
|
||||||
public class FileStorage implements Storage {
|
public class FileStorage implements Storage {
|
||||||
|
|
||||||
private final FileDataCollectorSettings settings;
|
private final FileDataCollectorSettings settings;
|
||||||
|
private final Map<String, ReentrantLock> locks;
|
||||||
|
|
||||||
public FileStorage(FileDataCollectorSettings fileDataCollectorSettings) {
|
public FileStorage(FileDataCollectorSettings fileDataCollectorSettings) {
|
||||||
this.settings = fileDataCollectorSettings;
|
this.settings = fileDataCollectorSettings;
|
||||||
|
this.locks = settings.isUseFileLocks() ? new ConcurrentHashMap<>() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -30,13 +33,25 @@ public class FileStorage implements Storage {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void insert(Document document) {
|
public void insert(Document document) {
|
||||||
var fileName = document.get("dataType") + "_" + document.get("dataTypeName") + ".json";
|
if (settings.getTypeFilter().test(document.getString("dataType"), document.getString("dataTypeName")) && settings.getUserFilter().test(document.getString("tiktokUser"))) {
|
||||||
|
var fileName = document.get("dataType") + "_" + document.get("dataTypeName") + (settings.isAppendUserName() ? "_"+document.getString("tiktokUser") : "") + ".json";
|
||||||
|
if (settings.isUseFileLocks()) {
|
||||||
|
var lock = locks.computeIfAbsent(fileName, s -> new ReentrantLock());
|
||||||
|
lock.lock();
|
||||||
|
save(document, fileName);
|
||||||
|
lock.unlock();
|
||||||
|
} else
|
||||||
|
save(document, fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void save(Document document, String fileName) {
|
||||||
try {
|
try {
|
||||||
var file = new File(settings.getParentFile(), fileName);
|
var file = new File(settings.getParentFile(), fileName);
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
Files.writeString(file.toPath(), document.toJson(JsonWriterSettings.builder().indent(true).build()), StandardOpenOption.APPEND);
|
Files.writeString(file.toPath(), document.toJson(JsonWriterSettings.builder().indent(true).build())+'\n', StandardOpenOption.APPEND);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<version>1.5.3-Release</version>
|
<version>1.6.2-Release</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>extension-recorder</artifactId>
|
<artifactId>extension-recorder</artifactId>
|
||||||
|
|||||||
6
pom.xml
6
pom.xml
@@ -7,7 +7,7 @@
|
|||||||
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
<groupId>io.github.jwdeveloper.tiktok</groupId>
|
||||||
<artifactId>TikTokLiveJava</artifactId>
|
<artifactId>TikTokLiveJava</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>1.5.3-Release</version>
|
<version>1.6.2-Release</version>
|
||||||
<modules>
|
<modules>
|
||||||
<module>API</module>
|
<module>API</module>
|
||||||
<module>Client</module>
|
<module>Client</module>
|
||||||
@@ -77,7 +77,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<version>1.18.22</version>
|
<version>1.18.32</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -106,4 +106,4 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
Reference in New Issue
Block a user