Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved to Kotlinx-serialization and updated Gradle and Kotlin #254

Closed
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
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
apply plugin: 'com.android.application'
apply plugin: 'org.jetbrains.kotlin.android'
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}

android {
compileSdkVersion 32
compileSdkVersion 34
defaultConfig {
applicationId "com.yausername.youtubedl_android_example"
minSdkVersion 21
//noinspection ExpiredTargetSdkVersion
targetSdkVersion 32
targetSdkVersion 34
versionCode project.versionCode
versionName project.versionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
15 changes: 13 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />

<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="29" />

<uses-permission
android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />

<application
android:name=".App"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,7 @@ private void startDownload() {
return;
}

YoutubeDLRequest request = new YoutubeDLRequest(url);
File youtubeDLDir = getDownloadLocation();
File config = new File(youtubeDLDir, "config.txt");

if (useConfigFile.isChecked() && config.exists()) {
request.addOption("--config-location", config.getAbsolutePath());
} else {
request.addOption("--no-mtime");
request.addOption("--downloader", "libaria2c.so");
request.addOption("--external-downloader-args", "aria2c:\"--summary-interval=1\"");
request.addOption("-f", "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best");
request.addOption("-o", youtubeDLDir.getAbsolutePath() + "/%(title)s.%(ext)s");
}
YoutubeDLRequest request = getYoutubeDLRequest(url);

showStart();

Expand All @@ -160,6 +148,23 @@ private void startDownload() {

}

private YoutubeDLRequest getYoutubeDLRequest(String url) {
YoutubeDLRequest request = new YoutubeDLRequest(url);
File youtubeDLDir = getDownloadLocation();
File config = new File(youtubeDLDir, "config.txt");

if (useConfigFile.isChecked() && config.exists()) {
request.addOption("--config-location", config.getAbsolutePath());
} else {
request.addOption("--no-mtime");
request.addOption("--downloader", "libaria2c.so");
request.addOption("--external-downloader-args", "aria2c:\"--summary-interval=1\"");
request.addOption("-f", "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best");
request.addOption("-o", youtubeDLDir.getAbsolutePath() + "/%(title)s.%(ext)s");
}
return request;
}

@Override
protected void onDestroy() {
compositeDisposable.dispose();
Expand All @@ -180,17 +185,37 @@ private void showStart() {
pbLoading.setVisibility(View.VISIBLE);
}

public static final int STORAGE_PERMISSION_REQUEST_CODE = 1;

public boolean isStoragePermissionGranted() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) {
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
return true;
} else {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
requestStoragePermission();
return false;
}
} else {
return true;
}
}

private void requestStoragePermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, STORAGE_PERMISSION_REQUEST_CODE);
}
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
Log.i(TAG, "Request code:" + requestCode);
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == STORAGE_PERMISSION_REQUEST_CODE) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(DownloadingExampleActivity.this, "permission granted", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(DownloadingExampleActivity.this, "permission denied", Toast.LENGTH_LONG).show();
}
}
}
}
12 changes: 7 additions & 5 deletions aria2c/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
apply plugin: 'org.jetbrains.kotlin.android'
plugins {
id 'org.jetbrains.kotlin.android'
id 'com.android.library'
id 'maven-publish'
}

