Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,26 @@
<version>${project.version}</version>
</dependency>

<!-- Logging -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j-core.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j-slf4j-impl.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<version>${lmax-disruptor.version}</version>
<scope>runtime</scope>
</dependency>

<!-- HTTP server -->
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-core</artifactId>
Expand Down
7 changes: 7 additions & 0 deletions lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,12 @@
<artifactId>commons-net</artifactId>
<version>3.8.0</version>
</dependency>

<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
</dependency>
</dependencies>
</project>
28 changes: 14 additions & 14 deletions lib/src/main/java/xyz/gianlu/librespot/ZeroconfServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import com.google.gson.JsonObject;
import com.spotify.connectstate.Connect;
import okhttp3.HttpUrl;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import xyz.gianlu.librespot.common.NameThreadFactory;
import xyz.gianlu.librespot.common.Utils;
import xyz.gianlu.librespot.core.Session;
Expand Down Expand Up @@ -40,7 +40,7 @@
public class ZeroconfServer implements Closeable {
private final static int MAX_PORT = 65536;
private final static int MIN_PORT = 1024;
private static final Logger LOGGER = LogManager.getLogger(ZeroconfServer.class);
private static final Logger LOGGER = LoggerFactory.getLogger(ZeroconfServer.class);
private static final byte[] EOL = new byte[]{'\r', '\n'};
private static final JsonObject DEFAULT_GET_INFO_FIELDS = new JsonObject();
private static final JsonObject DEFAULT_SUCCESSFUL_ADD_USER = new JsonObject();
Expand Down Expand Up @@ -247,19 +247,19 @@ private void handleGetInfo(OutputStream out, String httpVersion) throws IOExcept
private void handleAddUser(OutputStream out, Map<String, String> params, String httpVersion) throws GeneralSecurityException, IOException {
String username = params.get("userName");
if (username == null || username.isEmpty()) {
LOGGER.fatal("Missing userName!");
LOGGER.error("Missing userName!");
return;
}

String blobStr = params.get("blob");
if (blobStr == null || blobStr.isEmpty()) {
LOGGER.fatal("Missing blob!");
LOGGER.error("Missing blob!");
return;
}

String clientKeyStr = params.get("clientKey");
if (clientKeyStr == null || clientKeyStr.isEmpty()) {
LOGGER.fatal("Missing clientKey!");
LOGGER.error("Missing clientKey!");
return;
}

Expand Down Expand Up @@ -300,7 +300,7 @@ private void handleAddUser(OutputStream out, Map<String, String> params, String
byte[] mac = hmac.doFinal();

if (!Arrays.equals(mac, checksum)) {
LOGGER.fatal("Mac and checksum don't match!");
LOGGER.error("Mac and checksum don't match!");

out.write(httpVersion.getBytes());
out.write(" 400 Bad Request".getBytes()); // I don't think this is the Spotify way
Expand Down Expand Up @@ -355,7 +355,7 @@ private void handleAddUser(OutputStream out, Map<String, String> params, String

sessionListeners.forEach(l -> l.sessionChanged(session));
} catch (Session.SpotifyAuthenticationException | MercuryClient.MercuryException | IOException | GeneralSecurityException ex) {
LOGGER.fatal("Couldn't establish a new session.", ex);
LOGGER.error("Couldn't establish a new session.", ex);

synchronized (connectionLock) {
connectingUsername = null;
Expand Down Expand Up @@ -465,11 +465,11 @@ public void run() {
handle(socket);
socket.close();
} catch (IOException ex) {
LOGGER.fatal("Failed handling request!", ex);
LOGGER.error("Failed handling request!", ex);
}
});
} catch (IOException ex) {
if (!shouldStop) LOGGER.fatal("Failed handling connection!", ex);
if (!shouldStop) LOGGER.error("Failed handling connection!", ex);
}
}
}
Expand All @@ -481,13 +481,13 @@ private void handleRequest(@NotNull OutputStream out, @NotNull String httpVersio
try {
handleAddUser(out, params, httpVersion);
} catch (GeneralSecurityException | IOException ex) {
LOGGER.fatal("Failed handling addUser!", ex);
LOGGER.error("Failed handling addUser!", ex);
}
} else if (Objects.equals(action, "getInfo")) {
try {
handleGetInfo(out, httpVersion);
} catch (IOException ex) {
LOGGER.fatal("Failed handling getInfo!", ex);
LOGGER.error("Failed handling getInfo!", ex);
}
} else {
LOGGER.warn("Unknown action: " + action);
Expand Down Expand Up @@ -522,13 +522,13 @@ private void handle(@NotNull Socket socket) throws IOException {
if (Objects.equals(method, "POST")) {
String contentType = headers.get("Content-Type");
if (!Objects.equals(contentType, "application/x-www-form-urlencoded")) {
LOGGER.fatal("Bad Content-Type: " + contentType);
LOGGER.error("Bad Content-Type: " + contentType);
return;
}

String contentLengthStr = headers.get("Content-Length");
if (contentLengthStr == null) {
LOGGER.fatal("Missing Content-Length header!");
LOGGER.error("Missing Content-Length header!");
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package xyz.gianlu.librespot.audio;

import com.google.protobuf.ByteString;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import xyz.gianlu.librespot.common.Utils;
import xyz.gianlu.librespot.core.PacketsReceiver;
import xyz.gianlu.librespot.core.Session;
Expand All @@ -24,7 +24,7 @@
*/
public final class AudioKeyManager implements PacketsReceiver {
private static final byte[] ZERO_SHORT = new byte[]{0, 0};
private static final Logger LOGGER = LogManager.getLogger(AudioKeyManager.class);
private static final Logger LOGGER = LoggerFactory.getLogger(AudioKeyManager.class);
private static final long AUDIO_KEY_REQUEST_TIMEOUT = 2000;
private final AtomicInteger seqHolder = new AtomicInteger(0);
private final Map<Integer, Callback> callbacks = Collections.synchronizedMap(new HashMap<>());
Expand Down Expand Up @@ -109,7 +109,7 @@ public void key(byte[] key) {

@Override
public void error(short code) {
LOGGER.fatal("Audio key error, code: {}", code);
LOGGER.error("Audio key error, code: {}", code);

synchronized (reference) {
reference.set(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package xyz.gianlu.librespot.audio;


import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.DataInputStream;
import java.io.IOException;
Expand All @@ -15,7 +15,7 @@
* @author Gianlu
*/
public class NormalizationData {
private static final Logger LOGGER = LogManager.getLogger(NormalizationData.class);
private static final Logger LOGGER = LoggerFactory.getLogger(NormalizationData.class);
public final float track_gain_db;
public final float track_peak;
public final float album_gain_db;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import okhttp3.HttpUrl;
import okhttp3.Response;
import okhttp3.ResponseBody;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import xyz.gianlu.librespot.audio.cdn.CdnFeedHelper;
import xyz.gianlu.librespot.audio.cdn.CdnManager;
import xyz.gianlu.librespot.audio.format.AudioQualityPicker;
Expand All @@ -30,7 +30,7 @@
* @author Gianlu
*/
public final class PlayableContentFeeder {
private static final Logger LOGGER = LogManager.getLogger(PlayableContentFeeder.class);
private static final Logger LOGGER = LoggerFactory.getLogger(PlayableContentFeeder.class);
private static final String STORAGE_RESOLVE_INTERACTIVE = "/storage-resolve/files/audio/interactive/%s";
private static final String STORAGE_RESOLVE_INTERACTIVE_PREFETCH = "/storage-resolve/files/audio/interactive_prefetch/%s";
protected final Session session;
Expand Down Expand Up @@ -84,7 +84,7 @@ private StorageResolveResponse resolveStorageInteractive(@NotNull ByteString fil
String country = session.countryCode();
if (country != null) ContentRestrictedException.checkRestrictions(country, original.getRestrictionList());

LOGGER.fatal("Couldn't find playable track: " + id.toSpotifyUri());
LOGGER.error("Couldn't find playable track: " + id.toSpotifyUri());
throw new FeederException();
}

Expand Down Expand Up @@ -134,7 +134,7 @@ private LoadedStream loadStream(@NotNull Metadata.AudioFile file, @Nullable Meta
private LoadedStream loadTrack(@NotNull Metadata.Track track, @NotNull AudioQualityPicker audioQualityPicker, boolean preload, @Nullable HaltListener haltListener) throws IOException, CdnManager.CdnException, MercuryClient.MercuryException {
Metadata.AudioFile file = audioQualityPicker.getFile(track.getFileList());
if (file == null) {
LOGGER.fatal("Couldn't find any suitable audio file, available: {}", Utils.formatsToString(track.getFileList()));
LOGGER.error("Couldn't find any suitable audio file, available: {}", Utils.formatsToString(track.getFileList()));
throw new FeederException();
}

Expand All @@ -150,7 +150,7 @@ private LoadedStream loadEpisode(@NotNull EpisodeId id, @NotNull AudioQualityPic
} else {
Metadata.AudioFile file = audioQualityPicker.getFile(episode.getAudioList());
if (file == null) {
LOGGER.fatal("Couldn't find any suitable audio file, available: {}", Utils.formatsToString(episode.getAudioList()));
LOGGER.error("Couldn't find any suitable audio file, available: {}", Utils.formatsToString(episode.getAudioList()));
throw new FeederException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import okhttp3.HttpUrl;
import okhttp3.Request;
import okhttp3.Response;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import xyz.gianlu.librespot.audio.HaltListener;
import xyz.gianlu.librespot.audio.NormalizationData;
import xyz.gianlu.librespot.audio.PlayableContentFeeder;
Expand All @@ -23,7 +23,7 @@
* @author Gianlu
*/
public final class CdnFeedHelper {
private static final Logger LOGGER = LogManager.getLogger(CdnFeedHelper.class);
private static final Logger LOGGER = LoggerFactory.getLogger(CdnFeedHelper.class);

private CdnFeedHelper() {
}
Expand Down
10 changes: 5 additions & 5 deletions lib/src/main/java/xyz/gianlu/librespot/audio/cdn/CdnManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import com.spotify.metadata.Metadata;
import com.spotify.storage.StorageResolve.StorageResolveResponse;
import okhttp3.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import xyz.gianlu.librespot.audio.*;
import xyz.gianlu.librespot.audio.decrypt.AesAudioDecrypt;
import xyz.gianlu.librespot.audio.decrypt.AudioDecrypt;
Expand All @@ -33,7 +33,7 @@
* @author Gianlu
*/
public class CdnManager {
private static final Logger LOGGER = LogManager.getLogger(CdnManager.class);
private static final Logger LOGGER = LoggerFactory.getLogger(CdnManager.class);
private final Session session;

public CdnManager(@NotNull Session session) {
Expand Down Expand Up @@ -294,15 +294,15 @@ private void requestChunk(int index) {
return;
}
} catch (IOException | CacheManager.BadChunkHashException ex) {
LOGGER.fatal("Failed requesting chunk from cache, index: {}", index, ex);
LOGGER.error("Failed requesting chunk from cache, index: {}", index, ex);
}
}

try {
InternalResponse resp = request(index);
writeChunk(resp.buffer, index, false);
} catch (IOException | CdnException ex) {
LOGGER.fatal("Failed requesting chunk from network, index: {}", index, ex);
LOGGER.error("Failed requesting chunk from network, index: {}", index, ex);
internalStream.notifyChunkError(index, new AbsChunkedInputStream.ChunkException(ex));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package xyz.gianlu.librespot.audio.storage;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import xyz.gianlu.librespot.audio.AbsChunkedInputStream;
import xyz.gianlu.librespot.cache.CacheManager;
import xyz.gianlu.librespot.common.Utils;
Expand All @@ -19,7 +19,7 @@
public class AudioFileFetch implements AudioFile {
public static final byte HEADER_SIZE = 0x3;
public static final byte HEADER_CDN = 0x4;
private static final Logger LOGGER = LogManager.getLogger(AudioFileFetch.class);
private static final Logger LOGGER = LoggerFactory.getLogger(AudioFileFetch.class);
private final CacheManager.Handler cache;
private int size = -1;
private int chunks = -1;
Expand Down Expand Up @@ -65,7 +65,7 @@ public synchronized void writeHeader(int id, byte[] bytes, boolean cached) throw

@Override
public synchronized void streamError(int chunkIndex, short code) {
LOGGER.fatal("Stream error, index: {}, code: {}", chunkIndex, code);
LOGGER.error("Stream error, index: {}, code: {}", chunkIndex, code);

exception = AbsChunkedInputStream.ChunkException.fromStreamError(code);
notifyAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import com.google.protobuf.ByteString;
import com.spotify.metadata.Metadata;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import xyz.gianlu.librespot.audio.AbsChunkedInputStream;
import xyz.gianlu.librespot.audio.GeneralAudioStream;
import xyz.gianlu.librespot.audio.HaltListener;
Expand All @@ -28,7 +28,7 @@
* @author Gianlu
*/
public class AudioFileStreaming implements AudioFile, GeneralAudioStream {
private static final Logger LOGGER = LogManager.getLogger(AudioFileStreaming.class);
private static final Logger LOGGER = LoggerFactory.getLogger(AudioFileStreaming.class);
private final CacheManager.Handler cacheHandler;
private final Metadata.AudioFile file;
private final byte[] key;
Expand Down Expand Up @@ -72,7 +72,7 @@ private void requestChunk(@NotNull ByteString fileId, int index, @NotNull AudioF
try {
session.channel().requestChunk(fileId, index, file);
} catch (IOException ex) {
LOGGER.fatal("Failed requesting chunk from network, index: {}", index, ex);
LOGGER.error("Failed requesting chunk from network, index: {}", index, ex);
chunksBuffer.internalStream.notifyChunkError(index, new AbsChunkedInputStream.ChunkException(ex));
}
}
Expand All @@ -84,7 +84,7 @@ private boolean tryCacheChunk(int index) {
cacheHandler.readChunk(index, this);
return true;
} catch (IOException | CacheManager.BadChunkHashException ex) {
LOGGER.fatal("Failed requesting chunk from cache, index: {}", index, ex);
LOGGER.error("Failed requesting chunk from cache, index: {}", index, ex);
return false;
}
}
Expand Down Expand Up @@ -147,7 +147,7 @@ public void writeHeader(int id, byte[] bytes, boolean cached) {

@Override
public void streamError(int chunkIndex, short code) {
LOGGER.fatal("Stream error, index: {}, code: {}", chunkIndex, code);
LOGGER.error("Stream error, index: {}, code: {}", chunkIndex, code);
chunksBuffer.internalStream.notifyChunkError(chunkIndex, AbsChunkedInputStream.ChunkException.fromStreamError(code));
}

Expand Down
Loading