From 7276a55653085b85f2ad3cbb6b4ffe450b5c1e35 Mon Sep 17 00:00:00 2001 From: funny0619 Date: Sat, 17 Jan 2026 14:42:36 +0800 Subject: [PATCH 1/2] Allow for poToken and VisitorData generation for clients on Youtube Object Creation --- .../com/github/felipeucelli/javatube/InnerTube.java | 2 ++ .../com/github/felipeucelli/javatube/Youtube.java | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/github/felipeucelli/javatube/InnerTube.java b/src/main/java/com/github/felipeucelli/javatube/InnerTube.java index b004c42..c61b712 100644 --- a/src/main/java/com/github/felipeucelli/javatube/InnerTube.java +++ b/src/main/java/com/github/felipeucelli/javatube/InnerTube.java @@ -662,6 +662,8 @@ public void insetPoToken() throws JSONException { } public void insetPoToken(String poToken, String visitorData) throws JSONException { + this.accessPoToken = poToken; + this.accessVisitorData = visitorData; JSONObject context = new JSONObject( "{" + "\"context\": {" + diff --git a/src/main/java/com/github/felipeucelli/javatube/Youtube.java b/src/main/java/com/github/felipeucelli/javatube/Youtube.java index 67e2786..7c98b8e 100644 --- a/src/main/java/com/github/felipeucelli/javatube/Youtube.java +++ b/src/main/java/com/github/felipeucelli/javatube/Youtube.java @@ -101,11 +101,16 @@ public Youtube(String url, boolean usePoToken, boolean allowCache) throws Except * */ public Youtube(String url, String clientName, boolean usePoToken, boolean allowCache) throws Exception { client = usePoToken ? "WEB" : clientName; - this.usePoToken = usePoToken; - this.allowCache = allowCache; - innerTube = new InnerTube(client, usePoToken, allowCache); + this.innerTube = new InnerTube(client, usePoToken, allowCache); urlVideo = url; watchUrl = "https://www.youtube.com/watch?v=" + getVideoId(); + this.usePoToken = usePoToken; + this.allowCache = allowCache; + if (this.usePoToken) { + String token = BotGuard.generatePoToken(getVideoId()); + String vData = getVisitorData(); + innerTube.insetPoToken(token, vData); + } } private String setVideoId() throws RegexMatchError { From 1c52c1d620a7bbbd3b6f30bc3fe206ab5f504fd9 Mon Sep 17 00:00:00 2001 From: funny0619 Date: Sat, 17 Jan 2026 15:02:03 +0800 Subject: [PATCH 2/2] Add small check to makesure poTokena and VisitorData is not null --- .../com/github/felipeucelli/javatube/Youtube.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/github/felipeucelli/javatube/Youtube.java b/src/main/java/com/github/felipeucelli/javatube/Youtube.java index 7c98b8e..044c955 100644 --- a/src/main/java/com/github/felipeucelli/javatube/Youtube.java +++ b/src/main/java/com/github/felipeucelli/javatube/Youtube.java @@ -107,12 +107,21 @@ public Youtube(String url, String clientName, boolean usePoToken, boolean allowC this.usePoToken = usePoToken; this.allowCache = allowCache; if (this.usePoToken) { - String token = BotGuard.generatePoToken(getVideoId()); - String vData = getVisitorData(); - innerTube.insetPoToken(token, vData); + String poToken = BotGuard.generatePoToken(getVideoId()); + String visitorData = getVisitorData(); + if (isValidToken(poToken) && isValidVisitorData(visitorData)) { + innerTube.insetPoToken(poToken, visitorData); + } } } + private boolean isValidToken(String poToken) { + return poToken != null && !poToken.isBlank(); + } + private boolean isValidVisitorData(String visitorData) { + return visitorData != null && !visitorData.isBlank(); + } + private String setVideoId() throws RegexMatchError { Pattern pattern = Pattern.compile("(?:v=|/)([0-9A-Za-z_-]{11}).*"); Matcher matcher = pattern.matcher(urlVideo);