2021-07-24 12:27:45 +02:00
|
|
|
package com.cappielloantonio.play.subsonic;
|
|
|
|
|
|
|
|
|
|
import com.cappielloantonio.play.subsonic.utils.StringUtil;
|
|
|
|
|
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
public class SubsonicPreferences {
|
|
|
|
|
private String serverUrl;
|
|
|
|
|
private String username;
|
2022-01-11 12:49:40 +01:00
|
|
|
private String password;
|
2021-12-23 17:10:03 +01:00
|
|
|
private String clientName = "Play";
|
2021-07-28 09:20:22 +02:00
|
|
|
private SubsonicAuthentication authentication;
|
2021-07-24 12:27:45 +02:00
|
|
|
|
|
|
|
|
public String getServerUrl() {
|
|
|
|
|
return serverUrl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getUsername() {
|
|
|
|
|
return username;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-11 12:49:40 +01:00
|
|
|
public String getPassword() {
|
|
|
|
|
return password;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-24 12:27:45 +02:00
|
|
|
public String getClientName() {
|
|
|
|
|
return clientName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SubsonicAuthentication getAuthentication() {
|
|
|
|
|
return authentication;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-28 18:28:47 +02:00
|
|
|
public void setServerUrl(String serverUrl) {
|
|
|
|
|
this.serverUrl = serverUrl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setUsername(String username) {
|
|
|
|
|
this.username = username;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-11 12:49:40 +01:00
|
|
|
public void setPassword(String password) {
|
|
|
|
|
this.password = password;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-28 18:28:47 +02:00
|
|
|
public void setClientName(String clientName) {
|
|
|
|
|
this.clientName = clientName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setAuthentication(String password, String token, String salt) {
|
2021-08-01 11:48:18 +02:00
|
|
|
if (password != null) this.authentication = new SubsonicAuthentication(password);
|
|
|
|
|
if (token != null && salt != null)
|
|
|
|
|
this.authentication = new SubsonicAuthentication(token, salt);
|
2021-07-24 12:27:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class SubsonicAuthentication {
|
|
|
|
|
private String salt;
|
|
|
|
|
private String token;
|
|
|
|
|
|
|
|
|
|
public SubsonicAuthentication(String password) {
|
|
|
|
|
update(password);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-28 13:55:05 +02:00
|
|
|
public SubsonicAuthentication(String token, String salt) {
|
|
|
|
|
this.token = token;
|
|
|
|
|
this.salt = salt;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-24 12:27:45 +02:00
|
|
|
public String getSalt() {
|
|
|
|
|
return salt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getToken() {
|
|
|
|
|
return token;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void update(String password) {
|
|
|
|
|
this.salt = UUID.randomUUID().toString();
|
|
|
|
|
this.token = StringUtil.tokenize(password + salt);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|