Skip to content
This repository has been archived by the owner on Nov 26, 2023. It is now read-only.

Commit

Permalink
It compiles now
Browse files Browse the repository at this point in the history
  • Loading branch information
duncte123 committed Jan 3, 2020
1 parent d1aa852 commit ba012ae
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 1,071 deletions.
11 changes: 1 addition & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,19 @@ version = "1.0-SNAPSHOT"
repositories {
jcenter()

maven {
url = uri("https://maven.notfab.net/Hosted")
}

maven {
url = uri("https://jitpack.io")
}
}

dependencies {
api(group = "com.github.duncte123", name = "lavaplayer", version = "1dff250")
api(group = "net.notfab.cache", name = "cache-client", version = "2.2")
api(group = "io.sentry", name = "sentry-logback", version = "1.7.17")
api(group = "com.google.apis", name = "google-api-services-youtube", version = "v3-rev212-1.25.0")
api(group = "me.duncte123", name = "botCommons", version = "1.0.65")


implementation(group = "se.michaelthelin.spotify", name = "spotify-web-api-java", version = "4.2.1")
}

configure<JavaPluginConvention> {
sourceCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_11
}

tasks.withType<Wrapper> {
Expand Down
31 changes: 8 additions & 23 deletions src/main/java/com/dunctebot/sourcemanagers/DuncteBotSources.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,23 @@
import com.dunctebot.sourcemanagers.extra.YoutubeContextFilterOverride;
import com.dunctebot.sourcemanagers.pornhub.PornHubAudioSourceManager;
import com.dunctebot.sourcemanagers.speech.SpeechAudioSourceManager;
import com.dunctebot.sourcemanagers.spotify.SpotifyAudioSourceManager;
import com.dunctebot.sourcemanagers.youtube.YoutubeAudioSourceManagerOverride;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
import net.notfab.caching.client.CacheClient;
import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager;

public class DuncteBotSources {
public static void registerCustom(AudioPlayerManager playerManager, String speechLanguage,
int playlistPageCount, boolean updateYoutubeData,
String youtubeApiKey, CacheClient cacheClient,
String spotifyClientId, String spotifyClientSecret, int playlistLimit) {
int playlistPageCount, boolean updateYoutubeData) {

final YoutubeAudioSourceManagerOverride youtubeAudioSourceManager = new YoutubeAudioSourceManagerOverride(
cacheClient,
youtubeApiKey
);
final YoutubeAudioSourceManager youtubeSource = playerManager.source(YoutubeAudioSourceManager.class);
youtubeSource.setPlaylistPageCount(playlistPageCount);
youtubeSource.getMainHttpConfiguration()
.setHttpContextFilter(
new YoutubeContextFilterOverride(updateYoutubeData, youtubeSource.getHttpInterface())
);

youtubeAudioSourceManager.setPlaylistPageCount(playlistPageCount);
youtubeAudioSourceManager.getMainHttpConfiguration().setHttpContextFilter(new YoutubeContextFilterOverride(updateYoutubeData));

playerManager.registerSourceManager(
new SpotifyAudioSourceManager(
youtubeAudioSourceManager,
spotifyClientId,
spotifyClientSecret,
youtubeApiKey,
playlistLimit
)
);
playerManager.registerSourceManager(new ClypitAudioSourceManager());
playerManager.registerSourceManager(new SpeechAudioSourceManager(speechLanguage));
playerManager.registerSourceManager(new PornHubAudioSourceManager());
playerManager.registerSourceManager(youtubeAudioSourceManager);

}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,40 @@
package com.dunctebot.sourcemanagers.extra;

import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeHttpContextFilter;
import com.sedmelluq.discord.lavaplayer.tools.DataFormatTools;
import com.sedmelluq.discord.lavaplayer.tools.JsonBrowser;
import com.sedmelluq.discord.lavaplayer.tools.io.HttpInterface;
import io.sentry.Sentry;
import org.apache.commons.io.IOUtils;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.protocol.HttpClientContext;

import java.io.Closeable;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import static com.dunctebot.sourcemanagers.extra.YoutubeUtils.getYoutubeHeaderDetails;

public class YoutubeContextFilterOverride extends YoutubeHttpContextFilter implements Closeable {
private YoutubeVersionData youtubeVersionData = null;
private final HttpInterface httpInterface;
private final ScheduledExecutorService dataUpdateThread = Executors.newSingleThreadScheduledExecutor((r) -> {
final Thread t = new Thread();
t.setName("YouTube-data-updater");
t.setDaemon(true);
return t;
});

public YoutubeContextFilterOverride() {
this(true);
public YoutubeContextFilterOverride(HttpInterface httpInterface) {
this(true, httpInterface);
}

public YoutubeContextFilterOverride(boolean shouldUpdate) {
public YoutubeContextFilterOverride(boolean shouldUpdate, HttpInterface httpInterface) {
this.httpInterface = httpInterface;

if (shouldUpdate) {
dataUpdateThread.scheduleAtFixedRate(this::updateYoutubeData, 0L, 1L, TimeUnit.DAYS);
}
Expand All @@ -56,6 +64,22 @@ private void updateYoutubeData() {
}
}

private YoutubeVersionData getYoutubeHeaderDetails() throws IOException {
final HttpGet httpGet = new HttpGet("https://www.youtube.com/");
httpGet.setHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36");

try (final CloseableHttpResponse response = this.httpInterface.execute(httpGet)) {
final String html = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);

final String extracted = DataFormatTools.extractBetween(html,
"window.ytplayer = {};ytcfg.set(",
");ytcfg.set(");
final JsonBrowser json = JsonBrowser.parse(extracted);

return YoutubeVersionData.fromBrowser(json);
}
}

@Override
public void onRequest(HttpClientContext context, HttpUriRequest request, boolean isRepetition) {
super.onRequest(context, request, isRepetition);
Expand All @@ -71,7 +95,7 @@ public void onRequest(HttpClientContext context, HttpUriRequest request, boolean
}

@Override
public void close() throws IOException {
public void close() {
dataUpdateThread.shutdown();
}
}

This file was deleted.

Loading

0 comments on commit ba012ae

Please sign in to comment.