diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..430b5d7 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,80 @@ +name: Publish +on: + push: + release: + types: [ published ] +jobs: + build: + runs-on: ubuntu-latest + env: + MAVEN_USERNAME: ${{ vars.MAVEN_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Setup Java + uses: actions/setup-java@v3 + with: + distribution: zulu + java-version: 17 + cache: gradle + + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 + + - name: Build and Publish + run: ./gradlew build publish --no-daemon -PMAVEN_USERNAME=$MAVEN_USERNAME -PMAVEN_PASSWORD=$MAVEN_PASSWORD + + - name: Upload common Artifact + uses: actions/upload-artifact@v3 + with: + name: youtube-common.jar + path: common/build/libs/youtube-common-*.jar + + - name: Upload lldevs Artifact + uses: actions/upload-artifact@v3 + with: + name: youtube-v2.jar + path: v2/build/libs/youtube-v2-*.jar + + - name: Upload plugin Artifact + uses: actions/upload-artifact@v3 + with: + name: youtube-plugin.jar + path: plugin/build/libs/youtube-plugin-*.jar + + release: + needs: build + runs-on: ubuntu-latest + if: github.event_name == 'release' + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Download youtube-common Artifact + uses: actions/download-artifact@v3 + with: + name: youtube-common.jar + + - name: Download youtube-v2 Artifact + uses: actions/download-artifact@v3 + with: + name: youtube-v2.jar + + - name: Download youtube-plugin Artifact + uses: actions/download-artifact@v3 + with: + name: youtube-plugin.jar + + - name: Upload Artifacts to GitHub Release + uses: ncipollo/release-action@v1 + with: + artifacts: '*.jar' + allowUpdates: true + omitBodyDuringUpdate: true + omitDraftDuringUpdate: true + omitNameDuringUpdate: true + omitPrereleaseDuringUpdate: true \ No newline at end of file diff --git a/README.md b/README.md index 2f3e773..ea1a430 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,22 @@ Which clients are used is entirely configurable. This module provides the base source manager, which can be used with any `com.sedmelluq.discord.lavaplayer` packages still on major version `1`. +
+Using in Gradle: + +```kotlin +repositories { + // replace with https://maven.lavalink.dev/snapshots if you want to use a snapshot version. + maven(url = "https://maven.lavalink.dev/releases") +} + +dependencies { + // Replace VERSION with the current version as shown by the Releases tab or a long commit hash `-SNAPSHOT` for snapshots. + implementation("dev.lavalink.youtube:common:VERSION") +} +``` + +
Example usage: ```java YoutubeAudioSourceManager youtube = new YoutubeAudioSourceManager(); @@ -30,13 +46,30 @@ rotator.forConfiguration(youtube.getHttpInterfaceManager(), false) .setup(); ``` -## lldevs +## v2 This modules expands on `common` by providing additional support for Lavaplayer `2.x` clients, such as [Lavalink-Devs/Lavaplayer](https://github.com/lavalink-devs/lavaplayer). Such features currently include thumbnail support within `AudioTrackInfo`. Additional clients are included that provide access to this additional information. These clients are suffixed with `Thumbnail`, such as `WebWithThumbnail`, `AndroidWithThumbnail` etc. +
+Using in Gradle: + +```kotlin +repositories { + // replace with https://maven.lavalink.dev/snapshots if you want to use a snapshot version. + maven(url = "https://maven.lavalink.dev/releases") +} + +dependencies { + // Replace VERSION with the current version as shown by the Releases tab or a long commit hash `-SNAPSHOT` for snapshots. + implementation("dev.lavalink.youtube:v2:VERSION") +} +``` + +
+ Example usage: ```java // same as the 'common' module but there are additional clients that provide video thumbnails in the returned metadata. @@ -44,18 +77,36 @@ YoutubeAudioSourceManager youtube = new YoutubeAudioSourceManager(/*allowSearch: ``` ## plugin -This module serves as the plugin for use with [Lavalink](https://github.com/lavalink-devs/lavalink). +This module serves as the plugin for use with [Lavalink](https://github.com/lavalink-devs/Lavalink). To use this plugin with Lavalink, you must declare the dependency. + +
+Using with Lavalink v3: + ```yaml lavalink: - # ... plugins: - # replace VERSION with the current version as shown by the Releases tab. - - dependency: "com.github.lavalink-devs.lavaplayer-youtube-source:plugin:VERSION" - repository: "https://jitpack.io" + # Replace VERSION with the current version as shown by the Releases tab or a long commit hash for snapshots. + - dependency: "dev.lavalink.youtube:youtube-plugin:VERSION" + repository: "https://maven.lavalink.dev/releases" # use https://maven.lavalink.dev/snapshots if you want to use a snapshot version. ``` +
+ +
+Using with Lavalink v4: + +```yaml +lavalink: + plugins: + # Replace VERSION with the current version as shown by the Releases tab or a long commit hash for snapshots. + - dependency: "dev.lavalink.youtube:youtube-plugin:VERSION" + snapshot: false # Set to true if you want to use a snapshot version. +``` + +
+ Configuring the plugin: ```yaml plugins: diff --git a/build.gradle.kts b/build.gradle.kts index dd10271..ed58513 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,14 +1,23 @@ +import org.ajoberstar.grgit.Grgit + plugins { java - `maven-publish` + id("org.ajoberstar.grgit") version "5.2.0" + alias(libs.plugins.maven.publish.base) apply false } -group = "dev.lavalink.youtube" -version = "1.0.7" +val (gitVersion, release) = versionFromGit() +logger.lifecycle("Version: $gitVersion (release: $release)") allprojects { - group = rootProject.group - version = rootProject.version + group = "dev.lavalink.youtube" + // The plugin project is the only one that should not have a snapshot version since lavalink expects the jar name to be specific + version = if (project.name == "plugin") { + gitVersion.removeSuffix("-SNAPSHOT") + } else { + gitVersion + } + repositories { mavenLocal() @@ -16,19 +25,48 @@ allprojects { maven(url = "https://maven.lavalink.dev/releases") maven(url = "https://jitpack.io") } +} - apply(plugin = "java") - apply(plugin = "maven-publish") +subprojects { + apply() + apply() - java { + configure { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } - dependencies { - implementation("org.mozilla:rhino-engine:1.7.14") - implementation("com.grack:nanojson:1.7") - compileOnly("org.slf4j:slf4j-api:1.7.25") - compileOnly("org.jetbrains:annotations:24.1.0") + configure { + if (findProperty("MAVEN_PASSWORD") != null && findProperty("MAVEN_USERNAME") != null) { + repositories { + val snapshots = "https://maven.lavalink.dev/snapshots" + val releases = "https://maven.lavalink.dev/releases" + + maven(if (release) releases else snapshots) { + credentials { + password = findProperty("MAVEN_PASSWORD") as String? + username = findProperty("MAVEN_USERNAME") as String? + } + } + } + } else { + logger.lifecycle("Not publishing to maven.lavalink.dev because credentials are not set") + } + } +} + +@SuppressWarnings("GrMethodMayBeStatic") +fun versionFromGit(): Pair { + Grgit.open(mapOf("currentDir" to project.rootDir)).use { git -> + val headTag = git.tag + .list() + .find { it.commit.id == git.head().id } + + val clean = git.status().isClean || System.getenv("CI") != null + if (!clean) { + logger.lifecycle("Git state is dirty, version is a snapshot.") + } + + return if (headTag != null && clean) headTag.name to true else "${git.head().id}-SNAPSHOT" to false } } \ No newline at end of file diff --git a/common/build.gradle.kts b/common/build.gradle.kts index f7ced4e..4e0a0c6 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -1,25 +1,24 @@ +import com.vanniktech.maven.publish.JavaLibrary +import com.vanniktech.maven.publish.JavadocJar + plugins { `java-library` - `maven-publish` + alias(libs.plugins.maven.publish.base) } -val moduleName = "common" +base { + archivesName = "youtube-common" +} dependencies { - compileOnly("dev.arbjerg:lavaplayer:1.5.3") -} + compileOnly(libs.lavaplayer.v1) -val sourcesJar by tasks.registering(Jar::class) { - archiveClassifier.set("sources") - from(sourceSets["main"].allSource) + implementation(libs.rhino.engine) + implementation(libs.nanojson) + compileOnly(libs.slf4j) + compileOnly(libs.annotations) } -publishing { - publications { - create("mavenJava") { - from(components["java"]) - artifactId = moduleName - artifact(sourcesJar) - } - } -} +mavenPublishing { + configure(JavaLibrary(JavadocJar.Javadoc())) +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..e69de29 diff --git a/lldevs/build.gradle.kts b/lldevs/build.gradle.kts deleted file mode 100644 index b4edd87..0000000 --- a/lldevs/build.gradle.kts +++ /dev/null @@ -1,26 +0,0 @@ -plugins { - `java-library` - `maven-publish` -} - -val moduleName = "lldevs" - -dependencies { - compileOnly(project(":common")) - compileOnly("dev.arbjerg:lavaplayer:2.1.1") -} - -val sourcesJar by tasks.registering(Jar::class) { - archiveClassifier.set("sources") - from(sourceSets["main"].allSource) -} - -publishing { - publications { - create("mavenJava") { - from(components["java"]) - artifactId = moduleName - artifact(sourcesJar) - } - } -} diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts index bd59e9e..7ed3fbc 100644 --- a/plugin/build.gradle.kts +++ b/plugin/build.gradle.kts @@ -1,16 +1,31 @@ +import com.vanniktech.maven.publish.JavaLibrary +import com.vanniktech.maven.publish.JavadocJar + plugins { `java-library` - `maven-publish` + alias(libs.plugins.lavalink.gradle.plugin) + alias(libs.plugins.maven.publish.base) } -val moduleName = "plugin" +lavalinkPlugin { + name = "youtube-plugin" + path = "dev.lavalink.youtube.plugin" + apiVersion = libs.versions.lavalink + serverVersion = "4.0.4" + configurePublishing = false +} + +base { + archivesName = "youtube-plugin" +} dependencies { - implementation(project(":common")) - implementation(project(":lldevs")) - compileOnly("dev.arbjerg.lavalink:plugin-api:3.7.11") - compileOnly("dev.arbjerg.lavalink:Lavalink-Server:3.7.11") - compileOnly("dev.arbjerg:lavaplayer-ext-youtube-rotator:1.5.3") + implementation(projects.common) + implementation(projects.v2) + compileOnly(libs.lavalink.server) + compileOnly(libs.lavaplayer.ext.youtube.rotator) + compileOnly(libs.slf4j) + compileOnly(libs.annotations) } java { @@ -18,24 +33,7 @@ java { targetCompatibility = JavaVersion.VERSION_11 } -val sourcesJar by tasks.registering(Jar::class) { - archiveClassifier.set("sources") - from(sourceSets["main"].allSource) -} - -tasks.jar { - dependsOn(project(":common").tasks.jar) - dependsOn(project(":lldevs").tasks.jar) - from(configurations.runtimeClasspath.get().map(::zipTree)) - duplicatesStrategy = DuplicatesStrategy.WARN -} - -publishing { - publications { - create("mavenJava") { - from(components["java"]) - artifactId = moduleName - artifact(sourcesJar) - } - } -} +mavenPublishing { + coordinates("dev.lavalink.youtube", "youtube-plugin", version.toString()) + configure(JavaLibrary(JavadocJar.None(), sourcesJar = false)) +} \ No newline at end of file diff --git a/plugin/src/main/resources/lavalink-plugins/youtube.properties b/plugin/src/main/resources/lavalink-plugins/youtube.properties deleted file mode 100644 index 047d03a..0000000 --- a/plugin/src/main/resources/lavalink-plugins/youtube.properties +++ /dev/null @@ -1,3 +0,0 @@ -name=youtube -path=dev.lavalink.youtube.plugin -version=1.0.7 diff --git a/settings.gradle.kts b/settings.gradle.kts index bc95d19..80b2179 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,3 +1,34 @@ -include("lldevs") +rootProject.name = "youtube-source" + +include("v2") include("common") include("plugin") + +enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") + +dependencyResolutionManagement { + versionCatalogs { + create("libs") { + version("lavaplayer-v1", "1.5.3") + version("lavaplayer-v2", "2.1.1") + + library("lavaplayer-v1", "dev.arbjerg", "lavaplayer").versionRef("lavaplayer-v1") + library("lavaplayer-v2", "dev.arbjerg", "lavaplayer").versionRef("lavaplayer-v2") + + version("lavalink", "3.7.11") + library("lavalink-server", "dev.arbjerg.lavalink", "Lavalink-Server").versionRef("lavalink") + library("lavaplayer-ext-youtube-rotator", "dev.arbjerg", "lavaplayer-ext-youtube-rotator").versionRef("lavaplayer-v1") + + library("rhino-engine", "org.mozilla", "rhino-engine").version("1.7.14") + library("nanojson", "com.grack", "nanojson").version("1.7") + library("slf4j", "org.slf4j", "slf4j-api").version("1.7.25") + library("annotations", "org.jetbrains", "annotations").version("24.1.0") + + plugin("lavalink-gradle-plugin", "dev.arbjerg.lavalink.gradle-plugin").version("1.0.15") + + val mavenPublishPlugin = version("maven-publish-plugin", "0.25.3") + plugin("maven-publish", "com.vanniktech.maven.publish").versionRef(mavenPublishPlugin) + plugin("maven-publish-base", "com.vanniktech.maven.publish.base").versionRef(mavenPublishPlugin) + } + } +} diff --git a/v2/build.gradle.kts b/v2/build.gradle.kts new file mode 100644 index 0000000..a6df1ea --- /dev/null +++ b/v2/build.gradle.kts @@ -0,0 +1,22 @@ +import com.vanniktech.maven.publish.JavaLibrary +import com.vanniktech.maven.publish.JavadocJar + +plugins { + `java-library` + alias(libs.plugins.maven.publish.base) +} + +base { + archivesName = "youtube-v2" +} + +dependencies { + api(projects.common) + compileOnly(libs.lavaplayer.v2) + compileOnly(libs.slf4j) + compileOnly(libs.annotations) +} + +mavenPublishing { + configure(JavaLibrary(JavadocJar.Javadoc())) +} diff --git a/lldevs/src/main/java/dev/lavalink/youtube/clients/AndroidTestsuiteWithThumbnail.java b/v2/src/main/java/dev/lavalink/youtube/clients/AndroidTestsuiteWithThumbnail.java similarity index 100% rename from lldevs/src/main/java/dev/lavalink/youtube/clients/AndroidTestsuiteWithThumbnail.java rename to v2/src/main/java/dev/lavalink/youtube/clients/AndroidTestsuiteWithThumbnail.java diff --git a/lldevs/src/main/java/dev/lavalink/youtube/clients/AndroidWithThumbnail.java b/v2/src/main/java/dev/lavalink/youtube/clients/AndroidWithThumbnail.java similarity index 100% rename from lldevs/src/main/java/dev/lavalink/youtube/clients/AndroidWithThumbnail.java rename to v2/src/main/java/dev/lavalink/youtube/clients/AndroidWithThumbnail.java diff --git a/lldevs/src/main/java/dev/lavalink/youtube/clients/IosWithThumbnail.java b/v2/src/main/java/dev/lavalink/youtube/clients/IosWithThumbnail.java similarity index 100% rename from lldevs/src/main/java/dev/lavalink/youtube/clients/IosWithThumbnail.java rename to v2/src/main/java/dev/lavalink/youtube/clients/IosWithThumbnail.java diff --git a/lldevs/src/main/java/dev/lavalink/youtube/clients/MusicWithThumbnail.java b/v2/src/main/java/dev/lavalink/youtube/clients/MusicWithThumbnail.java similarity index 100% rename from lldevs/src/main/java/dev/lavalink/youtube/clients/MusicWithThumbnail.java rename to v2/src/main/java/dev/lavalink/youtube/clients/MusicWithThumbnail.java diff --git a/lldevs/src/main/java/dev/lavalink/youtube/clients/TvHtml5EmbeddedWithThumbnail.java b/v2/src/main/java/dev/lavalink/youtube/clients/TvHtml5EmbeddedWithThumbnail.java similarity index 100% rename from lldevs/src/main/java/dev/lavalink/youtube/clients/TvHtml5EmbeddedWithThumbnail.java rename to v2/src/main/java/dev/lavalink/youtube/clients/TvHtml5EmbeddedWithThumbnail.java diff --git a/lldevs/src/main/java/dev/lavalink/youtube/clients/WebWithThumbnail.java b/v2/src/main/java/dev/lavalink/youtube/clients/WebWithThumbnail.java similarity index 100% rename from lldevs/src/main/java/dev/lavalink/youtube/clients/WebWithThumbnail.java rename to v2/src/main/java/dev/lavalink/youtube/clients/WebWithThumbnail.java diff --git a/lldevs/src/main/java/dev/lavalink/youtube/clients/skeleton/ThumbnailMusicClient.java b/v2/src/main/java/dev/lavalink/youtube/clients/skeleton/ThumbnailMusicClient.java similarity index 100% rename from lldevs/src/main/java/dev/lavalink/youtube/clients/skeleton/ThumbnailMusicClient.java rename to v2/src/main/java/dev/lavalink/youtube/clients/skeleton/ThumbnailMusicClient.java diff --git a/lldevs/src/main/java/dev/lavalink/youtube/clients/skeleton/ThumbnailNonMusicClient.java b/v2/src/main/java/dev/lavalink/youtube/clients/skeleton/ThumbnailNonMusicClient.java similarity index 100% rename from lldevs/src/main/java/dev/lavalink/youtube/clients/skeleton/ThumbnailNonMusicClient.java rename to v2/src/main/java/dev/lavalink/youtube/clients/skeleton/ThumbnailNonMusicClient.java diff --git a/lldevs/src/main/java/dev/lavalink/youtube/clients/skeleton/ThumbnailStreamingNonMusicClient.java b/v2/src/main/java/dev/lavalink/youtube/clients/skeleton/ThumbnailStreamingNonMusicClient.java similarity index 100% rename from lldevs/src/main/java/dev/lavalink/youtube/clients/skeleton/ThumbnailStreamingNonMusicClient.java rename to v2/src/main/java/dev/lavalink/youtube/clients/skeleton/ThumbnailStreamingNonMusicClient.java