From 24f04ec2bac0d271f7eef7cdf3c5497ac131364e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Denis=20=C3=87erri?=
<64997243+deniscerri@users.noreply.github.com>
Date: Mon, 27 Feb 2023 20:39:15 +0100
Subject: [PATCH] fixed some bugs on terminal mode and download card
---
app/build.gradle | 21 ++++++-----
app/src/main/AndroidManifest.xml | 3 +-
.../main/java/com/deniscerri/ytdlnis/App.kt | 23 ++++++++----
.../ytdlnis/ui/CustomCommandActivity.kt | 35 ++++++++++++-------
.../ui/downloadcard/DownloadAudioFragment.kt | 4 ---
.../DownloadMultipleBottomSheetDialog.kt | 1 -
.../ui/downloadcard/DownloadVideoFragment.kt | 12 ++-----
.../com/deniscerri/ytdlnis/util/FileUtil.kt | 2 +-
.../deniscerri/ytdlnis/work/DownloadWorker.kt | 6 +++-
app/src/main/res/layout/format_item.xml | 7 ++--
.../res/layout/format_select_bottom_sheet.xml | 3 +-
.../res/layout/please_wait_bottom_sheet.xml | 4 +--
app/src/main/res/values/strings.xml | 1 +
build.gradle | 2 +-
14 files changed, 72 insertions(+), 52 deletions(-)
diff --git a/app/build.gradle b/app/build.gradle
index 5ada4e52..d72b64d4 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -66,21 +66,24 @@ android {
buildTypes {
release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
+ minifyEnabled true
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
debuggable false
signingConfig signingConfigs.debug
}
dev {
- initWith buildTypes.release
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable true
+ signingConfig signingConfigs.debug
}
debug {
- initWith buildTypes.release
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable true
- proguardFiles 'baseline-profiles-rules.pro'
+ signingConfig signingConfigs.debug
}
}
@@ -116,9 +119,9 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
- implementation "com.github.junkfood02.youtubedl-android:library:$youtubedlAndroidVer"
- implementation "com.github.junkfood02.youtubedl-android:ffmpeg:$youtubedlAndroidVer"
- implementation "com.github.junkfood02.youtubedl-android:aria2c:$youtubedlAndroidVer"
+ implementation "com.github.JunkFood02.youtubedl-android:library:$youtubedlAndroidVer"
+ implementation "com.github.JunkFood02.youtubedl-android:ffmpeg:$youtubedlAndroidVer"
+ implementation "com.github.JunkFood02.youtubedl-android:aria2c:$youtubedlAndroidVer"
implementation "androidx.appcompat:appcompat:$appCompatVer"
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
@@ -136,7 +139,7 @@ dependencies {
androidTestImplementation "junit:junit:$junitVer"
androidTestImplementation "androidx.test.ext:junit:$androidJunitVer"
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVer"
- androidTestImplementation "androidx.benchmark:benchmark-macro-junit4:1.2.0-alpha09"
+ androidTestImplementation "androidx.benchmark:benchmark-macro-junit4:1.2.0-alpha10"
androidTestImplementation "androidx.test:runner:1.5.2"
androidTestImplementation "androidx.test:core:1.5.0"
androidTestImplementation "androidx.test:rules:1.5.0"
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 3e366f27..d2215144 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -5,8 +5,7 @@
-
+
diff --git a/app/src/main/java/com/deniscerri/ytdlnis/App.kt b/app/src/main/java/com/deniscerri/ytdlnis/App.kt
index ad018d49..daa784e3 100644
--- a/app/src/main/java/com/deniscerri/ytdlnis/App.kt
+++ b/app/src/main/java/com/deniscerri/ytdlnis/App.kt
@@ -13,6 +13,10 @@ import com.yausername.aria2c.Aria2c
import com.yausername.ffmpeg.FFmpeg
import com.yausername.youtubedl_android.YoutubeDL
import com.yausername.youtubedl_android.YoutubeDLException
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.SupervisorJob
+import kotlinx.coroutines.launch
import java.util.*
import java.util.concurrent.Executors
@@ -30,6 +34,16 @@ class App : Application() {
false
)
+ applicationScope = CoroutineScope(SupervisorJob())
+ applicationScope.launch((Dispatchers.IO)) {
+ try {
+ initLibraries()
+ }catch (e: Exception){
+ Toast.makeText(this@App, e.message, Toast.LENGTH_SHORT).show()
+ e.printStackTrace()
+ }
+ }
+
WorkManager.initialize(
this@App,
Configuration.Builder()
@@ -38,12 +52,8 @@ class App : Application() {
.getInt("concurrent_downloads", 1)))
.build())
- try {
- initLibraries()
- }catch (e: Exception){
- Toast.makeText(this@App, e.message, Toast.LENGTH_SHORT).show()
- e.printStackTrace()
- }
+
+
val locale = getSharedPreferences("root_preferences", MODE_PRIVATE)
.getString("app_language", Locale.getDefault().language)!!
AppCompatDelegate.setApplicationLocales(LocaleListCompat.forLanguageTags(locale))
@@ -62,5 +72,6 @@ class App : Application() {
companion object {
private const val TAG = "App"
+ private lateinit var applicationScope: CoroutineScope
}
}
\ No newline at end of file
diff --git a/app/src/main/java/com/deniscerri/ytdlnis/ui/CustomCommandActivity.kt b/app/src/main/java/com/deniscerri/ytdlnis/ui/CustomCommandActivity.kt
index bcc56403..8f51277c 100644
--- a/app/src/main/java/com/deniscerri/ytdlnis/ui/CustomCommandActivity.kt
+++ b/app/src/main/java/com/deniscerri/ytdlnis/ui/CustomCommandActivity.kt
@@ -100,6 +100,11 @@ class CustomCommandActivity : AppCompatActivity() {
private fun startDownload(command: String?) {
+ var cmd: String = ""
+ if (command!!.contains("yt-dlp")) cmd = command.replace("yt-dlp", "")
+ else cmd = command
+ cmd = cmd.trim()
+
downloadID = System.currentTimeMillis().toInt()
val theIntent = Intent(this, CustomCommandActivity::class.java)
@@ -121,8 +126,7 @@ class CustomCommandActivity : AppCompatActivity() {
notify(downloadID, commandNotification)
}
}
-
- val commandRegex = "\"([^\"]*)\"|(\\S+)"
+ val commandRegex = "(-\\S+)|(\\S+)"
val request = YoutubeDLRequest(emptyList())
val tempFolder = StringBuilder(context!!.cacheDir.absolutePath + """/${command}##terminal""")
@@ -130,8 +134,8 @@ class CustomCommandActivity : AppCompatActivity() {
tempFileDir.delete()
tempFileDir.mkdir()
-
- val m = Pattern.compile(commandRegex).matcher(command!!)
+ Log.e(TAG, cmd)
+ val m = Pattern.compile(commandRegex).matcher(cmd)
while (m.find()) {
if (m.group(1) != null) {
request.addOption(m.group(1)!!)
@@ -140,30 +144,34 @@ class CustomCommandActivity : AppCompatActivity() {
}
}
- request.addOption("-o", tempFileDir.absolutePath + "/%(uploader)s - %(title)s.%(ext)s")
+ request.addOption("-P", tempFileDir.absolutePath)
cancelFab!!.visibility = View.VISIBLE
fab!!.visibility = View.GONE
-
val disposable: Disposable = Observable.fromCallable {
try{
YoutubeDL.getInstance().execute(request, downloadID.toString()){ progress, _, line ->
+ Log.e(TAG, line)
runOnUiThread {
output!!.append("\n" + line)
output!!.scrollTo(0, output!!.height)
scrollView!!.fullScroll(View.FOCUS_DOWN)
-
- val title: String = getString(R.string.terminal)
- notificationUtil.updateDownloadNotification(
- downloadID,
- line, progress.toInt(), 0, title,
- NotificationUtil.COMMAND_DOWNLOAD_SERVICE_CHANNEL_ID
- )
}
+
+ val title: String = getString(R.string.terminal)
+ notificationUtil.updateDownloadNotification(
+ downloadID,
+ line, progress.toInt(), 0, title,
+ NotificationUtil.COMMAND_DOWNLOAD_SERVICE_CHANNEL_ID
+ )
}
}catch (e: Exception){
e.printStackTrace()
runOnUiThread {
+ output!!.append("\n" + e.message)
+ output!!.scrollTo(0, output!!.height)
+ scrollView!!.fullScroll(View.FOCUS_DOWN)
+
input!!.isEnabled = true
cancelFab!!.visibility = View.GONE
@@ -190,6 +198,7 @@ class CustomCommandActivity : AppCompatActivity() {
}
notificationUtil.cancelDownloadNotification(downloadID)
}) { e ->
+ e.printStackTrace()
scrollView!!.scrollTo(0, scrollView!!.maxScrollAmount)
input!!.setText("yt-dlp ")
input!!.isEnabled = true
diff --git a/app/src/main/java/com/deniscerri/ytdlnis/ui/downloadcard/DownloadAudioFragment.kt b/app/src/main/java/com/deniscerri/ytdlnis/ui/downloadcard/DownloadAudioFragment.kt
index d3d6f40e..c2255a3c 100644
--- a/app/src/main/java/com/deniscerri/ytdlnis/ui/downloadcard/DownloadAudioFragment.kt
+++ b/app/src/main/java/com/deniscerri/ytdlnis/ui/downloadcard/DownloadAudioFragment.kt
@@ -48,10 +48,6 @@ class DownloadAudioFragment(private var resultItem: ResultItem) : Fragment() {
lateinit var downloadItem: DownloadItem
- override fun onResume() {
- super.onResume()
- }
-
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
diff --git a/app/src/main/java/com/deniscerri/ytdlnis/ui/downloadcard/DownloadMultipleBottomSheetDialog.kt b/app/src/main/java/com/deniscerri/ytdlnis/ui/downloadcard/DownloadMultipleBottomSheetDialog.kt
index 31e42e7e..730221da 100644
--- a/app/src/main/java/com/deniscerri/ytdlnis/ui/downloadcard/DownloadMultipleBottomSheetDialog.kt
+++ b/app/src/main/java/com/deniscerri/ytdlnis/ui/downloadcard/DownloadMultipleBottomSheetDialog.kt
@@ -76,7 +76,6 @@ class DownloadMultipleBottomSheetDialog(private val items: List) :
recyclerView = view.findViewById(R.id.downloadMultipleRecyclerview)
recyclerView.layoutManager = LinearLayoutManager(requireContext())
- recyclerView.setHasFixedSize(true)
recyclerView.adapter = listAdapter
downloadViewModel.processingDownloads.observe(this) {
diff --git a/app/src/main/java/com/deniscerri/ytdlnis/ui/downloadcard/DownloadVideoFragment.kt b/app/src/main/java/com/deniscerri/ytdlnis/ui/downloadcard/DownloadVideoFragment.kt
index 82177403..80fb1e4e 100644
--- a/app/src/main/java/com/deniscerri/ytdlnis/ui/downloadcard/DownloadVideoFragment.kt
+++ b/app/src/main/java/com/deniscerri/ytdlnis/ui/downloadcard/DownloadVideoFragment.kt
@@ -29,7 +29,9 @@ import com.deniscerri.ytdlnis.util.FileUtil
import com.deniscerri.ytdlnis.util.UiUtil
import com.google.android.material.chip.Chip
import com.google.android.material.textfield.TextInputLayout
+import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
class DownloadVideoFragment(private val resultItem: ResultItem) : Fragment() {
@@ -142,7 +144,6 @@ class DownloadVideoFragment(private val resultItem: ResultItem) : Fragment() {
val listener = object : OnFormatClickListener {
override fun onFormatClick(allFormats: List, item: Format) {
downloadItem.format = item
- Log.e("Aa", item.toString())
if (containers.contains(item.container)){
downloadItem.format.container = item.container
@@ -150,15 +151,8 @@ class DownloadVideoFragment(private val resultItem: ResultItem) : Fragment() {
}else{
containerAutoCompleteTextView.setText(containers[0], false)
}
- if (resultItem.formats.isEmpty()){
- resultItem.formats = ArrayList(allFormats)
- }else{
- resultItem.formats = ArrayList(resultItem.formats.filter { it.format_note.contains("audio", ignoreCase = true) })
- resultItem.formats.addAll(allFormats)
- }
- resultViewModel.update(resultItem)
+
formats = allFormats.toMutableList()
- Log.e("Aa", item.toString())
uiUtil.populateFormatCard(formatCard, item)
}
}
diff --git a/app/src/main/java/com/deniscerri/ytdlnis/util/FileUtil.kt b/app/src/main/java/com/deniscerri/ytdlnis/util/FileUtil.kt
index d04c3d12..9e4f3d93 100644
--- a/app/src/main/java/com/deniscerri/ytdlnis/util/FileUtil.kt
+++ b/app/src/main/java/com/deniscerri/ytdlnis/util/FileUtil.kt
@@ -21,7 +21,6 @@ import kotlin.math.max
import kotlin.math.pow
class FileUtil() {
-
fun deleteFile(path: String){
val file = File(path)
if (file.exists()) {
@@ -127,6 +126,7 @@ class FileUtil() {
bytes = inputStream.read(buffer)
}
}catch (e : Exception){
+ e.printStackTrace()
Toast.makeText(context, e.message, Toast.LENGTH_LONG).show()
}
diff --git a/app/src/main/java/com/deniscerri/ytdlnis/work/DownloadWorker.kt b/app/src/main/java/com/deniscerri/ytdlnis/work/DownloadWorker.kt
index adc1c14f..51b5570c 100644
--- a/app/src/main/java/com/deniscerri/ytdlnis/work/DownloadWorker.kt
+++ b/app/src/main/java/com/deniscerri/ytdlnis/work/DownloadWorker.kt
@@ -110,6 +110,7 @@ class DownloadWorker(
}
if (downloadItem.customFileNameTemplate.isEmpty()) downloadItem.customFileNameTemplate = "%(uploader)s - %(title)s"
+ request.addOption("--restrict-filenames")
when(type){
DownloadViewModel.Type.audio -> {
@@ -183,7 +184,7 @@ class DownloadWorker(
request.addOption("-o", tempFileDir.absolutePath + "/${downloadItem.customFileNameTemplate}.%(ext)s")
}
DownloadViewModel.Type.command -> {
- val commandRegex = "\"([^\"]*)\"|(\\S+)"
+ val commandRegex = "\"([^\"]*)\"|(-\\S+)"
val command = commandTemplateDao.getTemplate(downloadItem.format.format_id.toLong())
val m = Pattern.compile(commandRegex).matcher(command.content)
while (m.find()) {
@@ -193,6 +194,8 @@ class DownloadWorker(
request.addOption(m.group(2)!!)
}
}
+ request.addOption("-P", tempFileDir.absolutePath)
+
}
}
@@ -230,6 +233,7 @@ class DownloadWorker(
}
}catch (e: Exception){
finalPath = context.getString(R.string.unfound_file)
+ e.printStackTrace()
handler.postDelayed({
Toast.makeText(context, e.message, Toast.LENGTH_SHORT).show()
}, 1000)
diff --git a/app/src/main/res/layout/format_item.xml b/app/src/main/res/layout/format_item.xml
index a538c14d..6d0db3d5 100644
--- a/app/src/main/res/layout/format_item.xml
+++ b/app/src/main/res/layout/format_item.xml
@@ -3,9 +3,12 @@
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/format_card_constraintLayout"
android:layout_width="match_parent"
+ android:clickable="true"
android:layout_height="wrap_content"
- android:paddingVertical="10dp"
- xmlns:android="http://schemas.android.com/apk/res/android">
+ android:paddingVertical="5dp"
+ android:background="?android:attr/selectableItemBackground"
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:focusable="true">
@@ -20,7 +20,7 @@
android:textColor="?attr/colorAccent"
android:layout_height="wrap_content"
android:text="@string/cancel"
- android:textSize="20sp"
+ android:textSize="17sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index b707589e..62bc10a5 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -124,6 +124,7 @@
Album
Video Quality
Embed Subtitles
+ Embed Subtitles
Add Chapters
Show Options for Downloading
Settings for how to download items
diff --git a/build.gradle b/build.gradle
index 867dee58..38722381 100644
--- a/build.gradle
+++ b/build.gradle
@@ -21,7 +21,7 @@ buildscript {
commonsIoVer = '2.5'
// supports java 1.6
commonsCompressVer = '1.12'
- youtubedlAndroidVer = "970b819246"
+ youtubedlAndroidVer = "7222fe9637"
workVer = "2.8.0"
composeVer = "1.4.0-alpha02"
kotlinVer = "1.7.21"