aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/utility/YouTubeAPI.java
diff options
context:
space:
mode:
authorPinapelz <yukais@pinapelz.com>2023-12-12 20:00:01 -0800
committerPinapelz <yukais@pinapelz.com>2023-12-12 20:00:01 -0800
commit9038849e18337b87fc235f80f7ac196a7194ccd5 (patch)
tree1342a0e3f92ad994b15fc0375f2c5161490cc841 /src/main/java/utility/YouTubeAPI.java
parentef8f8b47190c6f66afe6a36fe41ebe865dfe50e3 (diff)
Add support for queueing full YouTube playlist via /play
Signed-off-by: Pinapelz <yukais@pinapelz.com>
Diffstat (limited to 'src/main/java/utility/YouTubeAPI.java')
-rw-r--r--src/main/java/utility/YouTubeAPI.java22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/main/java/utility/YouTubeAPI.java b/src/main/java/utility/YouTubeAPI.java
index c50897a..982a1d3 100644
--- a/src/main/java/utility/YouTubeAPI.java
+++ b/src/main/java/utility/YouTubeAPI.java
@@ -9,6 +9,7 @@ import java.io.*;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
public class YouTubeAPI {
private String ytapiKey = "";
@@ -43,4 +44,25 @@ public class YouTubeAPI {
}
}
+ public String[] getPlaylistVideoURLs(String playlistID, int maxResults) throws IOException{
+ String url = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults="+ maxResults +"&playlistId=" + playlistID + "&key=" + ytapiKey;
+ try (InputStream is = new URL(url).openStream();
+ BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
+ StringBuilder sb = new StringBuilder();
+ int cb;
+ while ((cb = br.read()) != -1) {
+ sb.append((char) cb);
+ }
+ JSONObject jsonObject = new JSONObject(sb.toString());
+ JSONArray jsonArray = jsonObject.getJSONArray("items");
+ String[] result = new String[jsonArray.length()];
+ for(int i = 0; i < jsonArray.length(); i++){
+ result[i] = "https://www.youtube.com/watch?v=" + jsonArray.getJSONObject(i).getJSONObject("snippet").getJSONObject("resourceId").getString("videoId");
+ }
+ return result;
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage