Closed furkanbalci0 closed 10 months ago
Please post the exception message (not just the stack trace), and the relevant parts of your code.
Sure,
Repositroy Class
class YoutubeRepository {
fun getTranscripts(videoId: String): String {
val python = Python.getInstance()
val pythonFile = python.getModule("youtube")
val result: PyObject = kotlin.run { pythonFile.callAttr("get_transcripts", videoId) }
val moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()
//List adapter
val jsonAdapter: JsonAdapter<List<TranscriptModel>> = moshi
.adapter<List<TranscriptModel>>(Types.newParameterizedType(List::class.java, TranscriptModel::class.java))
.lenient()
val list = jsonAdapter.fromJson(result.toString())!!
val stringBuilder = StringBuilder()
for (transcript in list) {
val text = transcript.text
stringBuilder.append("$text ")
}
//replace all new lines with spaces
stringBuilder.replace(Regex("[\\n\\r]"), " ")
return stringBuilder.toString()
}
}
src/main/python/youtube.py
from youtube_transcript_api import YouTubeTranscriptApi
def get_transcripts(video_id):
try:
transcript_list = YouTubeTranscriptApi.list_transcripts(video_id)
for transcript in transcript_list:
return transcript.fetch()
except Exception as e:
return {"error": str(e)}
gradle: app (root)
plugins {
id 'com.android.application' version '8.1.2' apply false
id 'org.jetbrains.kotlin.android' version '1.9.0' apply false
id 'com.chaquo.python' version '14.0.2' apply false
}
gradle: module
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.chaquo.python'
}
android {
namespace 'com.speedreadtube.app'
compileSdk 34
defaultConfig {
applicationId "com.speedreadtube.app"
minSdk 24
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk {
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
}
python {
version "3.11"
buildPython "/Library/Frameworks/Python.framework/Versions/3.11/bin/python3"
pip {
// A requirement specifier, with or without a version number:
install "youtube_transcript_api"
}
}
}
sourceSets {
main {
python.srcDir "src/main/python"
}
}
buildFeatures {
viewBinding true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.10.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
//Moshi
implementation 'com.squareup.moshi:moshi:1.14.0'
implementation 'com.squareup.moshi:moshi-kotlin:1.14.0'
//Navigation
implementation "androidx.navigation:navigation-fragment-ktx:2.7.4"
implementation "androidx.navigation:navigation-ui-ktx:2.7.4"
//Coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.2'
//Lottie
implementation 'com.airbnb.android:lottie:6.1.0'
//BlurKit
implementation 'jp.wasabeef:blurry:4.0.1'
implementation("com.squareup.okhttp3:logging-interceptor:4.11.0")
implementation("com.squareup.okhttp3:okhttp:4.11.0")
implementation("com.squareup.okhttp3:okhttp-urlconnection:4.9.1")
}
You still haven't posted the actual exception message. Please try to find it and understand it yourself before asking for help.
It should be in in the log near the stack trace, and if the exception comes from Python code, there should be some <python>
lines there too.
This stack trace is in an unusual format, which my searches suggest may be connected to Xiaomi MIUI devices. You may get more useful information from a different device.
I need to be able to access the python code in order to throw any exceptions, but since I cannot access the python code anyway, it gives the above error.
Where should “buildPython” be in Gradle?
Currently: "/Library/Frameworks/Python.framework/Versions/3.11/bin/python3"
You've closed the issue: does this mean you've solved your problem? If so, please post a comment explaining how you solved it, as this may be useful to other people.
I'm sorry for keeping you busy. I have concluded that the problem is not caused by you.
Chaquopy version
14.0.2
Devices or emulators where the issue happens
All devices and emulators.
Relevant parts of your code
Describe your issue
Sometimes the app works and sometimes it doesn't. It happens completely randomly. I do this entirely in mainthread.