mirror of
https://github.com/revanced/revanced-integrations.git
synced 2024-06-02 11:26:18 +02:00
add debug logs
This commit is contained in:
parent
ee929735c4
commit
b3a9980d86
|
@ -4,13 +4,11 @@ import android.net.Uri;
|
||||||
import android.os.StrictMode;
|
import android.os.StrictMode;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import app.revanced.integrations.shared.Logger;
|
import app.revanced.integrations.shared.Logger;
|
||||||
import app.revanced.integrations.shared.Utils;
|
|
||||||
import app.revanced.integrations.youtube.requests.Requester;
|
import app.revanced.integrations.youtube.requests.Requester;
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
import org.schabi.newpipe.extractor.NewPipe;
|
||||||
import org.schabi.newpipe.extractor.downloader.Downloader;
|
import org.schabi.newpipe.extractor.downloader.Downloader;
|
||||||
import org.schabi.newpipe.extractor.downloader.Request;
|
import org.schabi.newpipe.extractor.downloader.Request;
|
||||||
import org.schabi.newpipe.extractor.downloader.Response;
|
import org.schabi.newpipe.extractor.downloader.Response;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
|
||||||
import org.schabi.newpipe.extractor.services.youtube.YoutubeService;
|
import org.schabi.newpipe.extractor.services.youtube.YoutubeService;
|
||||||
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeStreamLinkHandlerFactory;
|
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeStreamLinkHandlerFactory;
|
||||||
import org.schabi.newpipe.extractor.stream.AudioStream;
|
import org.schabi.newpipe.extractor.stream.AudioStream;
|
||||||
|
@ -19,27 +17,22 @@ import org.schabi.newpipe.extractor.stream.VideoStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Comparator;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class Test {
|
public class Test {
|
||||||
private static Map<Integer, String> formats = new HashMap<>();
|
private static Map<Integer, String> formats;
|
||||||
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static HttpURLConnection makeRequest(final Request request) {
|
public static HttpURLConnection makeRequest(final Request request) {
|
||||||
try {
|
try {
|
||||||
Utils.verifyOffMainThread();
|
Logger.printInfo(() -> "Hooked request");
|
||||||
//Objects.requireNonNull(request.dataToSend());
|
|
||||||
|
|
||||||
|
|
||||||
HttpURLConnection connection = (HttpURLConnection) new URL(request.url()).openConnection();
|
HttpURLConnection connection = (HttpURLConnection) new URL(request.url()).openConnection();
|
||||||
connection.setRequestMethod(request.httpMethod());
|
connection.setRequestMethod(request.httpMethod());
|
||||||
|
|
||||||
connection.setUseCaches(false);
|
connection.setUseCaches(false);
|
||||||
connection.setDoOutput(true);
|
connection.setDoOutput(Objects.equals(request.httpMethod(), "POST"));
|
||||||
|
|
||||||
String agentString = "Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0";
|
String agentString = "Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0";
|
||||||
connection.setRequestProperty("User-Agent", agentString);
|
connection.setRequestProperty("User-Agent", agentString);
|
||||||
|
@ -56,17 +49,21 @@ public class Test {
|
||||||
connection.addRequestProperty(headerName, headerValueList.get(0));
|
connection.addRequestProperty(headerName, headerValueList.get(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Logger.printInfo(() -> "Hooked headers");
|
||||||
|
|
||||||
final byte[] innerTubeBody = request.dataToSend();
|
final byte[] innerTubeBody = request.dataToSend();
|
||||||
if (innerTubeBody != null) {
|
if (innerTubeBody != null) {
|
||||||
connection.getOutputStream().write(innerTubeBody, 0, innerTubeBody.length);
|
connection.getOutputStream().write(innerTubeBody, 0, innerTubeBody.length);
|
||||||
}
|
}
|
||||||
|
Logger.printInfo(() -> "Hooked body");
|
||||||
|
|
||||||
final int responseCode = connection.getResponseCode();
|
final int responseCode = connection.getResponseCode();
|
||||||
if (responseCode == 200) return connection;
|
if (responseCode == 200) return connection;
|
||||||
else if (responseCode == 429) {
|
else if (responseCode == 429) {
|
||||||
|
Logger.printInfo(() -> "Hooked reCaptcha Challenge requested");
|
||||||
throw new Exception("reCaptcha Challenge requested");
|
throw new Exception("reCaptcha Challenge requested");
|
||||||
} else {
|
} else {
|
||||||
|
Logger.printInfo(() -> "Hooked Error making request: " + responseCode);
|
||||||
throw new Exception("Error making request: " + responseCode);
|
throw new Exception("Error making request: " + responseCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +77,9 @@ public class Test {
|
||||||
public static String hook(String s) {
|
public static String hook(String s) {
|
||||||
|
|
||||||
if (!s.contains("googlevideo")) return s;
|
if (!s.contains("googlevideo")) return s;
|
||||||
if (formats.isEmpty()) {
|
if (formats == null) {
|
||||||
|
var f = new HashMap<Integer, String>();
|
||||||
|
Logger.printInfo(() -> "Hooked start");
|
||||||
try {
|
try {
|
||||||
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
|
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
|
||||||
StrictMode.setThreadPolicy(policy);
|
StrictMode.setThreadPolicy(policy);
|
||||||
|
@ -89,33 +88,54 @@ public class Test {
|
||||||
@Override
|
@Override
|
||||||
public Response execute(Request request) throws IOException {
|
public Response execute(Request request) throws IOException {
|
||||||
var c = makeRequest(request);
|
var c = makeRequest(request);
|
||||||
var r = new Response(
|
Logger.printInfo(() -> "Hooked got response");
|
||||||
c.getResponseCode(),
|
var body = false;
|
||||||
c.getResponseMessage(),
|
try{
|
||||||
c.getHeaderFields(),
|
body = c.getInputStream() != null;
|
||||||
Requester.parseString(c),
|
} catch (Exception e) {
|
||||||
c.getURL().toString()
|
Logger.printInfo(() -> "Hooked Error making request: " + e.getMessage(), e);
|
||||||
);
|
}
|
||||||
|
Response r = null;
|
||||||
|
try {
|
||||||
|
r = new Response(
|
||||||
|
c.getResponseCode(),
|
||||||
|
c.getResponseMessage(),
|
||||||
|
c.getHeaderFields(),
|
||||||
|
body ? Requester.parseString(c) : null,
|
||||||
|
c.getURL().toString()
|
||||||
|
);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Logger.printInfo(() -> "Hooked Error making request: " + e.getMessage(), e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
c.disconnect();
|
c.disconnect();
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var extractor = new YoutubeService(1).getStreamExtractor(YoutubeStreamLinkHandlerFactory.getInstance().fromId("piKJAUwCYTo"));
|
var extractor = new YoutubeService(1).getStreamExtractor(YoutubeStreamLinkHandlerFactory.getInstance().fromId("piKJAUwCYTo"));
|
||||||
extractor.fetchPage();
|
extractor.fetchPage();
|
||||||
|
Logger.printInfo(() -> "Hooked got extractor");
|
||||||
for (AudioStream audioStream : extractor.getAudioStreams()) {
|
for (AudioStream audioStream : extractor.getAudioStreams()) {
|
||||||
formats.put(audioStream.getItag(), audioStream.getContent());
|
f.put(audioStream.getItag(), audioStream.getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger.printInfo(() -> "Hooked got audio");
|
||||||
|
|
||||||
for (VideoStream videoOnlyStream : extractor.getVideoOnlyStreams()) {
|
for (VideoStream videoOnlyStream : extractor.getVideoOnlyStreams()) {
|
||||||
formats.put(videoOnlyStream.getItag(), videoOnlyStream.getContent());
|
f.put(videoOnlyStream.getItag(), videoOnlyStream.getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger.printInfo(() -> "Hooked got video only");
|
||||||
|
|
||||||
for (VideoStream videoStream : extractor.getVideoStreams()) {
|
for (VideoStream videoStream : extractor.getVideoStreams()) {
|
||||||
formats.put(videoStream.getItag(), videoStream.getContent());
|
f.put(videoStream.getItag(), videoStream.getContent());
|
||||||
}
|
}
|
||||||
} catch (ExtractionException | IOException ignored) {
|
|
||||||
Logger.printInfo(() -> "Hooked Error making request: " + ignored.getMessage(), ignored);
|
formats = f;
|
||||||
|
Logger.printInfo(() -> "Hooked got format");
|
||||||
|
|
||||||
|
} catch (Exception i) {
|
||||||
|
Logger.printInfo(() -> "Hooked Error making request: " + i.getMessage(), i);
|
||||||
}
|
}
|
||||||
//formats = StoryboardRendererRequester.getFormats("piKJAUwCYTo");
|
//formats = StoryboardRendererRequester.getFormats("piKJAUwCYTo");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user