Merge branch 'patch-25' into 'dev'

Update close for try witch resources

See merge request morningstar/Arcturus-Community!197
This commit is contained in:
Mike 2020-06-01 09:32:31 -04:00
commit fa1b27f4b7

View File

@ -133,37 +133,35 @@ public class YoutubeManager {
InputStream is = conn.getInputStream(); InputStream is = conn.getInputStream();
InputStreamReader isr = new InputStreamReader(is); InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr); YoutubePlaylist playlist;
try (BufferedReader br = new BufferedReader(isr)) {
YoutubePlaylist playlist = null; playlist = null;
String inputLine;
String inputLine; while ((inputLine = br.readLine()) != null) {
while ((inputLine = br.readLine()) != null) { if (inputLine.contains("window[\"ytInitialData\"]")) {
if (inputLine.contains("window[\"ytInitialData\"]")) { JsonObject obj = new JsonParser().parse(inputLine.substring(inputLine.indexOf("{")).replace(";", "")).getAsJsonObject();
JsonObject obj = new JsonParser().parse(inputLine.substring(inputLine.indexOf("{")).replace(";", "")).getAsJsonObject();
JsonObject meta = obj.get("microformat").getAsJsonObject().get("microformatDataRenderer").getAsJsonObject();
JsonObject meta = obj.get("microformat").getAsJsonObject().get("microformatDataRenderer").getAsJsonObject(); String name = meta.get("title").getAsString();
String name = meta.get("title").getAsString(); String description = meta.get("description").getAsString();
String description = meta.get("description").getAsString();
ArrayList<YoutubeVideo> videos = new ArrayList<>();
ArrayList<YoutubeVideo> videos = new ArrayList<>();
JsonArray rawVideos = obj.get("contents").getAsJsonObject().get("twoColumnBrowseResultsRenderer").getAsJsonObject().get("tabs").getAsJsonArray().get(0).getAsJsonObject().get("tabRenderer").getAsJsonObject().get("content").getAsJsonObject().get("sectionListRenderer").getAsJsonObject().get("contents").getAsJsonArray().get(0).getAsJsonObject().get("itemSectionRenderer").getAsJsonObject().get("contents").getAsJsonArray().get(0).getAsJsonObject().get("playlistVideoListRenderer").getAsJsonObject().get("contents").getAsJsonArray();
JsonArray rawVideos = obj.get("contents").getAsJsonObject().get("twoColumnBrowseResultsRenderer").getAsJsonObject().get("tabs").getAsJsonArray().get(0).getAsJsonObject().get("tabRenderer").getAsJsonObject().get("content").getAsJsonObject().get("sectionListRenderer").getAsJsonObject().get("contents").getAsJsonArray().get(0).getAsJsonObject().get("itemSectionRenderer").getAsJsonObject().get("contents").getAsJsonArray().get(0).getAsJsonObject().get("playlistVideoListRenderer").getAsJsonObject().get("contents").getAsJsonArray();
for (JsonElement rawVideo : rawVideos) {
for (JsonElement rawVideo : rawVideos) { JsonObject videoData = rawVideo.getAsJsonObject().get("playlistVideoRenderer").getAsJsonObject();
JsonObject videoData = rawVideo.getAsJsonObject().get("playlistVideoRenderer").getAsJsonObject(); if (!videoData.has("lengthSeconds")) continue; // removed videos
if (!videoData.has("lengthSeconds")) continue; // removed videos videos.add(new YoutubeVideo(videoData.get("videoId").getAsString(), Integer.valueOf(videoData.get("lengthSeconds").getAsString())));
videos.add(new YoutubeVideo(videoData.get("videoId").getAsString(), Integer.valueOf(videoData.get("lengthSeconds").getAsString()))); }
playlist = new YoutubePlaylist(playlistId, name, description, videos);
break;
} }
playlist = new YoutubePlaylist(playlistId, name, description, videos);
break;
} }
} }
br.close();
this.playlistCache.put(playlistId, playlist); this.playlistCache.put(playlistId, playlist);
return playlist; return playlist;