Page 1 of 1

Android Studio Class Search OpenSubtitles

Posted: Sat May 09, 2020 7:20 pm
by shivitoapps
any help would be greatly appreciated. I have created a class and am trying to send/receive data from opensubtitles. However I'm a noob and need some guidance. The below code is my attempt to get a boolean of true witch i think would mean i have sucessfully athenticated with OpenSubtitles api. Up to this point it always returns false.

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(); } }
thanks!

Re: Android Studio Class Search OpenSubtitles

Posted: Tue May 12, 2020 3:57 am
by shivitoapps
I have made progress. However now when trying to do a search request I'm getting "status=408 Invalid parameters"

Code: Select all

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,"en", "", "", "", "blade", "", "", ""); 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(); } }

Re: Android Studio Class Search OpenSubtitles

Posted: Tue May 12, 2020 3:59 am
by shivitoapps
I am making some progress. However now I'm getting "status=408 Invalid parameters"
also i'm using this git: https://github.com/gturri/aXMLRPC

Code: Select all

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,"en", "", "", "", "blade", "", "", ""); 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(); } }

Re: Android Studio Class Search OpenSubtitles

Posted: Tue May 12, 2020 10:29 am
by oss
I believe you will find out what is problem. Be careful it is struct, maybe this will help you for examples:

https://trac.opensubtitles.org/projects ... mlRpcIntro

check SearchSubtitles()

Re: Android Studio Class Search OpenSubtitles

Posted: Tue May 12, 2020 7:59 pm
by shivitoapps
What is the string parameter suppose to look like? I have been trying for days now :(
maybe I should find a different git hub library. Do you have any suggestions? I have tried https://github.com/wtekiela/opensub4j but the gradle has some issues with 7.0. I'm currently using https://github.com/gturri/aXMLRPC but so far all i can do is LogIn.

Re: Android Studio Class Search OpenSubtitles

Posted: Wed May 13, 2020 4:24 am
by shivitoapps
Okay, Progress of a sort. I'm now getting this reply when i use SearchSubtitles method

Code: Select all

{seconds=0.296, data=[Ljava.lang.Object;@2b6b285, message=Only first 5 results returned, register own UserAgent, status=200 OK}
One problem I do not see the 5 results. are they in the Object maybe?

Re: Android Studio Class Search OpenSubtitles

Posted: Wed May 13, 2020 6:27 am
by oss
Hi

please read message:
only first 5 results returned, register own UserAgent

You need to register and use OWN UserAgent, not TESTUSERAGENT.

Re: Android Studio Class Search OpenSubtitles

Posted: Wed May 13, 2020 6:20 pm
by shivitoapps
Okay. I'll register XD

Re: Android Studio Class Search OpenSubtitles

Posted: Thu May 14, 2020 7:35 pm
by shivitoapps
Okay I registered and am now using my own useragent.
I'm still having some issue. Please see below.

I still can not get the list of returned items.
my code:

Code: Select all

Object test = client.callAsync(testcallback,"SearchSubtitles",params);
OpenSubtitles api reply:

Code: Select all

{seconds=0.248, data=[Ljava.lang.Object;@2554a79, status=200 OK}
I see it says (data=[Ljava.lang.Object;@2554a79) however I cant figure out how to read that object.
any help would be appreciated. Thanks!

Re: Android Studio Class Search OpenSubtitles

Posted: Thu May 21, 2020 4:38 am
by shivitoapps
Resolved. I just needed to properly handle the reply. Here is the code that works.

Code: Select all

Thread thread = new Thread() { @Override public void run() { try { // Setup XMLRPC Client XMLRPCClient client = new XMLRPCClient(new URL("https://api.opensubtitles.org/xml-rpc")); HashMap ed = (HashMap<Object,String>) client.call("LogIn",username,password,"en",useragent); // separate my Token from the reply String Token = (String) ed.get("token"); // setup Parameters for next call to search for subs Map<String, String> videoProperties = new HashMap<>(); videoProperties.put("sublanguageid", "en"); videoProperties.put("query", "blade 2"); Object[] videoParams = {videoProperties}; Object[] params = {Token, videoParams}; // Make next call include method and Parameters java.util.HashMap test2 = (HashMap<String,Array>) client.call("SearchSubtitles",params); // select data key from test2 Object[] d = (Object[]) test2.get("data"); // change d Object to List List ee = Arrays.asList(d); // Grab Map from list Map xx = (Map) ee.get(1); Log.d("diditworkstring", String.valueOf(xx.get("ZipDownloadLink"))); } catch (Exception ex) { // Any other exception Log.d("diditworkexception", String.valueOf(ex)); } } };

Re: Android Studio Class Search OpenSubtitles

Posted: Thu May 21, 2020 6:55 am
by oss
good job :)

Re: Android Studio Class Search OpenSubtitles

Posted: Sat May 30, 2020 4:24 am
by Akinloye oluwadare
Please, how can I make use of this subtitles? am watching an India movie and I need it to be subtitle. Pls kindly help me.

Thank you.

Re: Android Studio Class Search OpenSubtitles

Posted: Sun May 31, 2020 5:41 am
by oss