Forum rules
Under no circumstances is spamming or advertising of any kind allowed. Do not post any abusive, obscene, vulgar, slanderous, hateful, threatening, sexually-orientated or any other material that may violate others security. Profanity or any kind of insolent behavior to other members (regardless of rank) will not be tolerated. Remember, what you don’t find offensive can be offensive to other members. Please treat each other with the kind of reverence you’d expect from other members.
Failure to comply with any of the above will result in users being banned without notice. If any further details are needed, contact: “The team” using the link at the bottom of the forum page. Thank you.
shivitoapps
Posts: 8
Joined: Sat May 09, 2020 7:09 pm

Android Studio Class Search OpenSubtitles

Sat May 09, 2020 7:20 pm

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!
Last edited by shivitoapps on Tue May 12, 2020 5:51 am, edited 1 time in total.

shivitoapps
Posts: 8
Joined: Sat May 09, 2020 7:09 pm

Re: Android Studio Class Search OpenSubtitles

Tue May 12, 2020 3:57 am

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

shivitoapps
Posts: 8
Joined: Sat May 09, 2020 7:09 pm

Re: Android Studio Class Search OpenSubtitles

Tue May 12, 2020 3:59 am

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

User avatar
oss
Site Admin
Posts: 5879
Joined: Sat Feb 25, 2006 11:26 pm
Contact: Website

Re: Android Studio Class Search OpenSubtitles

Tue May 12, 2020 10:29 am

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()

shivitoapps
Posts: 8
Joined: Sat May 09, 2020 7:09 pm

Re: Android Studio Class Search OpenSubtitles

Tue May 12, 2020 7:59 pm

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.

shivitoapps
Posts: 8
Joined: Sat May 09, 2020 7:09 pm

Re: Android Studio Class Search OpenSubtitles

Wed May 13, 2020 4:24 am

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?

User avatar
oss
Site Admin
Posts: 5879
Joined: Sat Feb 25, 2006 11:26 pm
Contact: Website

Re: Android Studio Class Search OpenSubtitles

Wed May 13, 2020 6:27 am

Hi

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

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

shivitoapps
Posts: 8
Joined: Sat May 09, 2020 7:09 pm

Re: Android Studio Class Search OpenSubtitles

Wed May 13, 2020 6:20 pm

Okay. I'll register XD

shivitoapps
Posts: 8
Joined: Sat May 09, 2020 7:09 pm

Re: Android Studio Class Search OpenSubtitles

Thu May 14, 2020 7:35 pm

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!

shivitoapps
Posts: 8
Joined: Sat May 09, 2020 7:09 pm

Re: Android Studio Class Search OpenSubtitles

Thu May 21, 2020 4:38 am

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)); } } };

User avatar
oss
Site Admin
Posts: 5879
Joined: Sat Feb 25, 2006 11:26 pm
Contact: Website

Re: Android Studio Class Search OpenSubtitles

Thu May 21, 2020 6:55 am

good job :)

Akinloye oluwadare
Posts: 1
Joined: Sat May 30, 2020 3:09 am

Re: Android Studio Class Search OpenSubtitles

Sat May 30, 2020 4:24 am

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.


Return to “Programs using OS”

Who is online

Users browsing this forum: No registered users and 23 guests