Code: Select all
import android.os.Build;
import android.util.ArrayMap;
import android.util.Log;
import androidx.annotation.RequiresApi;
import java.io.IOException;
import java.lang.reflect.Array;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.PasswordAuthentication;
import java.net.URL;
import java.net.URLConnection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import de.timroes.axmlrpc.XMLRPCCallback;
import de.timroes.axmlrpc.XMLRPCClient;
import de.timroes.axmlrpc.XMLRPCException;
import de.timroes.axmlrpc.XMLRPCServerException;
public class OpensubsRequest {
static String username;
static String password;
static String language;
static String useragent;
static String search;
static Array xx5;
@RequiresApi(api = Build.VERSION_CODES.O)
public static void makerequest(){
Authenticator.setDefault (new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication (username, password.toCharArray());
}
});
Thread thread = new Thread() {
@Override
public void run() {
try {
Pattern pattern = Pattern.compile("token=.*status");
XMLRPCClient client = new XMLRPCClient(new URL("https://api.opensubtitles.org/xml-rpc"));
Object ed = client.call("LogIn",username,password,"en",useragent);
String Token = ed.toString();
Matcher matcher = pattern.matcher(Token);
if (matcher.find()) {
Token = matcher.group().replace("token=","").replace(", status","").trim();
}
Object test = client.call("SearchSubtitles",Token,"South Park");
Log.d("diditwork", String.valueOf(ed));
Log.d("diditwork", String.valueOf(test));
} catch (Exception ex) {
// Any other exception
Log.d("diditworkexception", String.valueOf(ex));
}
}
};
thread.start();
}
}