Skip to content

Commit 67ba011

Browse files
committed
Load device type from conf
1 parent 9cfb27d commit 67ba011

8 files changed

Lines changed: 29 additions & 5 deletions

File tree

api/src/main/java/xyz/gianlu/librespot/api/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
public class Main {
1717

1818
public static void main(String[] args) throws IOException, GeneralSecurityException, MercuryClient.PubSubException, SpotifyIrc.IrcException, Session.SpotifyAuthenticationException {
19-
Session session = new Session.Builder(Session.DeviceType.Computer, new FileConfiguration(new File("conf.properties")))
19+
Session session = new Session.Builder(new FileConfiguration(new File("conf.properties")))
2020
.userPass(args[0], args[1])
2121
.create();
2222

conf.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# Configuration!
2-
deviceName=librespot-java
2+
deviceName=librespot-java
3+
deviceType=Computer

core/src/main/java/xyz/gianlu/librespot/AbsConfiguration.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package xyz.gianlu.librespot;
22

33
import org.jetbrains.annotations.Nullable;
4+
import xyz.gianlu.librespot.core.Session;
45
import xyz.gianlu.librespot.player.CacheManager;
56
import xyz.gianlu.librespot.player.Player;
67

@@ -11,4 +12,7 @@ public abstract class AbsConfiguration implements Player.PlayerConfiguration, Ca
1112

1213
@Nullable
1314
public abstract String deviceName();
15+
16+
@Nullable
17+
public abstract Session.DeviceType deviceType();
1418
}

core/src/main/java/xyz/gianlu/librespot/DefaultConfiguration.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package xyz.gianlu.librespot;
22

33
import org.jetbrains.annotations.NotNull;
4+
import xyz.gianlu.librespot.core.Session;
45
import xyz.gianlu.librespot.player.TrackHandler;
56

67
import java.io.File;
@@ -54,4 +55,10 @@ public boolean doCleanUp() {
5455
public String deviceName() {
5556
return "librespot-java";
5657
}
58+
59+
@NotNull
60+
@Override
61+
public Session.DeviceType deviceType() {
62+
return Session.DeviceType.Computer;
63+
}
5764
}

core/src/main/java/xyz/gianlu/librespot/FileConfiguration.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.jetbrains.annotations.NotNull;
44
import org.jetbrains.annotations.Nullable;
5+
import xyz.gianlu.librespot.core.Session;
56
import xyz.gianlu.librespot.player.TrackHandler;
67

78
import java.io.File;
@@ -72,4 +73,11 @@ public float normalisationPregain() {
7273
public @Nullable String deviceName() {
7374
return properties.getProperty("deviceName", null);
7475
}
76+
77+
@Override
78+
public @Nullable Session.DeviceType deviceType() {
79+
String val = properties.getProperty("deviceType", null);
80+
if (val == null) return null;
81+
return Session.DeviceType.valueOf(val);
82+
}
7583
}

core/src/main/java/xyz/gianlu/librespot/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
public class Main {
1515

1616
public static void main(String[] args) throws IOException, GeneralSecurityException, Session.SpotifyAuthenticationException, SpotifyIrc.IrcException, MercuryClient.PubSubException {
17-
Session session = new Session.Builder(Session.DeviceType.Computer, new FileConfiguration(new File("conf.properties")))
17+
Session session = new Session.Builder(new FileConfiguration(new File("conf.properties")))
1818
// .facebook()
1919
// .zeroconf()
2020
.userPass(args[0], args[1])

core/src/main/java/xyz/gianlu/librespot/core/Session.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,11 +404,15 @@ public Builder(@NotNull DeviceType deviceType, @NotNull String deviceName, @NotN
404404
this.inner = new Inner(deviceType, deviceName, configuration);
405405
}
406406

407-
public Builder(@NotNull DeviceType deviceType, @NotNull AbsConfiguration configuration) {
407+
public Builder(@NotNull AbsConfiguration configuration) {
408408
String deviceName = configuration.deviceName();
409409
if (deviceName == null || deviceName.isEmpty())
410410
throw new IllegalArgumentException("Device name required: " + deviceName);
411411

412+
DeviceType deviceType = configuration.deviceType();
413+
if (deviceType == null)
414+
throw new IllegalArgumentException("Device type required!");
415+
412416
this.inner = new Inner(deviceType, deviceName, configuration);
413417
}
414418

core/src/main/java/xyz/gianlu/librespot/crypto/Shannon.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* <p>
66
* Based on original reference implementation in C.
77
*
8-
* @author Felix Bruns <[email protected]>
8+
* @author Felix Bruns ([email protected])
99
*/
1010
@SuppressWarnings("ALL")
1111
public class Shannon {

0 commit comments

Comments
 (0)