Skip to content
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
201 changes: 103 additions & 98 deletions youtubeapi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,106 +3,111 @@ apply plugin: 'kotlin-android'
apply plugin: 'com.android.library'

android {
compileSdkVersion project.ext.compileSdkVersion
buildToolsVersion project.ext.buildToolsVersion
testOptions.unitTests.includeAndroidResources = true

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
minSdkVersion project.ext.minSdkVersion
targetSdkVersion project.ext.targetSdkVersion
versionCode 15
versionName "0.1.5"

// required for androidTest support
// more info: https://developer.android.com/training/testing/unit-testing/instrumented-unit-tests
// small tests: https://stackoverflow.com/questions/4671923/what-is-the-purpose-of-smalltest-mediumtest-and-largetest-annotations-in-an
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

// More info: http://myhexaville.com/2017/03/10/android-multidex/
// Additionally, you should extend your application from MultiDexApplication
multiDexEnabled = true

// consumerProguardFiles 'proguard-rules.txt' // embed this file to aar
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

// gradle 4.6 migration: disable dimensions mechanism
// more: https://proandroiddev.com/advanced-android-flavors-part-4-a-new-version-fc2ad80c01bb
flavorDimensions "default"

productFlavors {
stbeta {}
ststable {}
stfdroid {}
compileSdkVersion project.ext.compileSdkVersion
buildToolsVersion project.ext.buildToolsVersion
testOptions.unitTests.includeAndroidResources = true

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
minSdkVersion project.ext.minSdkVersion
targetSdkVersion project.ext.targetSdkVersion
versionCode 15
versionName "0.1.5"

// required for androidTest support
// more info: https://developer.android.com/training/testing/unit-testing/instrumented-unit-tests
// small tests: https://stackoverflow.com/questions/4671923/what-is-the-purpose-of-smalltest-mediumtest-and-largetest-annotations-in-an
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

// More info: http://myhexaville.com/2017/03/10/android-multidex/
// Additionally, you should extend your application from MultiDexApplication
multiDexEnabled = true

consumerProguardFiles 'consumer-rules.pro'
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

// gradle 4.6 migration: disable dimensions mechanism
// more: https://proandroiddev.com/advanced-android-flavors-part-4-a-new-version-fc2ad80c01bb
flavorDimensions "default"

productFlavors {
stbeta {}
// The active JavaScriptEngine implementation requires API 26.
ststable { minSdkVersion 26 }
stfdroid {}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

testImplementation project(':youtubeapi')
testImplementation project(':sharedtests')
testImplementation 'co.infinum:retromock:' + retromockVersion
testImplementation 'junit:junit:' + junitVersion
testImplementation 'org.robolectric:robolectric:' + robolectricVersion

androidTestImplementation project(':youtubeapi')
androidTestImplementation project(':sharedtests')
androidTestImplementation 'junit:junit:' + junitVersion
androidTestImplementation 'androidx.test:runner:' + testXSupportVersion
androidTestImplementation 'androidx.test:rules:' + testXSupportVersion

implementation project(':commons-io-2.8.0') // My Android 4.3 fix
implementation project(':sharedutils')
implementation project(':mediaserviceinterfaces')

implementation 'com.squareup.retrofit2:retrofit:' + retrofitVersion
implementation 'com.squareup.retrofit2:converter-gson:' + retrofitVersion
implementation 'com.google.code.gson:gson:' + gsonVersion
implementation 'com.jayway.jsonpath:json-path:' + jsonPathVersion

implementation 'com.google.net.cronet:cronet-okhttp:' + cronetOkHttpVersion
implementation 'org.chromium.net:cronet-api:' + cronetApiVersion

implementation 'io.reactivex.rxjava2:rxandroid:' + rxAndroidVersion
implementation 'io.reactivex.rxjava2:rxjava:' + rxJavaVersion

implementation 'androidx.annotation:annotation:' + annotationXVersion

// js interpreter
// duktape fork
// implementation 'app.cash.quickjs:quickjs-android:' + quickjsVersion
//implementation 'com.squareup.duktape:duktape-android:' + duktapeVersion
//implementation 'org.mozilla:rhino:' + rhinoVersion
//implementation 'com.eclipsesource.j2v8:j2v8:' + j2v8Version + '@aar'
// https://mvnrepository.com/artifact/com.eclipsesource.j2v8/j2v8/6.2.1
//implementation(name: 'j2v8-6.2.1', ext: 'aar')
//implementation files('libs/j2v8-6.2.1-fixed.aar')
// https://stackoverflow.com/questions/60878599/error-building-android-library-direct-local-aar-file-dependencies-are-not-supp
stbetaImplementation project(':j2v8')
ststableImplementation project(':j2v8')
stfdroidImplementation 'com.eclipsesource.j2v8:j2v8:' + j2v8Version + '@aar'

// Add kotlin support libs
implementation 'androidx.core:core-ktx:' + kotlinCoreXVersion
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:' + kotlinVersion
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:' + kotlinVersion

// https://github.com/florianingerl/com.florianingerl.util.regex
implementation 'com.github.florianingerl.util:regex:' + florianingerlRegexVersion

// NewPipe pot
implementation 'androidx.webkit:webkit:' + webkitVersion
implementation 'com.grack:nanojson:' + nanojsonVersion
implementation fileTree(dir: 'libs', include: ['*.jar'])

testImplementation project(':youtubeapi')
testImplementation project(':sharedtests')
testImplementation 'co.infinum:retromock:' + retromockVersion
testImplementation 'junit:junit:' + junitVersion
testImplementation 'org.robolectric:robolectric:' + robolectricVersion

androidTestImplementation project(':youtubeapi')
androidTestImplementation project(':sharedtests')
androidTestImplementation 'junit:junit:' + junitVersion
androidTestImplementation 'androidx.test:runner:' + testXSupportVersion
androidTestImplementation 'androidx.test:rules:' + testXSupportVersion

implementation project(':commons-io-2.8.0') // My Android 4.3 fix
implementation project(':sharedutils')
implementation project(':mediaserviceinterfaces')

implementation 'com.squareup.retrofit2:retrofit:' + retrofitVersion
implementation 'com.squareup.retrofit2:converter-gson:' + retrofitVersion
implementation 'com.google.code.gson:gson:' + gsonVersion
implementation 'com.jayway.jsonpath:json-path:' + jsonPathVersion

implementation 'com.google.net.cronet:cronet-okhttp:' + cronetOkHttpVersion
implementation 'org.chromium.net:cronet-api:' + cronetApiVersion

implementation 'io.reactivex.rxjava2:rxandroid:' + rxAndroidVersion
implementation 'io.reactivex.rxjava2:rxjava:' + rxJavaVersion

implementation 'androidx.annotation:annotation:' + annotationXVersion
// Beta01 remains compatible with SmartTube's AGP 7.4.2 build.
implementation 'androidx.javascriptengine:javascriptengine:1.0.0-beta01'

// js interpreter
// duktape fork
// implementation 'app.cash.quickjs:quickjs-android:' + quickjsVersion
//implementation 'com.squareup.duktape:duktape-android:' + duktapeVersion
//implementation 'org.mozilla:rhino:' + rhinoVersion
//implementation 'com.eclipsesource.j2v8:j2v8:' + j2v8Version + '@aar'
// https://mvnrepository.com/artifact/com.eclipsesource.j2v8/j2v8/6.2.1
//implementation(name: 'j2v8-6.2.1', ext: 'aar')
//implementation files('libs/j2v8-6.2.1-fixed.aar')
// https://stackoverflow.com/questions/60878599/error-building-android-library-direct-local-aar-file-dependencies-are-not-supp
stbetaImplementation project(':j2v8')
// Keep the unused V8 implementation compilable without publishing or
// packaging its native libraries in the stable artifact.
ststableCompileOnly project(':j2v8')
stfdroidImplementation 'com.eclipsesource.j2v8:j2v8:' + j2v8Version + '@aar'

// Add kotlin support libs
implementation 'androidx.core:core-ktx:' + kotlinCoreXVersion
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:' + kotlinVersion
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:' + kotlinxVersion

// https://github.com/florianingerl/com.florianingerl.util.regex
implementation 'com.github.florianingerl.util:regex:' + florianingerlRegexVersion

// NewPipe pot
implementation 'androidx.webkit:webkit:' + webkitVersion
implementation 'com.grack:nanojson:' + nanojsonVersion
}
4 changes: 4 additions & 0 deletions youtubeapi/consumer-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# The stable artifact intentionally compiles, but does not package, the legacy
# J2V8 backend. It is unreachable while JavaScriptEngine is the selected
# implementation, so consumers may safely ignore its optional class references.
-dontwarn com.eclipsesource.v8.**
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.liskovsoft.youtubeapi.app.nsigsolver.runtime

import androidx.test.platform.app.InstrumentationRegistry
import com.liskovsoft.sharedutils.prefs.GlobalPreferences
import com.liskovsoft.youtubeapi.app.nsigsolver.impl.V8ChallengeProvider
import com.liskovsoft.youtubeapi.app.nsigsolver.impl.JsChallangeProvider
import com.liskovsoft.youtubeapi.app.nsigsolver.provider.ChallengeInput
import com.liskovsoft.youtubeapi.app.nsigsolver.provider.ChallengeOutput
import com.liskovsoft.youtubeapi.app.nsigsolver.provider.JsChallengeProviderResponse
Expand Down Expand Up @@ -86,13 +86,13 @@ internal class ChallengeProviderTest {

@Test
fun testNonEmptyResponse() {
val actual = V8ChallengeProvider.bulkSolve(tests).toList()
val actual = JsChallangeProvider.bulkSolve(tests).toList()
assertEquals(responses, actual)
}

@Test
fun testSingleNRequest() {
val result = V8ChallengeProvider.bulkSolve(listOf(tests.first())).toList()
val result = JsChallangeProvider.bulkSolve(listOf(tests.first())).toList()
assertTrue("not empty", result.isNotEmpty())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.liskovsoft.youtubeapi.app.potoken
import com.google.gson.JsonElement
import com.liskovsoft.sharedutils.TestHelpers
import com.liskovsoft.googlecommon.common.helpers.RetrofitHelper
import com.liskovsoft.googlecommon.common.js.V8Runtime
import com.liskovsoft.googlecommon.common.js.JavaScriptRuntime

internal class PoToken {
data class Arguments(val privateScript: String?,
Expand Down Expand Up @@ -39,7 +39,7 @@ internal class PoToken {
""".trimIndent()
)

val poToken = V8Runtime.instance().evaluate(script.joinToString(""))
val poToken = JavaScriptRuntime.evaluate(script.joinToString(""))

return Result(poToken, bgResult.integrityTokenData)
}
Expand Down Expand Up @@ -102,8 +102,8 @@ internal class PoToken {
"result.toString();"
)

val result = V8Runtime.instance().evaluate(script) ?: return null
//val result = V8Runtime.instance().evaluate(script.joinToString(""))
val result = JavaScriptRuntime.evaluate(script) ?: return null
//val result = JavaScriptRuntime.evaluate(script.joinToString(""))

val (postProcessFunction, payload) = result.split(RESULT_DELIM)

Expand All @@ -127,4 +127,4 @@ internal class PoToken {
private fun asInt(intElem: JsonElement?) = if (intElem?.isJsonNull == true) null else intElem?.asInt

private fun asString(strElem: JsonElement?) = if (strElem?.isJsonNull == true) null else strElem?.asString
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.liskovsoft.youtubeapi.app.potoken

import com.liskovsoft.sharedutils.TestHelpers
import com.liskovsoft.googlecommon.common.helpers.RetrofitHelper
import com.liskovsoft.googlecommon.common.js.V8Runtime
import com.liskovsoft.googlecommon.common.js.JavaScriptRuntime
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue
Expand Down Expand Up @@ -78,8 +78,8 @@ class PoTokenApiTest {
"var vm = trayride; vm.a('${program}', () => {}, true, undefined, () => {}).toString();"
)

val result = V8Runtime.instance().evaluate(script.joinToString(""))
val result = JavaScriptRuntime.evaluate(script.joinToString(""))

assertNotNull(result)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal object JSInterpret {
return { args: List<String> ->
val fullCode =
"(function (${argNames.joinToString(separator = ",")}) { $code })(${args.joinToString(separator = ",", prefix = "'", postfix = "'")})"
V8Runtime.instance().evaluateWithErrors(fullCode)
JavaScriptRuntime.evaluate(fullCode)
}
}

Expand Down Expand Up @@ -46,7 +46,11 @@ internal object JSInterpret {
}

fun interpretExpression(jsCode: String): List<String>? {
val result = V8Runtime.instance().evaluate("JSON.stringify($jsCode)")
val result = try {
JavaScriptRuntime.evaluate("JSON.stringify($jsCode)")
} catch (error: JavaScriptRuntime.JavaScriptRuntimeException) {
null
}

val gson = Gson()
val listType = object : TypeToken<List<String>>() {}.type
Expand Down Expand Up @@ -171,4 +175,4 @@ internal object JSInterpret {

return null
}
}
}
Loading