ПРИМЕЧАНИЕ: gradle собирается отлично, я даже не получаю предупреждений, это просто ошибка yt-lp во время загрузки видео.
// build.gradle (project level)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
alias(libs.plugins.android.application) apply false
id("com.chaquo.python") version "16.0.0" apply false
}
// build.gradle (app level)
plugins {
alias(libs.plugins.android.application)
id("com.chaquo.python")
}
chaquopy {
defaultConfig {
buildPython("C:/Program Files/Python313/python.exe")
buildPython("C:/Program Files/Python313/python.exe", "-3.8")
}
sourceSets {
getByName("main") {
srcDir("src/main/assets/python") // Tell Chaquopy to look here
}
}
}
android {
namespace 'com.example.ytrans'
compileSdk 34
defaultConfig {
applicationId "com.example.ytrans"
minSdk 24
targetSdk 34
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk {
// On Apple silicon, you can omit x86_64.
abiFilters "arm64-v8a", "x86_64"
}
python {
version "3.8"
buildPython "C:/Program Files/Python313/python.exe"
pip {
install "yt-dlp" // This will install yt-dlp via pip
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
}
dependencies {
implementation libs.appcompat
implementation libs.material
implementation libs.activity
implementation libs.constraintlayout
testImplementation libs.junit
androidTestImplementation libs.ext.junit
androidTestImplementation libs.espresso.core
implementation files("libs/ffmpeg-kit-full-6.0-2.LTS.aar")
}
// java code
public static void downloadVideo(String video_url, String output_path)
{
Python py = Python.getInstance();
PyObject pyObj = py.getModule("yt_dlp_script"); // Import yt-dlp
try {
pyObj.callAttr("download", video_url, output_path);
Log.i("VideoDownloader", "Video downloaded successfully!");
} catch (Exception e) {
Log.e("VideoDownloader", "Error downloading video: " + e.getMessage());
}
}
# python script
import yt_dlp
def download(video_url, output_path):
ydl_opts = {
'outtmpl': output_path, # specify the output file path
'merge_output_format': 'mp4',
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.download([video_url]) # Download the video
Подробнее здесь: https://stackoverflow.com/questions/793 ... nvironment