diff --git a/API/src/main/java/io/github/jwdeveloper/tiktok/annotations/Priority.java b/API/src/main/java/io/github/jwdeveloper/tiktok/annotations/Priority.java index fbec43d..8559a53 100644 --- a/API/src/main/java/io/github/jwdeveloper/tiktok/annotations/Priority.java +++ b/API/src/main/java/io/github/jwdeveloper/tiktok/annotations/Priority.java @@ -23,11 +23,12 @@ package io.github.jwdeveloper.tiktok.annotations; /** - * HIGHEST 1 - * HIGH 2 - * NORMAL 3 - * LOW 4 - * LOWEST 5 + ORDER - + * HIGHEST 1st, + * HIGH 2nd, + * NORMAL 3rd, + * LOW 4th, + * LOWEST 5th */ public enum Priority { LOWEST(2), LOW(1), NORMAL(0), HIGH(-1), HIGHEST(-2); diff --git a/API/src/main/java/io/github/jwdeveloper/tiktok/data/events/control/TikTokPreConnectionEvent.java b/API/src/main/java/io/github/jwdeveloper/tiktok/data/events/control/TikTokPreConnectionEvent.java index 93f0b55..3d37607 100644 --- a/API/src/main/java/io/github/jwdeveloper/tiktok/data/events/control/TikTokPreConnectionEvent.java +++ b/API/src/main/java/io/github/jwdeveloper/tiktok/data/events/control/TikTokPreConnectionEvent.java @@ -35,9 +35,15 @@ public class TikTokPreConnectionEvent extends TikTokLiveClientEvent private final LiveUserData.Response userData; private final LiveData.Response roomData; @Setter boolean cancelConnection = false; + @Setter String reason = "TikTokPreConnectionEvent cancelled connection!"; public TikTokPreConnectionEvent(LiveUserData.Response userData, LiveData.Response liveData) { this.userData = userData; this.roomData = liveData; } + + public void setCancelConnection(boolean cancelConnection, String reason) { + this.cancelConnection = cancelConnection; + this.reason = reason; + } } \ No newline at end of file diff --git a/API/src/main/java/io/github/jwdeveloper/tiktok/exceptions/TikTokLivePreConnectionException.java b/API/src/main/java/io/github/jwdeveloper/tiktok/exceptions/TikTokLivePreConnectionException.java new file mode 100644 index 0000000..1a04e1d --- /dev/null +++ b/API/src/main/java/io/github/jwdeveloper/tiktok/exceptions/TikTokLivePreConnectionException.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2023-2024 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.exceptions; + +import io.github.jwdeveloper.tiktok.data.events.control.TikTokPreConnectionEvent; +import lombok.Getter; + +@Getter +public class TikTokLivePreConnectionException extends TikTokLiveException +{ + private final TikTokPreConnectionEvent preconnectEvent; + + public TikTokLivePreConnectionException(TikTokPreConnectionEvent preconnectEvent) { + super(preconnectEvent.getReason()); + this.preconnectEvent = preconnectEvent; + } +} \ No newline at end of file diff --git a/Client/src/main/java/io/github/jwdeveloper/tiktok/TikTokLiveClient.java b/Client/src/main/java/io/github/jwdeveloper/tiktok/TikTokLiveClient.java index cd50f33..0f2a927 100644 --- a/Client/src/main/java/io/github/jwdeveloper/tiktok/TikTokLiveClient.java +++ b/Client/src/main/java/io/github/jwdeveloper/tiktok/TikTokLiveClient.java @@ -140,7 +140,7 @@ public class TikTokLiveClient implements LiveClient var preconnectEvent = new TikTokPreConnectionEvent(userData, liveData); tikTokEventHandler.publish(this, preconnectEvent); if (preconnectEvent.isCancelConnection()) - throw new TikTokLiveException("TikTokPreConnectionEvent cancelled connection!"); + throw new TikTokLivePreConnectionException(preconnectEvent); if (clientSettings.isFetchGifts()) giftManager.attachGiftsList(httpClient.fetchRoomGiftsData(userData.getRoomId()).getGifts()); diff --git a/extension-recorder/src/main/java/io/github/jwdeveloper/tiktok/extension/recorder/impl/RecorderListener.java b/extension-recorder/src/main/java/io/github/jwdeveloper/tiktok/extension/recorder/impl/RecorderListener.java index e568d58..dad2073 100644 --- a/extension-recorder/src/main/java/io/github/jwdeveloper/tiktok/extension/recorder/impl/RecorderListener.java +++ b/extension-recorder/src/main/java/io/github/jwdeveloper/tiktok/extension/recorder/impl/RecorderListener.java @@ -63,12 +63,14 @@ public class RecorderListener implements LiveRecorder { liveClient.getLogger().info("Searching for live download url"); downloadData = settings.getPrepareDownloadData() != null ? - settings.getPrepareDownloadData().apply(json) : - mapToDownloadData(json); + settings.getPrepareDownloadData().apply(json) : + mapToDownloadData(json); - if (downloadData.getDownloadLiveUrl().isEmpty()) - liveClient.getLogger().warning("Unable to find download live url!"); - else + if (downloadData.getDownloadLiveUrl().isEmpty()) { + liveClient.getLogger().warning("Unable to find download live url!"); + if (settings.isCancelConnectionIfNotFound()) + event.setCancelConnection(true, "Unable to find download live url!"); + } else liveClient.getLogger().info("Live download url found!"); } diff --git a/extension-recorder/src/main/java/io/github/jwdeveloper/tiktok/extension/recorder/impl/data/RecorderSettings.java b/extension-recorder/src/main/java/io/github/jwdeveloper/tiktok/extension/recorder/impl/data/RecorderSettings.java index e17b02c..c338967 100644 --- a/extension-recorder/src/main/java/io/github/jwdeveloper/tiktok/extension/recorder/impl/data/RecorderSettings.java +++ b/extension-recorder/src/main/java/io/github/jwdeveloper/tiktok/extension/recorder/impl/data/RecorderSettings.java @@ -40,6 +40,10 @@ public class RecorderSettings { private File outputFile; private Function prepareDownloadData; private boolean stopOnDisconnect = true; + /** + True to Cancel connection to live if the download url is not found + */ + private boolean cancelConnectionIfNotFound = false; public static RecorderSettings DEFAULT() { return new RecorderSettings();