Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/com/github/felipeucelli/javatube/InnerTube.java
Original file line number Diff line number Diff line change
Expand Up @@ -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\": {" +
Expand Down
20 changes: 17 additions & 3 deletions src/main/java/com/github/felipeucelli/javatube/Youtube.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,25 @@ 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 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 {
Expand Down