Skip to content

Commit 08e2cf5

Browse files
committed
Add plugin module
1 parent 6c7953f commit 08e2cf5

File tree

13 files changed

+413
-34
lines changed

13 files changed

+413
-34
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ replay_pid*
2727
.gradle/*
2828
.idea/*
2929
.DS_Store
30-
*/build/*
30+
*/build/*
31+
build

build.gradle.kts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@ plugins {
33
`maven-publish`
44
}
55

6-
group = "dev.lavalink"
6+
group = "dev.lavalink.youtube"
7+
version = "1.0.0"
78

89
allprojects {
910
group = rootProject.group
11+
version = rootProject.version
1012

1113
repositories {
1214
mavenLocal()
1315
mavenCentral()
1416
maven(url = "https://maven.lavalink.dev/releases")
15-
maven(url = "https://m2.dv8tion.net/releases")
1617
maven(url = "https://jitpack.io")
1718
}
1819

common/build.gradle.kts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,8 @@ plugins {
44
}
55

66
val moduleName = "common"
7-
version = "1.0.0"
87

98
dependencies {
109
compileOnly("dev.arbjerg:lavaplayer:1.5.3")
1110
}
1211

13-
val sourcesJar by tasks.registering(Jar::class) {
14-
archiveClassifier.set("sources")
15-
from(sourceSets["common"].allSource)
16-
}
17-
18-
publishing {
19-
publications {
20-
create<MavenPublication>("mavenJava") {
21-
from(components["java"])
22-
artifactId = moduleName
23-
artifact(sourcesJar)
24-
}
25-
}
26-
}

lldevs/build.gradle.kts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,8 @@ plugins {
44
}
55

66
val moduleName = "lldevs"
7-
version = "1.0.0"
87

98
dependencies {
109
compileOnly(project(":common"))
1110
compileOnly("dev.arbjerg:lavaplayer:2.1.1")
1211
}
13-
14-
val sourcesJar by tasks.registering(Jar::class) {
15-
archiveClassifier.set("sources")
16-
from(sourceSets["main"].allSource)
17-
}
18-
19-
publishing {
20-
publications {
21-
create<MavenPublication>("mavenJava") {
22-
from(components["java"])
23-
artifactId = moduleName
24-
artifact(sourcesJar)
25-
}
26-
}
27-
}

plugin/build.gradle.kts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
plugins {
2+
`java-library`
3+
`maven-publish`
4+
}
5+
6+
val moduleName = "plugin"
7+
8+
dependencies {
9+
compileOnly("dev.arbjerg.lavalink:plugin-api:3.7.11")
10+
compileOnly("dev.arbjerg:lavaplayer-ext-youtube-rotator:1.5.3")
11+
compileOnly(project(":common"))
12+
compileOnly(project(":lldevs"))
13+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package dev.lavalink.youtube.plugin;
2+
3+
import dev.lavalink.youtube.clients.skeleton.Client;
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
6+
7+
import java.util.ArrayList;
8+
import java.util.Arrays;
9+
import java.util.List;
10+
11+
public interface ClientProvider {
12+
Logger log = LoggerFactory.getLogger(ClientProvider.class);
13+
14+
Client[] getClients(String[] clients);
15+
16+
default Client[] getClients(ClientReference[] clientValues, String[] clients) {
17+
List<Client> resolved = new ArrayList<>();
18+
19+
for (String clientName : clients) {
20+
Client client = getClientByName(clientValues, clientName);
21+
22+
if (client == null) {
23+
log.warn("Failed to resolve {} into a Client", clientName);
24+
continue;
25+
}
26+
27+
resolved.add(client);
28+
}
29+
30+
return resolved.toArray(new Client[0]);
31+
}
32+
33+
interface ClientReference {
34+
String getName();
35+
Client getClient();
36+
}
37+
38+
static Client getClientByName(ClientReference[] enumValues, String name) {
39+
return Arrays.stream(enumValues)
40+
.filter(it -> it.getName().equals(name))
41+
.findFirst()
42+
.map(ClientReference::getClient)
43+
.orElse(null);
44+
}
45+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package dev.lavalink.youtube.plugin;
2+
3+
import dev.lavalink.youtube.clients.*;
4+
import dev.lavalink.youtube.clients.skeleton.Client;
5+
6+
import java.util.function.Supplier;
7+
8+
public class ClientProviderV3 implements ClientProvider {
9+
@Override
10+
public Client[] getClients(String[] clients) {
11+
return getClients(ClientMapping.values(), clients);
12+
}
13+
14+
private enum ClientMapping implements ClientReference {
15+
ANDROID(Android::new),
16+
ANDROID_TESTSUITE(AndroidTestsuite::new),
17+
IOS(Ios::new),
18+
MUSIC(Music::new),
19+
TVHTML5EMBEDDED(TvHtml5Embedded::new),
20+
WEB(Web::new);
21+
22+
private final Supplier<Client> clientFactory;
23+
24+
ClientMapping(Supplier<Client> clientFactory) {
25+
this.clientFactory = clientFactory;
26+
}
27+
28+
@Override
29+
public String getName() {
30+
return name();
31+
}
32+
33+
@Override
34+
public Client getClient() {
35+
return clientFactory.get();
36+
}
37+
}
38+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package dev.lavalink.youtube.plugin;
2+
3+
import dev.lavalink.youtube.clients.*;
4+
import dev.lavalink.youtube.clients.skeleton.Client;
5+
6+
import java.util.function.Supplier;
7+
8+
public class ClientProviderV4 implements ClientProvider {
9+
@Override
10+
public Client[] getClients(String[] clients) {
11+
return getClients(ClientMapping.values(), clients);
12+
}
13+
14+
private enum ClientMapping implements ClientReference {
15+
ANDROID(AndroidWithThumbnail::new),
16+
ANDROID_TESTSUITE(AndroidTestsuiteWithThumbnail::new),
17+
IOS(IosWithThumbnail::new),
18+
MUSIC(MusicWithThumbnail::new),
19+
TVHTML5EMBEDDED(TvHtml5EmbeddedWithThumbnail::new),
20+
WEB(WebWithThumbnail::new);
21+
22+
private final Supplier<Client> clientFactory;
23+
24+
ClientMapping(Supplier<Client> clientFactory) {
25+
this.clientFactory = clientFactory;
26+
}
27+
28+
@Override
29+
public String getName() {
30+
return name();
31+
}
32+
33+
@Override
34+
public Client getClient() {
35+
return clientFactory.get();
36+
}
37+
}
38+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package dev.lavalink.youtube.plugin;
2+
3+
import org.springframework.boot.context.properties.ConfigurationProperties;
4+
import org.springframework.stereotype.Component;
5+
6+
import java.util.Collections;
7+
import java.util.List;
8+
9+
@ConfigurationProperties(prefix = "lavalink.server.ratelimit")
10+
@Component
11+
public class RatelimitConfig {
12+
private List<String> ipBlocks = Collections.emptyList();
13+
private List<String> excludedIps = Collections.emptyList();
14+
private String strategy = "RotatingNanoSwitch";
15+
private int retryLimit = -1;
16+
private boolean searchTriggersFail = true;
17+
18+
public List<String> getIpBlocks() {
19+
return this.ipBlocks;
20+
}
21+
22+
public List<String> getExcludedIps() {
23+
return this.excludedIps;
24+
}
25+
26+
public String getStrategy() {
27+
return this.strategy;
28+
}
29+
30+
public int getRetryLimit() {
31+
return this.retryLimit;
32+
}
33+
34+
public boolean getSearchTriggersFail() {
35+
return this.searchTriggersFail;
36+
}
37+
38+
public void setIpBlocks(List<String> ipBlocks) {
39+
this.ipBlocks = ipBlocks;
40+
}
41+
42+
public void setExcludedIps(List<String> excludedIps) {
43+
this.excludedIps = excludedIps;
44+
}
45+
46+
public void setStrategy(String strategy) {
47+
this.strategy = strategy;
48+
}
49+
50+
public void setRetryLimit(int retryLimit) {
51+
this.retryLimit = retryLimit;
52+
}
53+
54+
public void setSearchTriggersFail(boolean searchTriggersFail) {
55+
this.searchTriggersFail = searchTriggersFail;
56+
}
57+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package dev.lavalink.youtube.plugin;
2+
3+
import org.springframework.boot.context.properties.ConfigurationProperties;
4+
import org.springframework.stereotype.Component;
5+
6+
@ConfigurationProperties(prefix = "lavalink.server.ratelimit")
7+
@Component
8+
public class ServerConfig {
9+
private int youtubePlaylistLoadLimit = 6;
10+
11+
public int getYoutubePlaylistLoadLimit() {
12+
return this.youtubePlaylistLoadLimit;
13+
}
14+
15+
public void setYoutubePlaylistLoadLimit(int youtubePlaylistLoadLimit) {
16+
this.youtubePlaylistLoadLimit = youtubePlaylistLoadLimit;
17+
}
18+
}

0 commit comments

Comments
 (0)