From 380aeea9667bd3b9139f3a52f1f6ee8883a74acc Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 23 Jul 2012 06:58:36 +0000 Subject: [PATCH] * allow configuring osdb/sublight logins via Preferences and add another script that'll set these Preferences --- .../net/sourceforge/filebot/WebServices.java | 18 +++++--- website/scripts/configure.login.groovy | 43 +++++++++++++++++++ 2 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 website/scripts/configure.login.groovy diff --git a/source/net/sourceforge/filebot/WebServices.java b/source/net/sourceforge/filebot/WebServices.java index b9cb4ac3..f56f191f 100644 --- a/source/net/sourceforge/filebot/WebServices.java +++ b/source/net/sourceforge/filebot/WebServices.java @@ -91,25 +91,29 @@ public final class WebServices { throw new UnsupportedOperationException(); } - /** * Initialize client settings from system properties */ static { - String[] osdbLogin = getLogin(System.getProperty("osdb.user")); + String[] osdbLogin = getLogin("osdb.user"); OpenSubtitles.setUser(osdbLogin[0], osdbLogin[1]); - String[] sublightClientLogin = getLogin(System.getProperty("sublight.client")); + String[] sublightClientLogin = getLogin("sublight.client"); Sublight.setClient(sublightClientLogin[0], sublightClientLogin[1]); - String[] sublightUserLogin = getLogin(System.getProperty("sublight.user")); + String[] sublightUserLogin = getLogin("sublight.user"); Sublight.setUser(sublightUserLogin[0], sublightUserLogin[1]); } - private static String[] getLogin(String login) { - if (login == null) - return new String[] { "", "" }; + private static String[] getLogin(String key) { + // try system property first + String login = System.getProperty(key); + + // try settings second + if (login == null) { + login = Settings.forPackage(WebServices.class).get(key, ":"); + } return login.split(":", 2); } diff --git a/website/scripts/configure.login.groovy b/website/scripts/configure.login.groovy new file mode 100644 index 00000000..e2285934 --- /dev/null +++ b/website/scripts/configure.login.groovy @@ -0,0 +1,43 @@ +// OpenSubtitles +console.print('Enter OpenSubtitles username: ') +def osdbUser = console.readLine() +console.print('Enter OpenSubtitles password: ') +def osdbPwd = console.readLine() + +// Sublight +console.print('Enter Sublight username: ') +def sublightUser = console.readLine() +console.print('Enter Sublight password: ') +def sublightPwd = console.readLine() + +// I've requested a new API key for FileBot multiple times and have yet to recieve a reply... +// @from http://sublightcmd.codeplex.com/SourceControl/changeset/view/9437#8043 +def sublightClientId = 'SublightCmd' +def sublightApiKey = '12c72276-b95f-4144-bb2a-879775c71437' + + +setLogin('osdb.user', osdbUser, osdbPwd) +setLogin('sublight.client', sublightClientId, sublightApiKey) +setLogin('sublight.user', sublightUser, sublightPwd) + + +/* --------------------------------------------------------------------- */ + +import net.sourceforge.filebot.* + +console.print('Testing OpenSubtitles... ') +WebServices.OpenSubtitles.setUser(osdbUser, osdbPwd) +WebServices.OpenSubtitles.login() +console.println('OK') + +console.print('Testing Sublight... ') +WebServices.Sublight.setClient(sublightClientId, sublightApiKey) +WebServices.Sublight.setUser(osdbUser, osdbPwd) +WebServices.Sublight.getSubtitleList(null, 'Avatar', 2009, 'English') +console.println('OK') + +/* --------------------------------------------------------------------- */ + +def setLogin(key, user, pwd) { + Settings.forPackage(WebServices.class).put(key, [user, pwd].join(':')) +}