Skip to content

Commit 68b3892

Browse files
committed
Main classes are ready
1 parent b7fa0c9 commit 68b3892

6 files changed

Lines changed: 31 additions & 17 deletions

File tree

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +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(new FileConfiguration(new File("conf.properties")))
20-
.userPass(args[0], args[1])
21-
.create();
19+
Session session = new Session.Builder(new FileConfiguration(new File("conf.properties"), args)).create();
2220

2321
ApiServer server = new ApiServer(24879);
2422
server.registerHandler(new PlayerHandler(session));

api/src/main/java/xyz/gianlu/librespot/api/server/ApiServer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public class ApiServer implements Receiver {
2424

2525
public ApiServer(int port) throws IOException {
2626
server = new WebsocketServer(port, this);
27+
28+
LOGGER.info(String.format("Server started on port %d!", port));
2729
}
2830

2931
private static boolean validateVersion(@NotNull JsonObject obj) {

conf.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ deviceName=librespot-java
33
## Device type (Computer, Tablet, Smartphone, Speaker, TV, AVR, STB, AudioDongle, Unknown)
44
deviceType=Computer
55
# Authentication
6-
## Strategy (userPass, zeroconf, blob, facebook)
6+
## Strategy (USER_PASS, ZEROCONF, BLOB, FACEBOOK)
77
auth.strategy=zeroconf
8-
## Spotify username (blob, userPass)
8+
## Spotify username (BLOB, USER_PASS)
99
auth.username=
10-
## Spotify password (userPass)
10+
## Spotify password (USER_PASS)
1111
auth.password=
12-
## Spotify authentication blob (blob)
12+
## Spotify authentication blob (BLOB)
1313
auth.blob=

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package xyz.gianlu.librespot;
22

3+
import org.apache.log4j.Logger;
34
import org.jetbrains.annotations.Contract;
45
import org.jetbrains.annotations.NotNull;
56
import org.jetbrains.annotations.Nullable;
7+
import xyz.gianlu.librespot.common.Utils;
68
import xyz.gianlu.librespot.core.Session;
79
import xyz.gianlu.librespot.player.TrackHandler;
810

@@ -15,12 +17,31 @@
1517
* @author Gianlu
1618
*/
1719
public final class FileConfiguration extends AbsConfiguration {
20+
private static final Logger LOGGER = Logger.getLogger(FileConfiguration.class);
1821
private final Properties properties;
1922
private final DefaultConfiguration defaults = new DefaultConfiguration();
2023

21-
public FileConfiguration(@NotNull File file) throws IOException {
24+
public FileConfiguration(@NotNull File file, @Nullable String[] override) throws IOException {
2225
this.properties = new Properties();
2326
this.properties.load(new FileReader(file));
27+
28+
if (override != null && override.length > 0) {
29+
for (String str : override) {
30+
if (str == null) continue;
31+
32+
if (str.contains("=") && str.startsWith("--")) {
33+
String[] split = Utils.split(str, '=');
34+
if (split.length != 2) {
35+
LOGGER.warn("Invalid command line argument: " + str);
36+
continue;
37+
}
38+
39+
properties.setProperty(split[0].substring(2), split[1]);
40+
} else {
41+
LOGGER.warn("Invalid command line argument: " + str);
42+
}
43+
}
44+
}
2445
}
2546

2647
private boolean getBoolean(@NotNull String key, boolean fallback) {

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@
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(new FileConfiguration(new File("conf.properties")))
18-
// .facebook()
19-
// .zeroconf()
20-
.userPass(args[0], args[1])
21-
// .blob("username", new byte[] {...})
22-
.create();
23-
24-
ConsoleClient.start(session);
17+
new Session.Builder(new FileConfiguration(new File("conf.properties"), args)).create();
2518
}
2619
}

mdnsjava

0 commit comments

Comments
 (0)