Skip to content
Closed
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
24 changes: 11 additions & 13 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ name: Publish
on:
push:
release:
types: [ published ]
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@v4
Expand All @@ -25,23 +23,23 @@ jobs:
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4

- name: Build and Publish
run: ./gradlew build publish --no-daemon -PMAVEN_USERNAME=$MAVEN_USERNAME -PMAVEN_PASSWORD=$MAVEN_PASSWORD
- name: Build Project
run: ./gradlew build --no-daemon

- name: Upload common Artifact
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v4
with:
name: youtube-common.jar
path: common/build/libs/youtube-common-*.jar

- name: Upload lldevs Artifact
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v4
with:
name: youtube-v2.jar
path: v2/build/libs/youtube-v2-*.jar

- name: Upload plugin Artifact
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v4
with:
name: youtube-plugin.jar
path: plugin/build/libs/youtube-plugin-*.jar
Expand All @@ -55,17 +53,17 @@ jobs:
uses: actions/checkout@v4

- name: Download youtube-common Artifact
uses: actions/download-artifact@v4
uses: actions/download-artifact@v4
with:
name: youtube-common.jar

- name: Download youtube-v2 Artifact
uses: actions/download-artifact@v4
uses: actions/download-artifact@v4
with:
name: youtube-v2.jar

- name: Download youtube-plugin Artifact
uses: actions/download-artifact@v4
uses: actions/download-artifact@v4
with:
name: youtube-plugin.jar

Expand All @@ -77,4 +75,4 @@ jobs:
omitBodyDuringUpdate: true
omitDraftDuringUpdate: true
omitNameDuringUpdate: true
omitPrereleaseDuringUpdate: true
omitPrereleaseDuringUpdate: true
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,28 @@ If `videoId` could not be found or loaded, or the `itag` does not exist, or if n
Otherwise:
`200 - OK` accompanied by the selected format stream (audio or video). `Content-Type` header will be set appropriately.

### `GET` `/youtube/oauth/{refreshToken}`

Response:

If the `refreshToken` is invalid, expired, or cannot be processed:
`500 - Internal Server Error`

If the refresh process succeeds and a new access token is generated:
`200 - OK` accompanied by the new access token in JSON format.

Example response:
```json
{
"access_token": "AccessToken",
"expires_in": 69420,
"scope": "used scope",
"token_type": "type"
}
```



## Migration from Lavaplayer's built-in YouTube source

This client is intended as a direct replacement for Lavaplayer's built-in `YoutubeAudioSourceManager`,
Expand Down
10 changes: 6 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@ subprojects {
targetCompatibility = JavaVersion.VERSION_1_8
}

configure<PublishingExtension> {
if (findProperty("MAVEN_PASSWORD") != null && findProperty("MAVEN_USERNAME") != null) {
configure<PublishingExtension> {
val mavenUsername = findProperty("MAVEN_USERNAME") as String?
val mavenPassword = findProperty("MAVEN_PASSWORD") as String?
if (!mavenUsername.isNullOrEmpty() && !mavenPassword.isNullOrEmpty()) {
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?
username = mavenUsername
password = mavenPassword
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ dependencies {
testImplementation(libs.lavaplayer.v1)
testImplementation("org.apache.logging.log4j:log4j-core:2.19.0")
testImplementation("org.apache.logging.log4j:log4j-slf4j2-impl:2.19.0")

testImplementation("org.junit.jupiter:junit-jupiter-api:5.11.0-M1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.11.0-M1")
}

mavenPublishing {
Expand All @@ -36,4 +39,7 @@ tasks {
)
)
}
test {
useJUnitPlatform() // Enable JUnit Platform for running JUnit 5 tests
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package dev.lavalink.youtube.cipher;

public class ScriptExtractionException extends RuntimeException {
private final ExtractionFailureType failureType;

public enum ExtractionFailureType {
TIMESTAMP_NOT_FOUND,
ACTION_FUNCTIONS_NOT_FOUND,
DECIPHER_FUNCTION_NOT_FOUND,
N_FUNCTION_NOT_FOUND
}

public ScriptExtractionException(String message, ExtractionFailureType failureType) {
super(message);
this.failureType = failureType;
}

public ScriptExtractionException(String message, ExtractionFailureType failureType, Throwable cause) {
super(message, cause);
this.failureType = failureType;
}

public ExtractionFailureType getFailureType() {
return failureType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,88 +5,38 @@
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptException;
import java.util.ArrayList;
import java.util.List;

/**
* Describes one signature cipher
*/
public class SignatureCipher {
private final List<CipherOperation> operations = new ArrayList<>();
public final String nFunction;
public final String scriptTimestamp;
public final String rawScript;

public final boolean tceScript;
public final String tceVars;
public SignatureCipher(
@NotNull String timestamp,
@NotNull String rawScript) {

public SignatureCipher(@NotNull String nFunction,
@NotNull String timestamp,
@NotNull String rawScript,
boolean tceScript,
@NotNull String tceVars) {
this.nFunction = nFunction;
this.scriptTimestamp = timestamp;
this.rawScript = rawScript;
this.tceScript = tceScript;
this.tceVars = tceVars;
}

/**
* @param text Text to apply the cipher on
* @return The result of the cipher on the input text
*/
public String apply(@NotNull String text) {
StringBuilder builder = new StringBuilder(text);

for (CipherOperation operation : operations) {
switch (operation.type) {
case SWAP:
int position = operation.parameter % text.length();
char temp = builder.charAt(0);
builder.setCharAt(0, builder.charAt(position));
builder.setCharAt(position, temp);
break;
case REVERSE:
builder.reverse();
break;
case SLICE:
case SPLICE:
builder.delete(0, operation.parameter);
break;
default:
throw new IllegalStateException("All branches should be covered");
}
}

return builder.toString();
}


/**
* @param text Text to transform
* @param text Text to transform
* @param funcName Function name to invoke
* @param scriptEngine JavaScript engine to execute function
* @return The result of the n parameter transformation
*/
public String transform(@NotNull String text, @NotNull ScriptEngine scriptEngine) throws ScriptException, NoSuchMethodException {
public String transform(@NotNull String text,@NotNull String funcName , @NotNull ScriptEngine scriptEngine)
throws ScriptException, NoSuchMethodException {
String transformed;

scriptEngine.eval("n=" + nFunction + (tceScript ? tceVars : ""));
transformed = (String) ((Invocable) scriptEngine).invokeFunction("n", text);
// String patchedScript = rawScript.replaceAll("\\bconst\\b", "var");
scriptEngine.eval(rawScript);
transformed = (String) ((Invocable) scriptEngine).invokeFunction(funcName, text);

return transformed;
}

/**
* @param operation The operation to add to this cipher
*/
public void addOperation(@NotNull CipherOperation operation) {
operations.add(operation);
}

/**
* @return True if the cipher contains no operations.
*/
public boolean isEmpty() {
return operations.isEmpty();
}
}

}
Loading