You've already forked Arcturus-Morningstar-Extended
mirror of
https://github.com/duckietm/Arcturus-Morningstar-Extended.git
synced 2026-06-19 15:06:19 +00:00
Merge remote-tracking branch 'upstream/main' into feature/checkpoint-20260403
This commit is contained in:
@@ -76,7 +76,11 @@ public class YoutubeManager {
|
||||
|
||||
private final THashMap<Integer, ArrayList<YoutubePlaylist>> playlists = new THashMap<>();
|
||||
private final THashMap<String, YoutubePlaylist> playlistCache = new THashMap<>();
|
||||
private final String apiKey = Emulator.getConfig().getValue("youtube.apikey");
|
||||
|
||||
private String getApiKey() {
|
||||
String key = Emulator.getConfig().getValue("youtube.apikey");
|
||||
return key != null ? key : "";
|
||||
}
|
||||
|
||||
public void load() {
|
||||
this.playlists.clear();
|
||||
@@ -89,11 +93,19 @@ public class YoutubeManager {
|
||||
|
||||
LOGGER.info("YouTube Manager -> Loading...");
|
||||
|
||||
if (getApiKey().isEmpty()) {
|
||||
LOGGER.warn("YouTube Manager -> No API key configured (youtube.apikey). YouTube TVs will not work!");
|
||||
}
|
||||
|
||||
int dbEntryCount = 0;
|
||||
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT * FROM youtube_playlists")) {
|
||||
try (ResultSet set = statement.executeQuery()) {
|
||||
while (set.next()) {
|
||||
final int itemId = set.getInt("item_id");
|
||||
final String playlistId = set.getString("playlist_id");
|
||||
dbEntryCount++;
|
||||
|
||||
LOGGER.info("YouTube Manager -> Loading playlist {} for base item #{}", playlistId, itemId);
|
||||
|
||||
youtubeDataLoaderPool.submit(() -> {
|
||||
YoutubePlaylist playlist;
|
||||
@@ -101,6 +113,9 @@ public class YoutubeManager {
|
||||
playlist = this.getPlaylistDataById(playlistId);
|
||||
if (playlist != null) {
|
||||
this.addPlaylistToItem(itemId, playlist);
|
||||
LOGGER.info("YouTube Manager -> Successfully loaded playlist {} for base item #{}", playlistId, itemId);
|
||||
} else {
|
||||
LOGGER.error("YouTube Manager -> Failed to load playlist {} for base item #{} (returned null - check API key and playlist ID)", playlistId, itemId);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("Failed to load YouTube playlist {} ERROR: {}", playlistId, e);
|
||||
@@ -112,6 +127,10 @@ public class YoutubeManager {
|
||||
LOGGER.error("Caught SQL exception", e);
|
||||
}
|
||||
|
||||
if (dbEntryCount == 0) {
|
||||
LOGGER.warn("YouTube Manager -> No entries found in youtube_playlists table!");
|
||||
}
|
||||
|
||||
youtubeDataLoaderPool.shutdown();
|
||||
try {
|
||||
youtubeDataLoaderPool.awaitTermination(60, TimeUnit.SECONDS);
|
||||
@@ -125,7 +144,12 @@ public class YoutubeManager {
|
||||
|
||||
public YoutubePlaylist getPlaylistDataById(String playlistId) throws IOException {
|
||||
if (this.playlistCache.containsKey(playlistId)) return this.playlistCache.get(playlistId);
|
||||
if(apiKey.isEmpty()) return null;
|
||||
|
||||
String apiKey = getApiKey();
|
||||
if(apiKey.isEmpty()) {
|
||||
LOGGER.error("YouTube API key is not configured! Set 'youtube.apikey' in emulator_settings to enable YouTube TV.");
|
||||
return null;
|
||||
}
|
||||
|
||||
YoutubePlaylist playlist;
|
||||
URL playlistInfo = URI.create("https://youtube.googleapis.com/youtube/v3/playlists?part=snippet&id=" + playlistId + "&maxResults=1&key=" + apiKey).toURL();
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ public class InteractionYoutubeTV extends HabboItem {
|
||||
if (this.currentVideo == null) {
|
||||
serverMessage.appendString("");
|
||||
} else {
|
||||
serverMessage.appendString(Emulator.getConfig().getValue("imager.url.youtube").replace("%video%", this.currentVideo.getId()));
|
||||
serverMessage.appendString("https://img.youtube.com/vi/" + this.currentVideo.getId() + "/hqdefault.jpg");
|
||||
}
|
||||
|
||||
super.serializeExtradata(serverMessage);
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ public class YoutubeRequestPlaylistChange extends MessageHandler {
|
||||
|
||||
if (item == null || !(item instanceof InteractionYoutubeTV)) return;
|
||||
|
||||
Optional<YoutubeManager.YoutubePlaylist> playlist = Emulator.getGameEnvironment().getItemManager().getYoutubeManager().getPlaylistsForItemId(item.getBaseItem().getId()).stream().filter(p -> p.getId().equals(playlistId)).findAny();
|
||||
Optional<YoutubeManager.YoutubePlaylist> playlist = Emulator.getGameEnvironment().getItemManager().getYoutubeManager().getPlaylistsForItemId(item.getId()).stream().filter(p -> p.getId().equals(playlistId)).findAny();
|
||||
|
||||
if (playlist.isPresent()) {
|
||||
YoutubeManager.YoutubeVideo video = playlist.get().getVideos().get(0);
|
||||
|
||||
+3
-2
@@ -25,10 +25,11 @@ public class YoutubeRequestPlaylists extends MessageHandler {
|
||||
if (item instanceof InteractionYoutubeTV) {
|
||||
InteractionYoutubeTV tv = (InteractionYoutubeTV) item;
|
||||
|
||||
ArrayList<YoutubeManager.YoutubePlaylist> playlists = Emulator.getGameEnvironment().getItemManager().getYoutubeManager().getPlaylistsForItemId(item.getBaseItem().getId());
|
||||
int furniItemId = item.getId();
|
||||
ArrayList<YoutubeManager.YoutubePlaylist> playlists = Emulator.getGameEnvironment().getItemManager().getYoutubeManager().getPlaylistsForItemId(furniItemId);
|
||||
|
||||
if (playlists == null) {
|
||||
LOGGER.error("No YouTube playlists set for base item #{}", item.getBaseItem().getId());
|
||||
LOGGER.error("No YouTube playlists loaded for item #{}. Check: 1) youtube_playlists table has entries with item_id={}, 2) youtube.apikey is set in emulator_settings, 3) playlist IDs are valid YouTube playlist IDs (start with PL)", furniItemId, furniItemId);
|
||||
this.client.sendResponse(new ConnectionErrorComposer(1000));
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user