Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Vk Music Source Manager #207

Merged
merged 23 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from 16 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
76 changes: 76 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ A collection of additional [Lavaplayer v2](https://github.com/sedmelluq/lavaplay
* [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)
topi314 marked this conversation as resolved.
Show resolved Hide resolved
* [Flowery TTS](https://flowery.pw/docs) (Thx to [bachtran02](https://github.com/bachtran02) for implementing it)
* [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)
* [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)
topi314 marked this conversation as resolved.
Show resolved Hide resolved

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

---

### Vk Music

<details>
<summary>How to get need user token</summary>
topi314 marked this conversation as resolved.
Show resolved Hide resolved

### WARNING!
#### 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.

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)
2. Authorize through your vk account.
3. A link like this `https://oauth.vk.com/blank.html#access_token=$$$$$&expires_in=0&user_id=$$$$$@email=$$$$$@gmail.com`
4. Copy your token and paste it into your config! Enjoy captcha-free vk music!

</details>

```java
AudioPlayerManager playerManager = new DefaultAudioPlayerManager();

// create a new VkMusicSourceManager with the user token and register it
playerManager.registerSourceManager(new VkMusicSourceManager("...");
```

#### LavaLyrics
<details>
<summary>Click to expand</summary>

```java
// create new lyrics manager
var lyricsManager = new LyricsManager();

// register source
lyricsManager.registerLyricsManager(vkmusic);
```
</details>

#### LavaSearch
<details>
<summary>Click to expand</summary>

```java
// create new search manager
var searchManager = new SearchManager();

// register source
searchManager.registerSearchManager(vkmusic);
```
</details>

---

## Lavalink Usage

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

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

To get your Vk Music user token go [here](#vk-music)

(YES `plugins` IS AT ROOT IN THE YAML)
```yaml
plugins:
Expand All @@ -357,11 +410,13 @@ plugins:
yandexmusic: false # Enable Yandex Music source
flowerytts: false # Enable Flowery TTS source
youtube: true # Enable YouTube search source (https://github.com/topi314/LavaSearch)
vkmusic: false # Enable Vk Music source
lyrics-sources:
spotify: false # Enable Spotify lyrics source
deezer: false # Enable Deezer lyrics source
youtube: false # Enable YouTube lyrics source
yandexmusic: false # Enable Yandex Music lyrics source
vkmusic: true # Enable Vk Music lyrics source
spotify:
clientId: "your client id"
clientSecret: "your client secret"
Expand Down Expand Up @@ -400,6 +455,11 @@ plugins:
audioFormat: "mp3" # supported formats are: mp3, ogg_opus, ogg_vorbis, aac, wav, and flac. Default format is mp3
youtube:
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
vkmusic:
userToken: "your user token" # This token is needed for authorization in the api. Guide: https://github.com/topi314/LavaSrc#vk-music
playlistLoadLimit: 1 # The number of pages at 50 tracks each
artistLoadLimit: 1 # The number of pages at 10 tracks each
recommendationsLoadLimit: 10 # Number of tracks
```

### Plugin Info
Expand Down Expand Up @@ -476,6 +536,22 @@ LavaSrc adds the following fields to tracks & playlists in Lavalink
* https://music.yandex.ru/users/yamusic-bestsongs/playlists/701626
* https://music.yandex.ru/artist/701626

### Vk Music
* `vksearch:animals architects`
* `vkrec:-2001015907_104015907` (`vkrec:{TRACK_ID}`)
* https://vk.com/audio-2001015907_104015907
* https://vk.ru/artist/shadxwbxrn
* https://vk.com/audios700949584?q=phonk%20playlist&z=audio_playlist-219343251_152_389941c481d1375ac0
* https://vk.com/audios700949584?q=phonk%20playlist&z=audio_playlist-219343251_152
* https://vk.com/music/playlist/-219343251_152_389941c481d1375ac0
* https://vk.ru/music/playlist/-219343251_152
* https://vk.com/music/album/-2000228258_15228258_cafcb9e95f552acbb6?act=album
* https://vk.com/music/album/-2000228258_15228258_cafcb9e95f552acbb6
* https://vk.ru/music/album/-2000228258_15228258?act=album
* https://vk.com/music/album/-2000228258_15228258
* https://vk.com/audios700949584?q=phonk%20album&z=audio_playlist-2000933493_13933493%2Fbe3494d46d310b0d0d
* https://vk.ru/audios700949584?q=phonk%20album&z=audio_playlist-2000933493_13933493

topi314 marked this conversation as resolved.
Show resolved Hide resolved
### Flowery TTS
You can read about all the available options [here](https://flowery.pw/docs), a list of available voices is [here](https://api.flowery.pw/v1/tts/voices)

Expand Down
7 changes: 7 additions & 0 deletions application.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ plugins:
yandexmusic: false # Enable Yandex Music source
flowerytts: false # Enable Flowery TTs source
youtube: true # Enable YouTube search source (https://github.com/topi314/LavaSearch)
vkmusic: false # Enable Vk Music source
lyrics-sources:
spotify: false # Enable Spotify lyrics source
deezer: false # Enable Deezer lyrics source
youtube: false # Enable YouTube lyrics source
yandexmusic: false # Enable Yandex Music lyrics source
vkmusic: false # Enable Vk Music lyrics source
spotify:
clientId: "your client id"
clientSecret: "your client secret"
Expand Down Expand Up @@ -48,6 +50,11 @@ plugins:
audioFormat: "mp3" # supported formats are: mp3, ogg_opus, ogg_vorbis, aac, wav, and flac. Default format is mp3
youtube:
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
vkmusic:
userToken: "your user token" # This token is needed for authorization in the api. Guide: https://github.com/topi314/LavaSrc#vk-music
playlistLoadLimit: 1 # The number of pages at 50 tracks each
artistLoadLimit: 1 # The number of pages at 10 tracks each
recommendationsLoadLimit: 10 # Number of tracks

server: # REST and WS server
port: 2333
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.github.topi314.lavasrc.vkmusic;

import com.github.topi314.lavasrc.ExtendedAudioPlaylist;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;

import java.util.List;

public class VkMusicAudioPlaylist extends ExtendedAudioPlaylist {

public VkMusicAudioPlaylist(String name, List<AudioTrack> tracks, Type type, String identifier, String artworkURL, String author, Integer totalTracks) {
super(name, tracks, type, identifier, artworkURL, author, totalTracks);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.github.topi314.lavasrc.vkmusic;

import com.github.topi314.lavasrc.ExtendedAudioTrack;
import com.sedmelluq.discord.lavaplayer.container.mp3.Mp3AudioTrack;
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManager;
import com.sedmelluq.discord.lavaplayer.tools.io.PersistentHttpStream;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
import com.sedmelluq.discord.lavaplayer.track.playback.LocalAudioTrackExecutor;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class VkMusicAudioTrack extends ExtendedAudioTrack {

private final VkMusicSourceManager sourceManager;

public VkMusicAudioTrack(AudioTrackInfo trackInfo, VkMusicSourceManager sourceManager) {
this(trackInfo, null, null, null, null, null, sourceManager);
}

public VkMusicAudioTrack(AudioTrackInfo trackInfo, String albumName, String albumUrl, String artistUrl, String artistArtworkUrl, String previewUrl, VkMusicSourceManager sourceManager) {
super(trackInfo, albumName, albumUrl, artistUrl, artistArtworkUrl, previewUrl, false);
this.sourceManager = sourceManager;
}

@Override
public void process(LocalAudioTrackExecutor executor) throws Exception {
try (var httpInterface = this.sourceManager.getHttpInterface()) {
try (var stream = new PersistentHttpStream(httpInterface, getMp3TrackUri(), this.trackInfo.length)) {
processDelegate(new Mp3AudioTrack(this.trackInfo, stream), executor);
}
}
}

public URI getMp3TrackUri() throws URISyntaxException, IOException {
var token = sourceManager.getUserToken();
var id = this.trackInfo.identifier;

if (token == null || token.isEmpty()) {
throw new IllegalArgumentException("Vk Music user token must be set");
}
topi314 marked this conversation as resolved.
Show resolved Hide resolved

var json = this.sourceManager.getJson("audio.getById", "&audios=" + id)
.get("response");
if (
json.isNull()
|| json.values().isEmpty()
|| json.values().get(0).get("url").isNull()
) {
throw new IllegalStateException("No download url found for track " + id);
}

return new URI(json.values().get(0).get("url").text());
}

@Override
protected AudioTrack makeShallowClone() {
return new VkMusicAudioTrack(this.trackInfo, this.sourceManager);
}

@Override
public AudioSourceManager getSourceManager() {
return this.sourceManager;
}
}
Loading