* allow configuring osdb/sublight logins via Preferences and add another script that'll set these Preferences

This commit is contained in:
Reinhard Pointner 2012-07-23 06:58:36 +00:00
parent 6b6839579e
commit 380aeea966
2 changed files with 54 additions and 7 deletions

View File

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

View File

@ -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(':'))
}