Skip to content

Commit bbaee2a

Browse files
authored
Added proxy settings for VK Music & fixed minor inaccuracies in README.md (#308)
1 parent 0cf077e commit bbaee2a

File tree

6 files changed

+51
-15
lines changed

6 files changed

+51
-15
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ plugins:
175175
playlistLoadLimit: 1 # The number of pages at 50 tracks each
176176
artistLoadLimit: 1 # The number of pages at 10 tracks each
177177
recommendationsLoadLimit: 10 # Number of tracks
178+
# proxy: # If the server with the plugin is located outside of Russia, you must configure a proxy located in Russia to bypass regional restrictions.
179+
# url: "https://example.org" # The HTTP proxy to use
180+
# username: "my-bot" # Optional username to authenticate with the proxy
181+
# password: "youshallpass" # Optional password to authenticate with the proxy
178182
tidal:
179183
countryCode: "US" # the country code for accessing region-specific content on Tidal (ISO 3166-1 alpha-2).
180184
searchLimit: 6 # How many search results should be returned
@@ -733,7 +737,9 @@ playerManager.registerSourceManager(new FloweryTTSSourceManager("..."));
733737
AudioPlayerManager playerManager = new DefaultAudioPlayerManager();
734738

735739
// create a new VkMusicSourceManager with the user token and register it
736-
playerManager.registerSourceManager(new VkMusicSourceManager("...");
740+
var vkMusic = new VkMusicSourceManager("...");
741+
742+
playerManager.registerSourceManager(vkMusic);
737743
```
738744

739745
#### LavaLyrics
@@ -746,7 +752,7 @@ playerManager.registerSourceManager(new VkMusicSourceManager("...");
746752
var lyricsManager = new LyricsManager();
747753

748754
// register source
749-
lyricsManager.registerLyricsManager(vkmusic);
755+
lyricsManager.registerLyricsManager(vkMusic);
750756
```
751757

752758
</details>
@@ -761,7 +767,7 @@ lyricsManager.registerLyricsManager(vkmusic);
761767
var searchManager = new SearchManager();
762768

763769
// register source
764-
searchManager.registerSearchManager(vkmusic);
770+
searchManager.registerSearchManager(vkMusic);
765771
```
766772

767773
</details>

application.example.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ plugins:
7676
playlistLoadLimit: 1 # The number of pages at 50 tracks each
7777
artistLoadLimit: 1 # The number of pages at 10 tracks each
7878
recommendationsLoadLimit: 10 # Number of tracks
79+
# proxy: # If the server with the plugin is located outside of Russia, you must configure a proxy located in Russia to bypass regional restrictions.
80+
# url: "https://example.org" # The HTTP proxy to use
81+
# username: "my-bot" # Optional username to authenticate with the proxy
82+
# password: "youshallpass" # Optional password to authenticate with the proxy
7983
tidal:
8084
countryCode: "US" # the country code for accessing region-specific content on Tidal (ISO 3166-1 alpha-2).
8185
searchLimit: 6 # How many search results should be returned

main/src/main/java/com/github/topi314/lavasrc/vkmusic/VkMusicAudioTrack.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,23 @@ public void process(LocalAudioTrackExecutor executor) throws Exception {
3535
}
3636

3737
public URI getMp3TrackUri() throws URISyntaxException, IOException {
38-
var id = this.trackInfo.identifier;
39-
var json = this.sourceManager.getJson("audio.getById", "&audios=" + id)
38+
String id = trackInfo.identifier;
39+
40+
var response = sourceManager
41+
.getJson("audio.getById", "&audios=" + id)
4042
.get("response");
41-
if (
42-
json.isNull()
43-
|| json.values().isEmpty()
44-
|| json.values().get(0).get("url").isNull()
45-
) {
43+
44+
if (response == null || response.isNull() || response.values().isEmpty()) {
45+
throw new IllegalStateException("Empty response for track " + id);
46+
}
47+
48+
var url = response.values().get(0).get("url");
49+
50+
if (url == null || url.text().isEmpty()) {
4651
throw new IllegalStateException("No download url found for track " + id);
4752
}
4853

49-
return new URI(json.values().get(0).get("url").text());
54+
return new URI(url.text());
5055
}
5156

5257
@Override

main/src/main/java/com/github/topi314/lavasrc/vkmusic/VkMusicSourceManager.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,16 @@ private AudioItem getTrack(String id) throws IOException {
400400
if (json.isNull() || json.get("response").isNull()) {
401401
return AudioReference.NO_TRACK;
402402
}
403-
return this.parseTrack(json.get("response").values().get(0));
403+
404+
var track = this.parseTrack(json.get("response").values().get(0));
405+
if (track == null) {
406+
return AudioReference.NO_TRACK;
407+
}
408+
return track;
404409
}
405410

406411
private AudioItem getArtist(String id) throws IOException {
407-
var json = this.getJson("audio.getAudiosByArtist", "&artist_id=" + id + "&count" + artistLoadLimit * 20);
412+
var json = this.getJson("audio.getAudiosByArtist", "&artist_id=" + id + "&count=" + artistLoadLimit * 20);
408413
if (json.isNull() || json.get("response").values().isEmpty()) {
409414
return AudioReference.NO_TRACK;
410415
}
@@ -453,7 +458,7 @@ private List<AudioTrack> parseTracks(JsonBrowser json) {
453458

454459
private AudioTrack parseTrack(JsonBrowser json) {
455460
try {
456-
if (json.get("url").isNull()) {
461+
if (json.get("url").isNull() || json.get("url").text().isEmpty()) {
457462
return null;
458463
}
459464
String coverUri = null;
@@ -537,4 +542,4 @@ public void shutdown() {
537542
public HttpInterface getHttpInterface() {
538543
return this.httpInterfaceManager.getInterface();
539544
}
540-
}
545+
}

plugin/src/main/java/com/github/topi314/lavasrc/plugin/LavaSrcPlugin.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ public LavaSrcPlugin(
146146
}
147147
if (sourcesConfig.isVkMusic() || lyricsSourcesConfig.isVkMusic()) {
148148
this.vkMusic = new VkMusicSourceManager(vkMusicConfig.getUserToken());
149+
proxyConfigurationService.configure(this.vkMusic, vkMusicConfig.getProxy());
150+
149151
if (vkMusicConfig.getPlaylistLoadLimit() > 0) {
150152
vkMusic.setPlaylistLoadLimit(vkMusicConfig.getPlaylistLoadLimit());
151153
}

plugin/src/main/java/com/github/topi314/lavasrc/plugin/config/VkMusicConfig.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
11
package com.github.topi314.lavasrc.plugin.config;
22

3+
import org.jetbrains.annotations.Nullable;
34
import org.springframework.boot.context.properties.ConfigurationProperties;
45
import org.springframework.stereotype.Component;
56

67
@ConfigurationProperties(prefix = "plugins.lavasrc.vkmusic")
78
@Component
89
public class VkMusicConfig {
910

11+
@Nullable
12+
private HttpProxyConfig proxy;
13+
1014
private String userToken;
1115
private int playlistLoadLimit = 1;
1216
private int artistLoadLimit = 1;
1317
private int recommendationLoadLimit = 1;
1418

19+
@Nullable
20+
public HttpProxyConfig getProxy() {
21+
return this.proxy;
22+
}
23+
24+
@SuppressWarnings("unused")
25+
public void setProxy(@Nullable HttpProxyConfig proxy) {
26+
this.proxy = proxy;
27+
}
28+
1529
public String getUserToken() {
1630
return this.userToken;
1731
}

0 commit comments

Comments
 (0)