-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ANDROID_EMBEDDED and ANDROID_MUSIC clients.
- Loading branch information
Showing
8 changed files
with
202 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
common/src/main/java/dev/lavalink/youtube/clients/AndroidEmbedded.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package dev.lavalink.youtube.clients; | ||
|
||
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException; | ||
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException.Severity; | ||
import com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface; | ||
import com.sedmelluq.discord.lavaplayer.track.AudioItem; | ||
import dev.lavalink.youtube.YoutubeAudioSourceManager; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class AndroidEmbedded extends Android { | ||
public static ClientConfig BASE_CONFIG = new ClientConfig() | ||
.withApiKey(Android.BASE_CONFIG.getApiKey()) | ||
.withClientName("ANDROID_EMBEDDED_PLAYER"); | ||
|
||
public AndroidEmbedded() { | ||
this(ClientOptions.DEFAULT); | ||
} | ||
|
||
public AndroidEmbedded(@NotNull ClientOptions options) { | ||
super(options, false); | ||
} | ||
|
||
@Override | ||
@NotNull | ||
protected ClientConfig getBaseClientConfig(@NotNull HttpInterface httpInterface) { | ||
return BASE_CONFIG.copy(); | ||
} | ||
|
||
@Override | ||
@NotNull | ||
public String getIdentifier() { | ||
return BASE_CONFIG.getName(); | ||
} | ||
|
||
@Override | ||
public boolean canHandleRequest(@NotNull String identifier) { | ||
// loose check to avoid loading mixes/playlists. | ||
return !identifier.contains("list=") && super.canHandleRequest(identifier); | ||
} | ||
|
||
@Override | ||
public AudioItem loadMix(@NotNull YoutubeAudioSourceManager source, | ||
@NotNull HttpInterface httpInterface, | ||
@NotNull String mixId, | ||
@Nullable String selectedVideoId) { | ||
// Considered returning null but an exception makes it clearer as to why a mix couldn't be loaded, | ||
// assuming someone tries to only register this client with the source manager. | ||
// Also, an exception will halt further loading so other source managers won't be queried. | ||
// N.B. This client genuinely cannot load mixes for whatever reason. You can get the mix metadata | ||
// but there are no videos in the response JSON. Weird. | ||
throw new FriendlyException("This client cannot load mixes", Severity.COMMON, | ||
new RuntimeException("ANDROID_EMBEDDED cannot be used to load mixes")); | ||
} | ||
|
||
@Override | ||
public AudioItem loadPlaylist(@NotNull YoutubeAudioSourceManager source, | ||
@NotNull HttpInterface httpInterface, | ||
@NotNull String playlistId, | ||
@Nullable String selectedVideoId) { | ||
// Similar to mixes except server returns status code 500 when trying to load playlists. | ||
throw new FriendlyException("This client cannot load playlists", Severity.COMMON, | ||
new RuntimeException("ANDROID_EMBEDDED cannot be used to load playlists")); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
common/src/main/java/dev/lavalink/youtube/clients/AndroidMusic.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package dev.lavalink.youtube.clients; | ||
|
||
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException; | ||
import com.sedmelluq.discord.lavaplayer.tools.FriendlyException.Severity; | ||
import com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface; | ||
import com.sedmelluq.discord.lavaplayer.track.AudioItem; | ||
import dev.lavalink.youtube.YoutubeAudioSourceManager; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class AndroidMusic extends Android { | ||
public static String CLIENT_VERSION = "6.42.52"; | ||
|
||
public static ClientConfig BASE_CONFIG = new ClientConfig() | ||
.withApiKey(Android.BASE_CONFIG.getApiKey()) | ||
.withClientName("ANDROID_MUSIC") | ||
.withClientField("clientVersion", CLIENT_VERSION) | ||
.withUserAgent(String.format("com.google.android.apps.youtube.music/%s (Linux; U; Android %s) gzip", CLIENT_VERSION, ANDROID_VERSION.getOsVersion())); | ||
|
||
public AndroidMusic() { | ||
this(ClientOptions.DEFAULT); | ||
} | ||
|
||
public AndroidMusic(@NotNull ClientOptions options) { | ||
super(options, false); | ||
} | ||
|
||
@Override | ||
@NotNull | ||
protected ClientConfig getBaseClientConfig(@NotNull HttpInterface httpInterface) { | ||
return BASE_CONFIG.copy(); | ||
} | ||
|
||
@Override | ||
@NotNull | ||
public String getIdentifier() { | ||
return BASE_CONFIG.getName(); | ||
} | ||
|
||
@Override | ||
public boolean canHandleRequest(@NotNull String identifier) { | ||
// loose check to avoid loading mixes/playlists. | ||
return !identifier.contains("list=") && super.canHandleRequest(identifier); | ||
} | ||
|
||
@Override | ||
public AudioItem loadMix(@NotNull YoutubeAudioSourceManager source, | ||
@NotNull HttpInterface httpInterface, | ||
@NotNull String mixId, | ||
@Nullable String selectedVideoId) { | ||
// Considered returning null but an exception makes it clearer as to why a mix couldn't be loaded, | ||
// assuming someone tries to only register this client with the source manager. | ||
// Also, an exception will halt further loading so other source managers won't be queried. | ||
// N.B. This client genuinely cannot load mixes for whatever reason. You can get the mix metadata | ||
// but there are no videos in the response JSON. Weird. | ||
throw new FriendlyException("This client cannot load mixes", Severity.COMMON, | ||
new RuntimeException("ANDROID_MUSIC cannot be used to load mixes")); | ||
} | ||
|
||
@Override | ||
public AudioItem loadPlaylist(@NotNull YoutubeAudioSourceManager source, | ||
@NotNull HttpInterface httpInterface, | ||
@NotNull String playlistId, | ||
@Nullable String selectedVideoId) { | ||
// Similar to mixes except server returns status code 500 when trying to load playlists. | ||
throw new FriendlyException("This client cannot load playlists", Severity.COMMON, | ||
new RuntimeException("ANDROID_MUSIC cannot be used to load playlists")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
v2/src/main/java/dev/lavalink/youtube/clients/AndroidEmbeddedWithThumbnail.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package dev.lavalink.youtube.clients; | ||
|
||
import dev.lavalink.youtube.clients.skeleton.NonMusicClientWithThumbnail; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class AndroidEmbeddedWithThumbnail extends AndroidEmbedded implements NonMusicClientWithThumbnail { | ||
public AndroidEmbeddedWithThumbnail() { | ||
super(); | ||
} | ||
|
||
public AndroidEmbeddedWithThumbnail(@NotNull ClientOptions options) { | ||
super(options); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
v2/src/main/java/dev/lavalink/youtube/clients/AndroidMusicWithThumbnail.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package dev.lavalink.youtube.clients; | ||
|
||
import dev.lavalink.youtube.clients.skeleton.NonMusicClientWithThumbnail; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class AndroidMusicWithThumbnail extends AndroidMusic implements NonMusicClientWithThumbnail { | ||
public AndroidMusicWithThumbnail() { | ||
super(); | ||
} | ||
|
||
public AndroidMusicWithThumbnail(@NotNull ClientOptions options) { | ||
super(options); | ||
} | ||
} |