android {
compileSdkVersion 32
compileSdkVersion 34

defaultConfig {
minSdkVersion 21
targetSdkVersion 32
targetSdkVersion 34

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand Down
19 changes: 9 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

ext {
kotlin_version = '1.7.22'
kotlin_version = '1.8.20'
}
repositories {
google()
Expand All @@ -15,7 +14,7 @@ buildscript {

}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1'
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand All @@ -24,30 +23,30 @@ buildscript {
}

def versionMajor = 0
def versionMinor = 15
def versionMinor = 16
def versionPatch = 0
def versionBuild = 0 // bump for dogfood builds, public betas, etc.

ext {
versionCode = versionMajor * 100000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
versionName = "${versionMajor}.${versionMinor}.${versionPatch}"
appCompatVer = '1.4.2'
appCompatVer = '1.6.1'
junitVer = '4.13.2'
androidJunitVer = '1.1.3'
espressoVer = '3.4.0'
jacksonVer = '2.11.1'
androidJunitVer = '1.1.5'
espressoVer = '3.5.1'
// supports java 1.6
commonsIoVer = '2.5'
// supports java 1.6
commonsCompressVer = '1.12'
coreKtxVer = '1.8.0'
coreKtxVer = '1.12.0'
kotlinxSerializationVer = '1.4.1'
}

allprojects {
group = 'com.github.yausername'
version = versionName
}

task clean(type: Delete) {
tasks.register('clean', Delete) {
delete rootProject.buildDir
}
12 changes: 7 additions & 5 deletions common/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
apply plugin: 'org.jetbrains.kotlin.android'
plugins {
id 'org.jetbrains.kotlin.android'
id 'com.android.library'
id 'maven-publish'
}

android {
compileSdkVersion 32
compileSdkVersion 34

defaultConfig {
minSdkVersion 21
targetSdkVersion 32
targetSdkVersion 34

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ object ZipUtils {

fun unzip(inputStream: InputStream?, targetDirectory: File) {
ZipArchiveInputStream(BufferedInputStream(inputStream)).use { zis ->
var entry: ZipArchiveEntry? = null
var entry: ZipArchiveEntry?
while (zis.nextZipEntry.also { entry = it } != null) {
val entryDestination = File(targetDirectory, entry!!.name)
// prevent zipSlip
Expand All @@ -56,7 +56,7 @@ object ZipUtils {
if (entry!!.isDirectory) {
entryDestination.mkdirs()
} else {
entryDestination.parentFile.mkdirs()
entryDestination.parentFile?.mkdirs()
FileOutputStream(entryDestination).use { out -> IOUtils.copy(zis, out) }
}
}
Expand Down
12 changes: 7 additions & 5 deletions ffmpeg/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
apply plugin: 'org.jetbrains.kotlin.android'
plugins {
id 'org.jetbrains.kotlin.android'
id 'com.android.library'
id 'maven-publish'
}

android {
compileSdkVersion 32
compileSdkVersion 34

defaultConfig {
minSdkVersion 21
targetSdkVersion 32
targetSdkVersion 34

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Nov 27 22:57:49 GST 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
19 changes: 12 additions & 7 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
apply plugin: 'org.jetbrains.kotlin.android'
plugins {
id 'org.jetbrains.kotlin.plugin.serialization' version '1.8.20'
id 'com.android.library'
id 'maven-publish'
id 'org.jetbrains.kotlin.android'
}
android {
compileSdkVersion 32
compileSdkVersion 34

defaultConfig {
minSdkVersion 21
targetSdkVersion 32
targetSdkVersion 34

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -18,6 +21,9 @@ android {
}
}
namespace 'com.yausername.youtubedl_android'
kotlinOptions {
jvmTarget = '17'
}

}
afterEvaluate {
Expand All @@ -42,8 +48,7 @@ dependencies {
testImplementation "junit:junit:$junitVer"
androidTestImplementation "androidx.test.ext:junit:$androidJunitVer"
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVer"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinxSerializationVer"

implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: "$jacksonVer"
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: "$jacksonVer"
implementation group: 'commons-io', name: 'commons-io', version: "$commonsIoVer"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package com.yausername.youtubedl_android

import android.content.Context
import android.os.Build
import com.fasterxml.jackson.databind.ObjectMapper
import com.yausername.youtubedl_android.YoutubeDLException
import com.yausername.youtubedl_android.mapper.VideoInfo
import com.yausername.youtubedl_common.SharedPrefsHelper
import com.yausername.youtubedl_common.SharedPrefsHelper.update
import com.yausername.youtubedl_common.utils.ZipUtils.unzip
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import org.apache.commons.io.FileUtils
import java.io.File
import java.io.IOException
Expand Down Expand Up @@ -107,10 +107,10 @@ object YoutubeDL {
request.addOption("--dump-json")
val response = execute(request, null, null)
val videoInfo: VideoInfo = try {
objectMapper.readValue(response.out, VideoInfo::class.java)
json.decodeFromString<VideoInfo>(response.out)
} catch (e: IOException) {
throw YoutubeDLException("Unable to parse video information", e)
} ?: throw YoutubeDLException("Failed to fetch video information")
}
return videoInfo
}

Expand Down Expand Up @@ -266,7 +266,10 @@ object YoutubeDL {
const val ytdlpDirName = "yt-dlp"
const val ytdlpBin = "yt-dlp"
private const val pythonLibVersion = "pythonLibVersion"
val objectMapper = ObjectMapper()
val json = Json {
ignoreUnknownKeys = true
encodeDefaults = true
}

@JvmStatic
fun getInstance() = this
Expand Down
Loading