Skip to content
This repository has been archived by the owner on Oct 26, 2024. It is now read-only.

fix(YouTube - Spoof video streams): Handle app left open for a long time #709

Merged
merged 3 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public static String blockInitPlaybackRequest(String originalUrlString) {
String path = originalUri.getPath();

if (path != null && path.contains("initplayback")) {
Logger.printDebug(() -> "Blocking 'initplayback' by returning unreachable url");
Logger.printDebug(() -> "Blocking 'initplayback' by clearing query");

return UNREACHABLE_HOST_URI_STRING;
return originalUri.buildUpon().clearQuery().build().toString();
}
} catch (Exception ex) {
Logger.printException(() -> "blockInitPlaybackRequest failure", ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public class StreamingDataRequest {
}
}

private static final String[] REQUEST_HEADER_KEYS = {
"Authorization", // Available only to logged in users.
"X-GOOG-API-FORMAT-VERSION",
"X-Goog-Visitor-Id"
};

/**
* TCP connection and HTTP read timeout.
*/
Expand Down Expand Up @@ -112,10 +118,12 @@ private static HttpURLConnection send(ClientType clientType, String videoId,
connection.setConnectTimeout(HTTP_TIMEOUT_MILLISECONDS);
connection.setReadTimeout(HTTP_TIMEOUT_MILLISECONDS);

String authHeader = playerHeaders.get("Authorization");
String visitorId = playerHeaders.get("X-Goog-Visitor-Id");
connection.setRequestProperty("Authorization", authHeader);
connection.setRequestProperty("X-Goog-Visitor-Id", visitorId);
for (String key : REQUEST_HEADER_KEYS) {
String value = playerHeaders.get(key);
if (value != null) {
connection.setRequestProperty(key, value);
}
}

String innerTubeBody = String.format(PlayerRoutes.createInnertubeBody(clientType), videoId);
byte[] requestBody = innerTubeBody.getBytes(StandardCharsets.UTF_8);
Expand Down
Loading