Skip to content

Commit 06b7cab

Browse files
infniborNansesstopi314
authored
Add Tidal source (#256)
Co-authored-by: Nansess <[email protected]> Co-authored-by: topi314 <[email protected]>
1 parent c0f51c2 commit 06b7cab

File tree

9 files changed

+499
-63
lines changed

9 files changed

+499
-63
lines changed

README.md

Lines changed: 96 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# LavaSrc
44

55
> [!IMPORTANT]
6-
> For LavaSrc v3 (Lavaplayer v1 & Lavalink v3) look [here](https://github.com/topi314/LavaSrc/tree/v3-legacy)
6+
> For LavaSrc v3 (Lavaplayer v1 & Lavalink v3) look [here](https://github.com/topi314/LavaSrc/tree/v3-legacy)
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)
@@ -13,9 +13,10 @@ A collection of additional [Lavaplayer v2](https://github.com/sedmelluq/lavaplay
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)
1515
* [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)
16+
* [Tidal](https://tidal.com) playlists/albums/songs/search results (Thx to [Nansess](https://github.com/Nansess) and [InfNibor](https://github.com/infnibor) for implementing it)
1617

1718
> [!IMPORTANT]
18-
> Tracks from Spotify & Apple Music don't actually play from their sources, but are instead resolved via the configured providers
19+
> Tracks from Spotify & Apple Music & Tidal don't actually play from their sources, but are instead resolved via the configured providers
1920
2021
## Summary
2122

@@ -62,6 +63,8 @@ To get your Yandex Music access token go [here](#yandex-music)
6263

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

66+
To get your Tidal token go [here](#tidal)
67+
6568
> [!WARNING]
6669
> YES `plugins` IS AT ROOT IN THE YAML
6770

@@ -82,6 +85,7 @@ plugins:
8285
flowerytts: false # Enable Flowery TTS source
8386
youtube: false # Enable YouTube search source (https://github.com/topi314/LavaSearch)
8487
vkmusic: false # Enable Vk Music source
88+
tidal: false # Enable Tidal source
8589
lyrics-sources:
8690
spotify: false # Enable Spotify lyrics source
8791
deezer: false # Enable Deezer lyrics source
@@ -131,6 +135,10 @@ plugins:
131135
playlistLoadLimit: 1 # The number of pages at 50 tracks each
132136
artistLoadLimit: 1 # The number of pages at 10 tracks each
133137
recommendationsLoadLimit: 10 # Number of tracks
138+
tidal:
139+
countryCode: "US" # the country code for accessing region-specific content on Tidal (ISO 3166-1 alpha-2).
140+
searchLimit: 6 # How many search results should be returned
141+
token: "your tidal token" # the token used for accessing the tidal api. See https://github.com/topi314/LavaSrc#tidal
134142
```
135143
136144
### Plugin Info
@@ -153,21 +161,21 @@ LavaSrc adds the following fields to tracks & playlists in Lavalink
153161
154162
```json
155163
{
156-
"encoded": "...",
157-
"info": {
158-
...
159-
},
160-
"pluginInfo": {
161-
"albumName": "...",
162-
"albumArtUrl": "...",
163-
"artistUrl": "...",
164-
"artistArtworkUrl": "...",
165-
"previewUrl": "...",
166-
"isPreview": false
167-
},
168-
"userData": {
169-
...
170-
}
164+
"encoded": "...",
165+
"info": {
166+
...
167+
},
168+
"pluginInfo": {
169+
"albumName": "...",
170+
"albumArtUrl": "...",
171+
"artistUrl": "...",
172+
"artistArtworkUrl": "...",
173+
"previewUrl": "...",
174+
"isPreview": false
175+
},
176+
"userData": {
177+
...
178+
}
171179
}
172180
```
173181

@@ -188,19 +196,19 @@ LavaSrc adds the following fields to tracks & playlists in Lavalink
188196

189197
```json
190198
{
191-
"info": {
192-
...
193-
},
194-
"pluginInfo": {
195-
"type": "playlist",
196-
"url": "...",
197-
"artworkUrl": "...",
198-
"author": "...",
199-
"totalTracks": 10
200-
},
201-
"tracks": [
202-
...
203-
]
199+
"info": {
200+
...
201+
},
202+
"pluginInfo": {
203+
"type": "playlist",
204+
"url": "...",
205+
"artworkUrl": "...",
206+
"author": "...",
207+
"totalTracks": 10
208+
},
209+
"tracks": [
210+
...
211+
]
204212
}
205213
```
206214

@@ -288,39 +296,38 @@ PATCH /v4/lavasrc/config
288296

289297
```json
290298
{
291-
"spotify": {
292-
"clientId": "your client id",
293-
"clientSecret": "your client secret",
294-
"spDc": "your sp dc cookie"
295-
},
296-
"applemusic": {
297-
"mediaAPIToken": "your apple music api token"
298-
},
299-
"deezer": {
300-
"arl": "your deezer arl",
301-
"formats": [
302-
"FLAC",
303-
"MP3_320",
304-
"MP3_256",
305-
"MP3_128",
306-
"MP3_64",
307-
"AAC_64"
308-
]
309-
},
310-
"yandexMusic": {
311-
"accessToken": "your access token"
312-
},
313-
"vkMusic": {
314-
"userToken": "your user token"
315-
}
299+
"spotify": {
300+
"clientId": "your client id",
301+
"clientSecret": "your client secret",
302+
"spDc": "your sp dc cookie"
303+
},
304+
"applemusic": {
305+
"mediaAPIToken": "your apple music api token"
306+
},
307+
"deezer": {
308+
"arl": "your deezer arl",
309+
"formats": [
310+
"FLAC",
311+
"MP3_320",
312+
"MP3_256",
313+
"MP3_128",
314+
"MP3_64",
315+
"AAC_64"
316+
]
317+
},
318+
"yandexMusic": {
319+
"accessToken": "your access token"
320+
},
321+
"vkMusic": {
322+
"userToken": "your user token"
323+
}
316324
}
317325
```
318326

319327
</details>
320328

321329
---
322330

323-
324331
## Lavaplayer Usage
325332

326333
Replace `x.y.z` with the latest version number
@@ -368,9 +375,9 @@ dependencies {
368375
<version>x.y.z</version>
369376
</dependency>
370377
<dependency>
371-
<groupId>com.github.topi314.lavasrc</groupId>
372-
<artifactId>lavasrc-protocol-jvm</artifactId>
373-
<version>x.y.z</version>
378+
<groupId>com.github.topi314.lavasrc</groupId>
379+
<artifactId>lavasrc-protocol-jvm</artifactId>
380+
<version>x.y.z</version>
374381
</dependency>
375382
</dependencies>
376383
```
@@ -452,7 +459,7 @@ follow [this guide](https://developer.apple.com/help/account/configure-app-capab
452459
AudioPlayerManager playerManager = new DefaultAudioPlayerManager();
453460

454461
// create a new AppleMusicSourceManager with the standard providers, apple music api token, countrycode and AudioPlayerManager and register it
455-
var appleMusic = new AppleMusicSourceManager(null, mediaAPIToken , "us", playerManager);
462+
var appleMusic = new AppleMusicSourceManager(null, mediaAPIToken, "us", playerManager);
456463
playerManager.registerSourceManager(appleMusic);
457464
```
458465

@@ -468,6 +475,7 @@ var searchManager = new SearchManager();
468475
// register source
469476
searchManager.registerSearchManager(appleMusic);
470477
```
478+
471479
</details>
472480

473481
---
@@ -537,7 +545,7 @@ searchManager.registerSearchManager(deezer);
537545
1. (Optional) Open DevTools in your browser and on the Network tab enable trotlining.
538546
2. Go to https://oauth.yandex.ru/authorize?response_type=token&client_id=23cabbbdc6cd418abb4b39c32c41195d
539547
3. Authorize and grant access
540-
4. The browser will redirect to the address like `https://music.yandex.ru/#access_token=AQAAAAAYc***&token_type=bearer&expires_in=31535645`.
548+
4. The browser will redirect to the address like `https://music.yandex.ru/#access_token=AQAAAAAYc***&token_type=bearer&expires_in=31535645`.
541549
Very quickly there will be a redirect to another page, so you need to have time to copy the link. ![image](https://user-images.githubusercontent.com/68972811/196124196-a817b828-3387-4f70-a2b2-cdfdc71ce1f2.png)
542550
5. Your accessToken, what is after `access_token`.
543551

@@ -673,6 +681,24 @@ searchManager.registerSearchManager(vkmusic);
673681

674682
---
675683

684+
### Tidal
685+
686+
<details>
687+
<summary>How to get tidal token</summary>
688+
689+
Use Google to get the tidal token.
690+
691+
</details>
692+
693+
```java
694+
AudioPlayerManager playerManager = new DefaultAudioPlayerManager();
695+
696+
// create a new TidalSourceManager with the token and register it
697+
var tidal = new TidalSourceManager(countryCode, () -> playerManager, new DefaultMirroringAudioTrackResolver(providers), "your tidal token");
698+
699+
playerManager.registerSourceManager(tidal);
700+
```
701+
676702
## Supported URLs and Queries
677703

678704
### Spotify
@@ -740,4 +766,13 @@ You can read about all the available options [here](https://flowery.pw/docs), a
740766
* https://vk.com/audios700949584?q=phonk%20album&z=audio_playlist-2000933493_13933493%2Fbe3494d46d310b0d0d
741767
* https://vk.ru/audios700949584?q=phonk%20album&z=audio_playlist-2000933493_13933493
742768

769+
### Tidal
770+
771+
* `tdsearch:animals architects`
772+
* `tdrec:12345678` (`tdrec:{TRACK_ID}`)
773+
* https://tidal.com/browse/track/12345678
774+
* https://tidal.com/browse/album/12345678
775+
* https://tidal.com/browse/playlist/12345678
776+
* https://tidal.com/browse/artist/12345678
777+
743778
---

application.example.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ plugins:
2020
youtube: false # Enable YouTube lyrics source
2121
yandexmusic: false # Enable Yandex Music lyrics source
2222
vkmusic: false # Enable Vk Music lyrics source
23+
tidal: false # Enable Tidal source
2324
spotify:
2425
clientId: "your client id"
2526
clientSecret: "your client secret"
@@ -55,6 +56,10 @@ plugins:
5556
playlistLoadLimit: 1 # The number of pages at 50 tracks each
5657
artistLoadLimit: 1 # The number of pages at 10 tracks each
5758
recommendationsLoadLimit: 10 # Number of tracks
59+
tidal:
60+
countryCode: "US" # the country code for accessing region-specific content on Tidal (ISO 3166-1 alpha-2).
61+
searchLimit: 6 # How many search results should be returned
62+
token: "your tidal token" # the token used for accessing the tidal api. See https://github.com/topi314/LavaSrc#tidal
5863

5964
server: # REST and WS server
6065
port: 2333

main/src/main/java/com/github/topi314/lavasrc/mirror/MirroringAudioTrack.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public MirroringAudioTrack(AudioTrackInfo trackInfo, String albumName, String al
2525
this.sourceManager = sourceManager;
2626
}
2727

28-
abstract protected InternalAudioTrack createAudioTrack(AudioTrackInfo trackInfo, SeekableInputStream inputStream);
28+
protected abstract InternalAudioTrack createAudioTrack(AudioTrackInfo trackInfo, SeekableInputStream inputStream);
2929

3030
@Override
3131
public void process(LocalAudioTrackExecutor executor) throws Exception {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.github.topi314.lavasrc.tidal;
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 TidalAudioPlaylist extends ExtendedAudioPlaylist {
9+
public TidalAudioPlaylist(String name, List<AudioTrack> tracks, ExtendedAudioPlaylist.Type type, String url, String artworkURL, String author, Integer totalTracks) {
10+
super(name, tracks, type, url, artworkURL, author, totalTracks);
11+
}
12+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.github.topi314.lavasrc.tidal;
2+
3+
import com.github.topi314.lavasrc.mirror.MirroringAudioTrack;
4+
import com.sedmelluq.discord.lavaplayer.tools.io.SeekableInputStream;
5+
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
6+
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
7+
import com.sedmelluq.discord.lavaplayer.track.InternalAudioTrack;
8+
9+
public class TidalAudioTrack extends MirroringAudioTrack {
10+
11+
public TidalAudioTrack(AudioTrackInfo trackInfo, TidalSourceManager sourceManager) {
12+
this(trackInfo, null, null, null, null, sourceManager);
13+
}
14+
15+
public TidalAudioTrack(AudioTrackInfo trackInfo, String albumName, String albumUrl, String artistUrl, String artistArtworkUrl, TidalSourceManager sourceManager) {
16+
super(trackInfo, albumName, albumUrl, artistUrl, artistArtworkUrl, null, false, sourceManager);
17+
}
18+
19+
@Override
20+
protected InternalAudioTrack createAudioTrack(AudioTrackInfo trackInfo, SeekableInputStream stream) {
21+
throw new UnsupportedOperationException("Previews are not supported by Tidal");
22+
}
23+
24+
@Override
25+
protected AudioTrack makeShallowClone() {
26+
return new TidalAudioTrack(this.trackInfo, (TidalSourceManager) this.sourceManager);
27+
}
28+
}

0 commit comments

Comments
 (0)