mirror of
https://github.com/revanced/revanced-patches
synced 2025-01-14 21:57:34 +01:00
refactor(YouTube - Spoof streaming data): Add more debug logging
This commit is contained in:
parent
e30ca6839e
commit
a92c7b2fa4
@ -115,8 +115,7 @@ public class StreamingDataRequest {
|
|||||||
Objects.requireNonNull(playerHeaders);
|
Objects.requireNonNull(playerHeaders);
|
||||||
|
|
||||||
final long startTime = System.currentTimeMillis();
|
final long startTime = System.currentTimeMillis();
|
||||||
String clientTypeName = clientType.name();
|
Logger.printDebug(() -> "Fetching video streams for: " + videoId + " using client: " + clientType);
|
||||||
Logger.printDebug(() -> "Fetching video streams for: " + videoId + " using client: " + clientType.name());
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
HttpURLConnection connection = PlayerRoutes.getPlayerResponseConnectionFromRoute(GET_STREAMING_DATA, clientType);
|
HttpURLConnection connection = PlayerRoutes.getPlayerResponseConnectionFromRoute(GET_STREAMING_DATA, clientType);
|
||||||
@ -124,12 +123,16 @@ public class StreamingDataRequest {
|
|||||||
connection.setReadTimeout(HTTP_TIMEOUT_MILLISECONDS);
|
connection.setReadTimeout(HTTP_TIMEOUT_MILLISECONDS);
|
||||||
|
|
||||||
for (String key : REQUEST_HEADER_KEYS) {
|
for (String key : REQUEST_HEADER_KEYS) {
|
||||||
if (!clientType.canLogin && key.equals(AUTHORIZATION_HEADER)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
String value = playerHeaders.get(key);
|
String value = playerHeaders.get(key);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
|
if (key.equals(AUTHORIZATION_HEADER)) {
|
||||||
|
if (!clientType.canLogin) {
|
||||||
|
Logger.printDebug(() -> "Not including request header: " + key);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger.printDebug(() -> "Including request header: " + key);
|
||||||
connection.setRequestProperty(key, value);
|
connection.setRequestProperty(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,8 +145,10 @@ public class StreamingDataRequest {
|
|||||||
final int responseCode = connection.getResponseCode();
|
final int responseCode = connection.getResponseCode();
|
||||||
if (responseCode == 200) return connection;
|
if (responseCode == 200) return connection;
|
||||||
|
|
||||||
handleConnectionError(clientTypeName + " not available with response code: "
|
// This situation likely means the patches are outdated.
|
||||||
+ responseCode + " message: " + connection.getResponseMessage(),
|
// Use a toast message that suggests updating.
|
||||||
|
handleConnectionError("Playback error (App is outdated?) " + clientType + ": "
|
||||||
|
+ responseCode + " response: " + connection.getResponseMessage(),
|
||||||
null, showErrorToasts);
|
null, showErrorToasts);
|
||||||
} catch (SocketTimeoutException ex) {
|
} catch (SocketTimeoutException ex) {
|
||||||
handleConnectionError("Connection timeout", ex, showErrorToasts);
|
handleConnectionError("Connection timeout", ex, showErrorToasts);
|
||||||
@ -172,17 +177,19 @@ public class StreamingDataRequest {
|
|||||||
try {
|
try {
|
||||||
// gzip encoding doesn't response with content length (-1),
|
// gzip encoding doesn't response with content length (-1),
|
||||||
// but empty response body does.
|
// but empty response body does.
|
||||||
if (connection.getContentLength() != 0) {
|
if (connection.getContentLength() == 0) {
|
||||||
try (InputStream inputStream = new BufferedInputStream(connection.getInputStream())) {
|
Logger.printDebug(() -> "Received empty response for video: " + videoId);
|
||||||
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
|
} else {
|
||||||
byte[] buffer = new byte[2048];
|
try (InputStream inputStream = new BufferedInputStream(connection.getInputStream());
|
||||||
int bytesRead;
|
ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
|
||||||
while ((bytesRead = inputStream.read(buffer)) >= 0) {
|
|
||||||
baos.write(buffer, 0, bytesRead);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ByteBuffer.wrap(baos.toByteArray());
|
byte[] buffer = new byte[2048];
|
||||||
|
int bytesRead;
|
||||||
|
while ((bytesRead = inputStream.read(buffer)) >= 0) {
|
||||||
|
baos.write(buffer, 0, bytesRead);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ByteBuffer.wrap(baos.toByteArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user