Skip to content

Commit 18ee677

Browse files
committed
Merge remote-tracking branch 'origin/dev'
# Conflicts: # CHANGELOG.md
2 parents b0a0eca + 4535dc5 commit 18ee677

File tree

16 files changed

+226
-153
lines changed

16 files changed

+226
-153
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@
33
Each release usually includes various fixes and improvements.
44
The most noteworthy of these, as well as any features and breaking changes, are listed here.
55

6+
## v3.2.1
7+
8+
* Update dependencies -- fixes frequent youtube HTTP errors
9+
* Return `FriendlyException` message on `LOAD_FAILED` #174
10+
* Add option to disable `ytsearch` and `scsearch` #194
11+
12+
Contributors:
13+
[@Devoxin](https://github.com/Devoxin),
14+
[@duncte123](https://github.com/duncte123),
15+
[@Frederikam](https://github.com/Frederikam), and
16+
[@napstr](https://github.com/napstr)
17+
618
## v3.2.0.3
719
* Add compatibility for Java 8-10
820

IMPLEMENTATION.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,22 @@ Additionally, in every `/loadtracks` response, a `loadType` property is returned
307307
* `NO_MATCHES` - Returned if no matches/sources could be found for a given identifier.
308308
* `LOAD_FAILED` - Returned if Lavaplayer failed to load something for some reason.
309309

310+
If the loadType is `LOAD_FAILED`, the response will contain an `exception` object with `message` and `severity` properties.
311+
`message` is a string detailing why the track failed to load, and is okay to display to end-users. Severity represents how common the error is.
312+
A severity level of `COMMON` indicates that the error is non-fatal and that the issue is not from Lavalink itself.
313+
314+
```json
315+
{
316+
"loadType": "LOAD_FAILED",
317+
"playlistInfo": {},
318+
"tracks": [],
319+
"exception": {
320+
"message": "The uploader has not made this video available in your country.",
321+
"severity": "COMMON"
322+
}
323+
}
324+
```
325+
310326
All REST responses from Lavalink include a `Lavalink-Api-Version` header.
311327

312328
### Resuming Lavalink sessions

LavalinkServer/application.yml.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ lavalink:
1818
local: false
1919
bufferDurationMs: 400
2020
youtubePlaylistLoadLimit: 6 # Number of pages at 100 each
21+
youtubeSearchEnabled: true
22+
soundcloudSearchEnabled: true
2123
gc-warnings: true
2224

2325
metrics:

LavalinkServer/build.gradle

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ apply plugin: 'com.gorylenko.gradle-git-properties'
66
apply plugin: 'org.ajoberstar.grgit'
77
apply plugin: 'kotlin'
88
apply plugin: 'kotlin-spring'
9+
apply plugin: "com.adarshr.test-logger"
910

1011
description = 'Play audio to discord voice channels'
1112
mainClassName = "lavalink.server.Launcher"
@@ -32,10 +33,6 @@ bootRun {
3233
}
3334
}
3435

35-
test {
36-
useJUnitPlatform()
37-
}
38-
3936
dependencies {
4037
compile group: 'club.minnced', name: 'magma', version: magmaVersion
4138
compile group: 'com.sedmelluq', name: 'lavaplayer', version: lavaplayerVersion
@@ -60,6 +57,8 @@ dependencies {
6057
compile group: 'io.prometheus', name: 'simpleclient_hotspot', version: prometheusVersion
6158
compile group: 'io.prometheus', name: 'simpleclient_logback', version: prometheusVersion
6259
compile group: 'io.prometheus', name: 'simpleclient_servlet', version: prometheusVersion
60+
61+
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: springBootVersion
6362
}
6463

6564
processResources {

LavalinkServer/src/main/java/lavalink/server/Launcher.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.springframework.boot.autoconfigure.SpringBootApplication;
3333
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
3434
import org.springframework.boot.context.event.ApplicationFailedEvent;
35+
import org.springframework.boot.web.servlet.ServletComponentScan;
3536

3637
import java.time.Instant;
3738
import java.time.ZoneId;

LavalinkServer/src/main/java/lavalink/server/config/AudioPlayerConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ public Supplier<AudioPlayerManager> audioPlayerManagerSupplier(AudioSourcesConfi
3131
}
3232

3333
if (sources.isYoutube()) {
34-
YoutubeAudioSourceManager youtube = new YoutubeAudioSourceManager();
34+
YoutubeAudioSourceManager youtube = new YoutubeAudioSourceManager(serverConfig.isYoutubeSearchEnabled());
3535
Integer playlistLoadLimit = serverConfig.getYoutubePlaylistLoadLimit();
3636

3737
if (playlistLoadLimit != null) youtube.setPlaylistPageCount(playlistLoadLimit);
3838
audioPlayerManager.registerSourceManager(youtube);
3939
}
4040
if (sources.isBandcamp()) audioPlayerManager.registerSourceManager(new BandcampAudioSourceManager());
41-
if (sources.isSoundcloud()) audioPlayerManager.registerSourceManager(new SoundCloudAudioSourceManager());
41+
if (sources.isSoundcloud()) audioPlayerManager.registerSourceManager(new SoundCloudAudioSourceManager(serverConfig.isSoundcloudSearchEnabled()));
4242
if (sources.isTwitch()) audioPlayerManager.registerSourceManager(new TwitchStreamAudioSourceManager());
4343
if (sources.isVimeo()) audioPlayerManager.registerSourceManager(new VimeoAudioSourceManager());
4444
if (sources.isMixer()) audioPlayerManager.registerSourceManager(new BeamAudioSourceManager());
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package lavalink.server.config;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.http.HttpStatus;
7+
import org.springframework.web.servlet.HandlerInterceptor;
8+
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
9+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
10+
11+
import javax.servlet.http.HttpServletRequest;
12+
import javax.servlet.http.HttpServletResponse;
13+
14+
@Configuration
15+
public class RequestAuthorizationFilter implements HandlerInterceptor, WebMvcConfigurer {
16+
17+
private static final Logger log = LoggerFactory.getLogger(RequestAuthorizationFilter.class);
18+
private ServerConfig serverConfig;
19+
private MetricsPrometheusConfigProperties metricsConfig;
20+
21+
public RequestAuthorizationFilter(ServerConfig serverConfig, MetricsPrometheusConfigProperties metricsConfig) {
22+
this.serverConfig = serverConfig;
23+
this.metricsConfig = metricsConfig;
24+
}
25+
26+
@Override
27+
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
28+
// Collecting metrics is anonymous
29+
if (!metricsConfig.getEndpoint().isEmpty()
30+
&& request.getServletPath().equals(metricsConfig.getEndpoint())) return true;
31+
32+
if (request.getServletPath().equals("/error")) return true;
33+
34+
String authorization = request.getHeader("Authorization");
35+
36+
if (authorization == null || !authorization.equals(serverConfig.getPassword())) {
37+
String method = request.getMethod();
38+
String path = request.getRequestURI().substring(request.getContextPath().length());
39+
String ip = request.getRemoteAddr();
40+
41+
if (authorization == null) {
42+
log.warn("Authorization missing for {} on {} {}", ip, method, path);
43+
response.setStatus(HttpStatus.UNAUTHORIZED.value());
44+
return false;
45+
}
46+
log.warn("Authorization failed for {} on {} {}", ip, method, path);
47+
response.setStatus(HttpStatus.FORBIDDEN.value());
48+
return false;
49+
}
50+
51+
return true;
52+
}
53+
54+
@Override
55+
public void addInterceptors(InterceptorRegistry registry) {
56+
registry.addInterceptor(this);
57+
}
58+
}

LavalinkServer/src/main/java/lavalink/server/config/ServerConfig.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public class ServerConfig {
3838
@Nullable
3939
private Integer youtubePlaylistLoadLimit;
4040
private boolean gcWarnings = true;
41+
private boolean youtubeSearchEnabled = true;
42+
private boolean soundcloudSearchEnabled = true;
4143

4244
public String getPassword() {
4345
return password;
@@ -84,4 +86,20 @@ public boolean isGcWarnings() {
8486
public void setGcWarnings(boolean gcWarnings) {
8587
this.gcWarnings = gcWarnings;
8688
}
89+
90+
public boolean isYoutubeSearchEnabled() {
91+
return youtubeSearchEnabled;
92+
}
93+
94+
public void setYoutubeSearchEnabled(boolean youtubeSearchEnabled) {
95+
this.youtubeSearchEnabled = youtubeSearchEnabled;
96+
}
97+
98+
public boolean isSoundcloudSearchEnabled() {
99+
return soundcloudSearchEnabled;
100+
}
101+
102+
public void setSoundcloudSearchEnabled(boolean soundcloudSearchEnabled) {
103+
this.soundcloudSearchEnabled = soundcloudSearchEnabled;
104+
}
87105
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package lavalink.server.info;
2+
3+
import org.springframework.web.bind.annotation.GetMapping;
4+
import org.springframework.web.bind.annotation.RestController;
5+
6+
/**
7+
* Created by napster on 08.03.19.
8+
*/
9+
@RestController
10+
public class InfoRestHandler {
11+
12+
private final AppInfo appInfo;
13+
14+
public InfoRestHandler(AppInfo appInfo) {
15+
this.appInfo = appInfo;
16+
}
17+
18+
@GetMapping("/version")
19+
public String version() {
20+
return appInfo.getVersionBuild();
21+
}
22+
}

LavalinkServer/src/main/java/lavalink/server/player/AudioLoader.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@
4040
public class AudioLoader implements AudioLoadResultHandler {
4141

4242
private static final Logger log = LoggerFactory.getLogger(AudioLoader.class);
43-
private static final LoadResult NO_MATCHES = new LoadResult(Collections.emptyList(),
44-
null, ResultStatus.NO_MATCHES, null);
45-
private static final LoadResult LOAD_FAILED = new LoadResult(Collections.emptyList(),
46-
null, ResultStatus.LOAD_FAILED, null);
43+
private static final LoadResult NO_MATCHES = new LoadResult(ResultStatus.NO_MATCHES, Collections.emptyList(),
44+
null, null);
4745

4846
private final AudioPlayerManager audioPlayerManager;
4947

@@ -71,7 +69,7 @@ public void trackLoaded(AudioTrack audioTrack) {
7169
log.info("Loaded track " + audioTrack.getInfo().title);
7270
ArrayList<AudioTrack> result = new ArrayList<>();
7371
result.add(audioTrack);
74-
this.loadResult.complete(new LoadResult(result, null, ResultStatus.TRACK_LOADED, null));
72+
this.loadResult.complete(new LoadResult(ResultStatus.TRACK_LOADED, result, null, null));
7573
}
7674

7775
@Override
@@ -88,7 +86,7 @@ public void playlistLoaded(AudioPlaylist audioPlaylist) {
8886
ResultStatus status = audioPlaylist.isSearchResult() ? ResultStatus.SEARCH_RESULT : ResultStatus.PLAYLIST_LOADED;
8987
List<AudioTrack> loadedItems = audioPlaylist.getTracks();
9088

91-
this.loadResult.complete(new LoadResult(loadedItems, playlistName, status, selectedTrack));
89+
this.loadResult.complete(new LoadResult(status, loadedItems, playlistName, selectedTrack));
9290
}
9391

9492
@Override
@@ -100,7 +98,7 @@ public void noMatches() {
10098
@Override
10199
public void loadFailed(FriendlyException e) {
102100
log.error("Load failed", e);
103-
this.loadResult.complete(LOAD_FAILED);
101+
this.loadResult.complete(new LoadResult(e));
104102
}
105103

106-
}
104+
}

0 commit comments

Comments
 (0)