-
Notifications
You must be signed in to change notification settings - Fork 138
/
configure.groovy
executable file
·62 lines (46 loc) · 1.67 KB
/
configure.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env -S filebot -script
osdbUser = any{ osdbUser }{ printf('Enter OpenSubtitles username: '); console.readLine() }
osdbPwd = any{ osdbPwd }{ printf('Enter OpenSubtitles password: '); console.readLine() }
/* --------------------------------------------------------------------- */
// user preferences are per-user and not per-device
log.fine "Store user preferences to [${UserData.root()}]"
// set login details
if (osdbUser && osdbPwd) {
log.config('Set OpenSubtitles login details')
try {
WebServices.setLogin(WebServices.OpenSubtitles, osdbUser, osdbPwd)
printAccountInformation()
} catch(e) {
if (e.message =~ /401 Unauthorized/) {
if (WebServices.OpenSubtitles.class =~ /XmlRpc/) {
log.warning 'Your login details are incorrect. Please go to www.opensubtitles.org (XML-RPC API; not www.opensubtitles.com) to check your login details and reset your password if necessary/'
} else {
log.warning 'Your login details are incorrect. Please go to www.opensubtitles.com (REST API; not www.opensubtitles.org) to check your login details and reset your password if necessary.'
}
}
die e.message
}
}
// clear login details
if (!osdbUser && !osdbPwd) {
log.config('Reset OpenSubtitles login details')
WebServices.setLogin(WebServices.OpenSubtitles, null, null)
}
/**
* Log in and retrieve account details.
*/
void printAccountInformation() {
printf('Checking... ')
def info = WebServices.OpenSubtitles.getServerInfo()
printf('OK\n\n')
if (WebServices.OpenSubtitles.class =~ /XmlRpc/) {
info.download_limits.each{ k, v ->
log.config("$k: $v")
}
} else {
info.each{ k, v ->
log.config("$k: $v")
}
}
WebServices.OpenSubtitles.logout()
}