Skip to content

Commit

Permalink
updating yt play feature
Browse files Browse the repository at this point in the history
  • Loading branch information
RichtXO committed Dec 8, 2024
1 parent ca63ec4 commit 51efe14
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 27 deletions.
40 changes: 19 additions & 21 deletions .github/workflows/CICD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,34 @@ on:
- master

jobs:
CI:
runs-on: ubuntu-latest
environment: prod

env:
SPOTIFY_CLIENT_ID: ${{ secrets.SPOTIFY_CLIENT_ID }}
SPOTIFY_SECRET: ${{ secrets.SPOTIFY_SECRET }}

steps:
- uses: actions/checkout@v4

- name: Set up JDK 21
uses: actions/setup-java@v4.2.2
with:
distribution: 'temurin'
java-version: '21'
cache: maven

- name: Run the Maven test
run: mvn test
# CI:
# runs-on: ubuntu-latest
# environment: prod
#
# steps:
# - uses: actions/checkout@v4
#
# - name: Set up JDK 21
# uses: actions/setup-java@v4.2.2
# with:
# distribution: 'temurin'
# java-version: '21'
# cache: maven
#
# - name: Run the Maven test
# run: mvn test

CD:
needs: [CI]
# needs: [CI]
runs-on: self-hosted
environment: prod

env:
TOKEN: ${{ secrets.TOKEN }}
SPOTIFY_CLIENT_ID: ${{ secrets.SPOTIFY_CLIENT_ID }}
SPOTIFY_SECRET: ${{ secrets.SPOTIFY_SECRET }}
YT_TOKEN: ${{ secrets.YT_VISITOR }}
YT_VISITOR: ${{ secrets.YT_TOKEN }}

steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ It's easy to get started via Docker containers! Also need a valid Discord App To
git clone https://github.com/RichtXO/Lil-Mo.git
cd Lil-Mo
```
4. Copy those 3 tokens and generate a new `.env` to hold them!
4. Copy these tokens and generate a new `.env` to hold them!
```sh
TOKEN={discord_token}
SPOTIFY_CLIENT_ID={spotify_client_id}
SPOTIFY_SECRET={spotify_client_secret}
YT_TOKEN={yt_poToken}
YT_VISITOR={yt_visiterData}
```
5. Run Lil Mo!
```sh
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/richtxo/LilMo.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
import com.sedmelluq.discord.lavaplayer.track.playback.NonAllocatingAudioFrameBuffer;
import dev.lavalink.youtube.YoutubeAudioSourceManager;
import dev.lavalink.youtube.clients.Web;
import discord4j.core.DiscordClientBuilder;
import discord4j.core.GatewayDiscordClient;
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent;
Expand All @@ -23,6 +24,7 @@ public class LilMo {
static {
PLAYER_MANAGER = new DefaultAudioPlayerManager();
YoutubeAudioSourceManager ytSourceManager = new YoutubeAudioSourceManager();
Web.setPoTokenAndVisitorData(System.getenv("YT_TOKEN"), System.getenv("YT_VISITOR"));
PLAYER_MANAGER.registerSourceManager(ytSourceManager);
PLAYER_MANAGER.getConfiguration().setFrameBufferFactory(NonAllocatingAudioFrameBuffer::new);

Expand All @@ -40,6 +42,10 @@ public static void main(String[] args){
LOGGER.error("Spotify credentials not set!");
return;
}
if (System.getenv("YT_TOKEN") == null || System.getenv("YT_VISITOR") == null) {
LOGGER.error("YT credentials not set!");
return;
}

final GatewayDiscordClient client = DiscordClientBuilder.create(System.getenv("TOKEN")).build()
.gateway()
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/richtxo/commands/music/Play.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public Mono<Void> handle(ChatInputInteractionEvent event) {
.map(ApplicationCommandInteractionOptionValue::asString).orElse("");
String provider = event.getOption("provider")
.flatMap(ApplicationCommandInteractionOption::getValue)
.map(ApplicationCommandInteractionOptionValue::asString).orElse("scsearch");
.map(ApplicationCommandInteractionOptionValue::asString).orElse("ytmsearch");
Snowflake guildId = event.getInteraction().getGuildId().orElse(Snowflake.of(0));
AudioProvider voice = GuildAudioManager.of(guildId).getProvider();

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/commands/play.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"choices": [
{
"name": "YouTube",
"value": "ytsearch"
"value": "ytmsearch"
},
{
"name": "SoundCloud",
Expand Down
4 changes: 1 addition & 3 deletions src/test/java/com/richtxo/util/spotify/SpotifyFetchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import static org.junit.jupiter.api.Assertions.*;

class SpotifyFetchTest {
final SpotifyFetch fetch = new SpotifyFetch();

@Test
@EnabledIfEnvironmentVariable(named = "SPOTIFY_CLIENT_ID", matches = "*",
disabledReason = "Needs Spotify Client ID to test fetchSong")
@EnabledIfEnvironmentVariable(named = "SPOTIFY_SECRET", matches = "*",
disabledReason = "Needs Spotify Secret to test fetchSong")
void fetchSong() {
final SpotifyFetch fetch = new SpotifyFetch();
final SpotifySong valid =
fetch.fetchSong("https://open.spotify.com/track/4cOdK2wGLETKBW3PvgPWqT?si=8347518e3fd249f5");
assertNotNull(valid);
Expand All @@ -30,7 +30,6 @@ void fetchSong() {
@EnabledIfEnvironmentVariable(named = "SPOTIFY_SECRET", matches = "*",
disabledReason = "Needs Spotify Secret to test fetchPlaylist")
void fetchPlaylist() {
final SpotifyFetch fetch = new SpotifyFetch();
final SpotifyPlaylist valid =
fetch.fetchPlaylist("https://open.spotify.com/playlist/51mPlHVdm7RAqdMACrOaXO?si=9ffd4363a75f4c41");
assertNotNull(valid);
Expand All @@ -47,7 +46,6 @@ void fetchPlaylist() {
@EnabledIfEnvironmentVariable(named = "SPOTIFY_SECRET", matches = "*",
disabledReason = "Needs Spotify Secret to test fetchAlbum")
void fetchAlbum() {
final SpotifyFetch fetch = new SpotifyFetch();
final SpotifyPlaylist valid =
fetch.fetchAlbum("https://open.spotify.com/album/5Z9iiGl2FcIfa3BMiv6OIw?si=QdYDFg5nSDmoi5grrwHH7g");
assertNotNull(valid);
Expand Down

0 comments on commit 51efe14

Please sign in to comment.