Skip to content
This repository has been archived by the owner on Apr 20, 2021. It is now read-only.

added initial code for api wrapper #31

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
18 changes: 1 addition & 17 deletions src/main/java/com/disbots/commands/music/Play.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.disbots.util.logging.Log;
import com.disbots.util.logging.LogTypes;
import com.disbots.util.music.LavaPlayerAudioSource;
import com.google.api.services.youtube.YouTube;
import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
Expand Down Expand Up @@ -36,23 +37,6 @@ public void OnPlayCommand(MessageCreateEvent message, String[] args)

try
{
/*
TODO: Enable youtube api.

YouTube youtubeService = getService();
// Define and execute the API request
YouTube.Search.List request = youtubeService.search()
.list("snippet");
SearchListResponse response = request.setMaxResults(1L).setKey(DEVELOPER_KEY)
.setOrder("viewCount")
.setQ(args[0])
.execute();

JSONObject httpResponse = new JSONObject(response);

System.out.println(httpResponse.get("videoId"));
*/

voiceChannel = message.getMessageAuthor().getConnectedVoiceChannel().get();

EmbedBuilder LoadingEmbed = new EmbedBuilder()
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/disbots/core/api/IRequests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.disbots.core.api;

import com.google.api.services.youtube.model.SearchListResponse;

import java.io.IOException;
import java.security.GeneralSecurityException;

/**
* @apiNote Interface, that contains all requests to
* youtube api.
*/
public interface IRequests
{
SearchListResponse SearchVideoByQuery(Long MaxResults, String setOrder, String Query) throws GeneralSecurityException, IOException;
}
28 changes: 28 additions & 0 deletions src/main/java/com/disbots/core/api/YoutubeApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.disbots.core.api;

import com.disbots.core.Main;
import com.google.api.services.youtube.YouTube;
import com.google.api.services.youtube.model.SearchListResponse;

import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Collections;

import static com.disbots.core.api.YoutubeApiService.getService;

public class YoutubeApi implements IRequests
{
@Override
public SearchListResponse SearchVideoByQuery(Long MaxResults, String Order, String Query) throws GeneralSecurityException, IOException
{
YouTube youtubeService = getService();
YouTube.Search.List request = youtubeService.search()
.list(Collections.singletonList("snippet"));
SearchListResponse response = request.setMaxResults(MaxResults).setKey(Main.DEVELOPER_KEY)
.setOrder(Order)
.setQ(Query)
.execute();

return response;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.disbots.core;
package com.disbots.core.api;

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
Expand Down
1 change: 1 addition & 0 deletions src/test/java/com/disbots/core/YoutubeApiServiceTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.disbots.core;

import com.disbots.core.api.YoutubeApiService;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

Expand Down