mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-03-01 17:59:39 -05:00
Changes:
Generated new Gifts Json TikTokLive.isLiveOnline() check if live if online TikTokLive.isLiveOnlineAsync() TikTokLive.isHostNameValid() check if hostName is correct TikTokLive.isHostNameValidAsync()
This commit is contained in:
@@ -1,18 +1,21 @@
|
||||
package io.github.jwdeveloper.tiktok.http;
|
||||
|
||||
import io.github.jwdeveloper.tiktok.exceptions.TikTokLiveRequestException;
|
||||
import io.github.jwdeveloper.tiktok.live.LiveClient;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class TikTokLiveOnlineChecker
|
||||
public class TikTokDataChecker
|
||||
{
|
||||
|
||||
public CompletableFuture<Boolean> isOnlineAsync(String hostName) {
|
||||
return CompletableFuture.supplyAsync(() -> isOnline(hostName));
|
||||
}
|
||||
|
||||
public CompletableFuture<Boolean> isHostNameValidAsync(String hostName) {
|
||||
return CompletableFuture.supplyAsync(() -> isOnline(hostName));
|
||||
}
|
||||
|
||||
public boolean isOnline(String hostName) {
|
||||
var factory = new TikTokHttpRequestFactory(new TikTokCookieJar());
|
||||
var url = getLiveUrl(hostName);
|
||||
@@ -26,10 +29,28 @@ public class TikTokLiveOnlineChecker
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isHostNameValid(String hostName) {
|
||||
var factory = new TikTokHttpRequestFactory(new TikTokCookieJar());
|
||||
var url = getProfileUrl(hostName);
|
||||
try {
|
||||
var response = factory.get(url);
|
||||
var titleContent = extractTitleContent(response);
|
||||
return isTitleHostNameValid(titleContent, hostName);
|
||||
} catch (Exception e)
|
||||
{
|
||||
throw new TikTokLiveRequestException("Unable to make check host name valid request",e);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isTitleLiveOnline(String title) {
|
||||
return title.contains("is LIVE");
|
||||
}
|
||||
|
||||
private boolean isTitleHostNameValid(String title, String hostName)
|
||||
{
|
||||
return title.contains(hostName);
|
||||
}
|
||||
|
||||
private String extractTitleContent(String html) {
|
||||
var regex = "<title\\b[^>]*>(.*?)<\\/title>";
|
||||
var pattern = Pattern.compile(regex);
|
||||
@@ -48,4 +69,11 @@ public class TikTokLiveOnlineChecker
|
||||
sb.append("/live");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String getProfileUrl(String hostName) {
|
||||
var sb = new StringBuilder();
|
||||
sb.append("https://www.tiktok.com/@");
|
||||
sb.append(hostName);
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user