Skip to content

Commit b2f23ce

Browse files
authored
Implement Vk Music Source Manager (#207)
1 parent 791a2db commit b2f23ce

File tree

10 files changed

+794
-7
lines changed

10 files changed

+794
-7
lines changed

README.md

+79-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
88
A collection of additional [Lavaplayer v2](https://github.com/sedmelluq/lavaplayer), [LavaSearch](https://github.com/topi314/LavaSearch) & [LavaLyrics](https://github.com/topi314/LavaLyrics) Audio Source Managers and [Lavalink v4](https://github.com/lavalink-devs/Lavalink) Plugin.
99
* [Spotify](https://www.spotify.com) playlists/albums/songs/artists(top tracks)/search results/[LavaSearch](https://github.com/topi314/LavaSearch)/[LavaLyrics](https://github.com/topi314/LavaLyrics)
10-
* [Apple Music](https://www.apple.com/apple-music/) playlists/albums/songs/artists/search results/[LavaSearch](https://github.com/topi314/LavaSearch)(Big thx to [ryan5453](https://github.com/ryan5453) for helping me)
11-
* [Deezer](https://www.deezer.com) playlists/albums/songs/artists/search results/[LavaSearch](https://github.com/topi314/LavaSearch)/[LavaLyrics](https://github.com/topi314/LavaLyrics)(Big thx to [ryan5453](https://github.com/ryan5453) and [melike2d](https://github.com/melike2d) for helping me)
12-
* [Yandex Music](https://music.yandex.ru) playlists/albums/songs/artists/podcasts/search results/[LavaLyrics](https://github.com/topi314/LavaLyrics)/[LavaSearch](https://github.com/topi314/LavaSearch)(Thx to [AgutinVBoy](https://github.com/agutinvboy) for implementing it)
10+
* [Apple Music](https://www.apple.com/apple-music/) playlists/albums/songs/artists/search results/[LavaSearch](https://github.com/topi314/LavaSearch) (Big thx to [ryan5453](https://github.com/ryan5453) for helping me)
11+
* [Deezer](https://www.deezer.com) playlists/albums/songs/artists/search results/[LavaSearch](https://github.com/topi314/LavaSearch)/[LavaLyrics](https://github.com/topi314/LavaLyrics) (Big thx to [ryan5453](https://github.com/ryan5453) and [melike2d](https://github.com/melike2d) for helping me)
12+
* [Yandex Music](https://music.yandex.ru) playlists/albums/songs/artists/podcasts/search results/[LavaLyrics](https://github.com/topi314/LavaLyrics)/[LavaSearch](https://github.com/topi314/LavaSearch) (Thx to [AgutinVBoy](https://github.com/agutinvboy) for implementing it)
1313
* [Flowery TTS](https://flowery.pw/docs) (Thx to [bachtran02](https://github.com/bachtran02) for implementing it)
1414
* [YouTube](https://youtube.com) & [YouTubeMusic](https://music.youtube.com/) [LavaSearch](https://github.com/topi314/LavaSearch)/[LavaLyrics](https://github.com/topi314/LavaLyrics) (Thx to [DRSchlaubi](https://github.com/DRSchlaubi) for helping me)
15+
* [Vk Music](https://music.vk.com/) playlists/albums/songs/artists(top tracks)/search results/[LavaLyrics](https://github.com/topi314/LavaLyrics)/[LavaSearch](https://github.com/topi314/LavaSearch) (Thx to [Krispeckt](https://github.com/Krispeckt) for implementing it)
1516

1617
> [!IMPORTANT]
1718
> Tracks from Spotify & Apple Music don't actually play from their sources, but are instead resolved via the configured providers
@@ -306,6 +307,56 @@ playerManager.registerSourceManager(new FloweryTTSSourceManager("..."));
306307

307308
---
308309

310+
### Vk Music
311+
312+
<details>
313+
<summary>How to get user token</summary>
314+
315+
### WARNING!
316+
#### Carefully, this token can be used to access your personal data. Use a newly created account specifically for LavaSrc. This source is designed mainly for the RU region, 80% of songs in other regions will not be played.
317+
318+
1. Go to the authorization page [Marusya application](https://oauth.vk.com/authorize?client_id=6463690&scope=1073737727&redirect_uri=https://oauth.vk.com/blank.html&display=page&response_type=token&revoke=1)
319+
2. Authorize through your vk account.
320+
3. A link like this `https://oauth.vk.com/blank.html#access_token=$$$$$&expires_in=0&user_id=$$$$$@[email protected]`
321+
4. Copy your token and paste it into your config! Enjoy captcha-free vk music!
322+
323+
</details>
324+
325+
```java
326+
AudioPlayerManager playerManager = new DefaultAudioPlayerManager();
327+
328+
// create a new VkMusicSourceManager with the user token and register it
329+
playerManager.registerSourceManager(new VkMusicSourceManager("...");
330+
```
331+
332+
#### LavaLyrics
333+
<details>
334+
<summary>Click to expand</summary>
335+
336+
```java
337+
// create new lyrics manager
338+
var lyricsManager = new LyricsManager();
339+
340+
// register source
341+
lyricsManager.registerLyricsManager(vkmusic);
342+
```
343+
</details>
344+
345+
#### LavaSearch
346+
<details>
347+
<summary>Click to expand</summary>
348+
349+
```java
350+
// create new search manager
351+
var searchManager = new SearchManager();
352+
353+
// register source
354+
searchManager.registerSearchManager(vkmusic);
355+
```
356+
</details>
357+
358+
---
359+
309360
## Lavalink Usage
310361

311362
This plugin requires Lavalink `v4` or greater
@@ -340,6 +391,8 @@ To get your Deezer arl cookie go [here](#deezer)
340391

341392
To get your Yandex Music access token go [here](#yandex-music)
342393

394+
To get your Vk Music user token go [here](#vk-music)
395+
343396
(YES `plugins` IS AT ROOT IN THE YAML)
344397
```yaml
345398
plugins:
@@ -357,11 +410,13 @@ plugins:
357410
yandexmusic: false # Enable Yandex Music source
358411
flowerytts: false # Enable Flowery TTS source
359412
youtube: true # Enable YouTube search source (https://github.com/topi314/LavaSearch)
413+
vkmusic: false # Enable Vk Music source
360414
lyrics-sources:
361415
spotify: false # Enable Spotify lyrics source
362416
deezer: false # Enable Deezer lyrics source
363417
youtube: false # Enable YouTube lyrics source
364418
yandexmusic: false # Enable Yandex Music lyrics source
419+
vkmusic: true # Enable Vk Music lyrics source
365420
spotify:
366421
clientId: "your client id"
367422
clientSecret: "your client secret"
@@ -400,6 +455,11 @@ plugins:
400455
audioFormat: "mp3" # supported formats are: mp3, ogg_opus, ogg_vorbis, aac, wav, and flac. Default format is mp3
401456
youtube:
402457
countryCode: "US" # the country code you want to use for searching lyrics via ISRC. See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
458+
vkmusic:
459+
userToken: "your user token" # This token is needed for authorization in the api. Guide: https://github.com/topi314/LavaSrc#vk-music
460+
playlistLoadLimit: 1 # The number of pages at 50 tracks each
461+
artistLoadLimit: 1 # The number of pages at 10 tracks each
462+
recommendationsLoadLimit: 10 # Number of tracks
403463
```
404464

405465
### Plugin Info
@@ -481,4 +541,20 @@ You can read about all the available options [here](https://flowery.pw/docs), a
481541

482542
* `ftts://hello%20world`
483543
* `ftts://hello%20world?audio_format=ogg_opus&translate=False&silence=1000&speed=1.0&voice=09924826-684f-51e9-825b-cf85aed2b2cf`
544+
545+
### Vk Music
546+
* `vksearch:animals architects`
547+
* `vkrec:-2001015907_104015907` (`vkrec:{TRACK_ID}`)
548+
* https://vk.com/audio-2001015907_104015907
549+
* https://vk.ru/artist/shadxwbxrn
550+
* https://vk.com/audios700949584?q=phonk%20playlist&z=audio_playlist-219343251_152_389941c481d1375ac0
551+
* https://vk.com/audios700949584?q=phonk%20playlist&z=audio_playlist-219343251_152
552+
* https://vk.com/music/playlist/-219343251_152_389941c481d1375ac0
553+
* https://vk.ru/music/playlist/-219343251_152
554+
* https://vk.com/music/album/-2000228258_15228258_cafcb9e95f552acbb6?act=album
555+
* https://vk.com/music/album/-2000228258_15228258_cafcb9e95f552acbb6
556+
* https://vk.ru/music/album/-2000228258_15228258?act=album
557+
* https://vk.com/music/album/-2000228258_15228258
558+
* https://vk.com/audios700949584?q=phonk%20album&z=audio_playlist-2000933493_13933493%2Fbe3494d46d310b0d0d
559+
* https://vk.ru/audios700949584?q=phonk%20album&z=audio_playlist-2000933493_13933493
484560
---

application.example.yml

+7
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ plugins:
1313
yandexmusic: false # Enable Yandex Music source
1414
flowerytts: false # Enable Flowery TTs source
1515
youtube: true # Enable YouTube search source (https://github.com/topi314/LavaSearch)
16+
vkmusic: false # Enable Vk Music source
1617
lyrics-sources:
1718
spotify: false # Enable Spotify lyrics source
1819
deezer: false # Enable Deezer lyrics source
1920
youtube: false # Enable YouTube lyrics source
2021
yandexmusic: false # Enable Yandex Music lyrics source
22+
vkmusic: false # Enable Vk Music lyrics source
2123
spotify:
2224
clientId: "your client id"
2325
clientSecret: "your client secret"
@@ -48,6 +50,11 @@ plugins:
4850
audioFormat: "mp3" # supported formats are: mp3, ogg_opus, ogg_vorbis, aac, wav, and flac. Default format is mp3
4951
youtube:
5052
countryCode: "US" # the country code you want to use for searching lyrics via ISRC. See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
53+
vkmusic:
54+
userToken: "your user token" # This token is needed for authorization in the api. Guide: https://github.com/topi314/LavaSrc#vk-music
55+
playlistLoadLimit: 1 # The number of pages at 50 tracks each
56+
artistLoadLimit: 1 # The number of pages at 10 tracks each
57+
recommendationsLoadLimit: 10 # Number of tracks
5158

5259
server: # REST and WS server
5360
port: 2333
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.github.topi314.lavasrc.vkmusic;
2+
3+
import com.github.topi314.lavasrc.ExtendedAudioPlaylist;
4+
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
5+
6+
import java.util.List;
7+
8+
public class VkMusicAudioPlaylist extends ExtendedAudioPlaylist {
9+
10+
public VkMusicAudioPlaylist(String name, List<AudioTrack> tracks, Type type, String identifier, String artworkURL, String author, Integer totalTracks) {
11+
super(name, tracks, type, identifier, artworkURL, author, totalTracks);
12+
}
13+
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.github.topi314.lavasrc.vkmusic;
2+
3+
import com.github.topi314.lavasrc.ExtendedAudioTrack;
4+
import com.sedmelluq.discord.lavaplayer.container.mp3.Mp3AudioTrack;
5+
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManager;
6+
import com.sedmelluq.discord.lavaplayer.tools.io.PersistentHttpStream;
7+
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
8+
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
9+
import com.sedmelluq.discord.lavaplayer.track.playback.LocalAudioTrackExecutor;
10+
11+
import java.io.IOException;
12+
import java.net.URI;
13+
import java.net.URISyntaxException;
14+
15+
public class VkMusicAudioTrack extends ExtendedAudioTrack {
16+
17+
private final VkMusicSourceManager sourceManager;
18+
19+
public VkMusicAudioTrack(AudioTrackInfo trackInfo, VkMusicSourceManager sourceManager) {
20+
this(trackInfo, null, null, null, null, null, sourceManager);
21+
}
22+
23+
public VkMusicAudioTrack(AudioTrackInfo trackInfo, String albumName, String albumUrl, String artistUrl, String artistArtworkUrl, String previewUrl, VkMusicSourceManager sourceManager) {
24+
super(trackInfo, albumName, albumUrl, artistUrl, artistArtworkUrl, previewUrl, false);
25+
this.sourceManager = sourceManager;
26+
}
27+
28+
@Override
29+
public void process(LocalAudioTrackExecutor executor) throws Exception {
30+
try (var httpInterface = this.sourceManager.getHttpInterface()) {
31+
try (var stream = new PersistentHttpStream(httpInterface, getMp3TrackUri(), this.trackInfo.length)) {
32+
processDelegate(new Mp3AudioTrack(this.trackInfo, stream), executor);
33+
}
34+
}
35+
}
36+
37+
public URI getMp3TrackUri() throws URISyntaxException, IOException {
38+
var id = this.trackInfo.identifier;
39+
var json = this.sourceManager.getJson("audio.getById", "&audios=" + id)
40+
.get("response");
41+
if (
42+
json.isNull()
43+
|| json.values().isEmpty()
44+
|| json.values().get(0).get("url").isNull()
45+
) {
46+
throw new IllegalStateException("No download url found for track " + id);
47+
}
48+
49+
return new URI(json.values().get(0).get("url").text());
50+
}
51+
52+
@Override
53+
protected AudioTrack makeShallowClone() {
54+
return new VkMusicAudioTrack(this.trackInfo, this.sourceManager);
55+
}
56+
57+
@Override
58+
public AudioSourceManager getSourceManager() {
59+
return this.sourceManager;
60+
}
61+
}

0 commit comments

Comments
 (0)