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 androidx.annotation.Nullable;
|
||||
import app.revanced.integrations.shared.Logger;
|
||||
import app.revanced.integrations.shared.Utils;
|
||||
import app.revanced.integrations.youtube.requests.Requester;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.downloader.Downloader;
|
||||
import org.schabi.newpipe.extractor.downloader.Request;
|
||||
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.linkHandler.YoutubeStreamLinkHandlerFactory;
|
||||
import org.schabi.newpipe.extractor.stream.AudioStream;
|
||||
|
@ -19,27 +17,22 @@ import org.schabi.newpipe.extractor.stream.VideoStream;
|
|||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class Test {
|
||||
private static Map<Integer, String> formats = new HashMap<>();
|
||||
private static Map<Integer, String> formats;
|
||||
|
||||
|
||||
@Nullable
|
||||
public static HttpURLConnection makeRequest(final Request request) {
|
||||
try {
|
||||
Utils.verifyOffMainThread();
|
||||
//Objects.requireNonNull(request.dataToSend());
|
||||
|
||||
Logger.printInfo(() -> "Hooked request");
|
||||
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(request.url()).openConnection();
|
||||
connection.setRequestMethod(request.httpMethod());
|
||||
|
||||
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";
|
||||
connection.setRequestProperty("User-Agent", agentString);
|
||||
|
@ -56,17 +49,21 @@ public class Test {
|
|||
connection.addRequestProperty(headerName, headerValueList.get(0));
|
||||
}
|
||||
}
|
||||
Logger.printInfo(() -> "Hooked headers");
|
||||
|
||||
final byte[] innerTubeBody = request.dataToSend();
|
||||
if (innerTubeBody != null) {
|
||||
connection.getOutputStream().write(innerTubeBody, 0, innerTubeBody.length);
|
||||
}
|
||||
Logger.printInfo(() -> "Hooked body");
|
||||
|
||||
final int responseCode = connection.getResponseCode();
|
||||
if (responseCode == 200) return connection;
|
||||
else if (responseCode == 429) {
|
||||
Logger.printInfo(() -> "Hooked reCaptcha Challenge requested");
|
||||
throw new Exception("reCaptcha Challenge requested");
|
||||
} else {
|
||||
Logger.printInfo(() -> "Hooked Error making request: " + responseCode);
|
||||
throw new Exception("Error making request: " + responseCode);
|
||||
}
|
||||
|
||||
|
@ -80,7 +77,9 @@ public class Test {
|
|||
public static String hook(String s) {
|
||||
|
||||
if (!s.contains("googlevideo")) return s;
|
||||
if (formats.isEmpty()) {
|
||||
if (formats == null) {
|
||||
var f = new HashMap<Integer, String>();
|
||||
Logger.printInfo(() -> "Hooked start");
|
||||
try {
|
||||
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
|
||||
StrictMode.setThreadPolicy(policy);
|
||||
|
@ -89,33 +88,54 @@ public class Test {
|
|||
@Override
|
||||
public Response execute(Request request) throws IOException {
|
||||
var c = makeRequest(request);
|
||||
var r = new Response(
|
||||
c.getResponseCode(),
|
||||
c.getResponseMessage(),
|
||||
c.getHeaderFields(),
|
||||
Requester.parseString(c),
|
||||
c.getURL().toString()
|
||||
);
|
||||
Logger.printInfo(() -> "Hooked got response");
|
||||
var body = false;
|
||||
try{
|
||||
body = c.getInputStream() != null;
|
||||
} catch (Exception e) {
|
||||
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();
|
||||
return r;
|
||||
}
|
||||
});
|
||||
var extractor = new YoutubeService(1).getStreamExtractor(YoutubeStreamLinkHandlerFactory.getInstance().fromId("piKJAUwCYTo"));
|
||||
extractor.fetchPage();
|
||||
|
||||
Logger.printInfo(() -> "Hooked got extractor");
|
||||
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()) {
|
||||
formats.put(videoOnlyStream.getItag(), videoOnlyStream.getContent());
|
||||
f.put(videoOnlyStream.getItag(), videoOnlyStream.getContent());
|
||||
}
|
||||
|
||||
Logger.printInfo(() -> "Hooked got video only");
|
||||
|
||||
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");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue