more fixes

This commit is contained in:
deniscerri 2025-02-16 14:31:15 +01:00
parent 1b40938622
commit c5298c5739
No known key found for this signature in database
GPG key ID: 95C43D517D830350
10 changed files with 122 additions and 15 deletions

View file

@ -19,9 +19,13 @@ import com.deniscerri.ytdl.database.models.CookieItem
import com.deniscerri.ytdl.database.repository.CookieRepository import com.deniscerri.ytdl.database.repository.CookieRepository
import com.deniscerri.ytdl.ui.more.WebViewActivity import com.deniscerri.ytdl.ui.more.WebViewActivity
import com.deniscerri.ytdl.util.FileUtil import com.deniscerri.ytdl.util.FileUtil
import com.google.gson.GsonBuilder
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import java.io.File import java.io.File
import java.util.Calendar
import java.util.Date import java.util.Date
@ -188,15 +192,25 @@ class CookieViewModel(private val application: Application) : AndroidViewModel(a
} }
} }
fun exportToFile(exported: (File?) -> Unit) { fun exportToFile(exported: (File?) -> Unit) = viewModelScope.launch(Dispatchers.IO) {
try{ try{
FileUtil.getCookieFile(application, true){ c -> FileUtil.getCookieFile(application, true){ c ->
val cookieFile = File(c) val cookieFile = File(c)
if (!cookieFile.exists()) updateCookiesFile() if (!cookieFile.exists()) updateCookiesFile()
val downloads = File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).absolutePath + File.separator + "YTDLnis_Cookies.txt") val dir = File("${FileUtil.getCachePath(application)}/Cookie Backups")
val file = cookieFile.copyTo(downloads, true) dir.mkdirs()
exported(file) val saveFile = File("${dir.absolutePath}/YTDLnis_Cookies.txt")
saveFile.delete()
saveFile.createNewFile()
cookieFile.copyTo(saveFile, true)
val res = runBlocking {
FileUtil.moveFile(saveFile.parentFile!!, application, FileUtil.getDefaultApplicationPath(), false) {}
}
exported(File(res[0]))
} }
}catch (e: Exception){ }catch (e: Exception){
e.printStackTrace() e.printStackTrace()

View file

@ -1,6 +1,7 @@
package com.deniscerri.ytdl.database.viewmodel package com.deniscerri.ytdl.database.viewmodel
import android.app.Application import android.app.Application
import android.os.Environment
import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.asLiveData import androidx.lifecycle.asLiveData
@ -9,8 +10,11 @@ import com.deniscerri.ytdl.database.DBManager
import com.deniscerri.ytdl.database.models.LogItem import com.deniscerri.ytdl.database.models.LogItem
import com.deniscerri.ytdl.database.repository.DownloadRepository import com.deniscerri.ytdl.database.repository.DownloadRepository
import com.deniscerri.ytdl.database.repository.LogRepository import com.deniscerri.ytdl.database.repository.LogRepository
import com.deniscerri.ytdl.util.FileUtil
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.File
class LogViewModel(private val application: Application) : AndroidViewModel(application) { class LogViewModel(private val application: Application) : AndroidViewModel(application) {
private val repository: LogRepository private val repository: LogRepository
@ -55,4 +59,24 @@ class LogViewModel(private val application: Application) : AndroidViewModel(appl
} }
fun exportToFile(id: Long, exported: (File?) -> Unit) = viewModelScope.launch(Dispatchers.IO) {
try{
val log = repository.getLogByID(id)
val dir = File("${FileUtil.getCachePath(application)}/Logs/")
dir.mkdirs()
val tmp = File("${dir.absolutePath}/[YTDLnis Log] ${log!!.title}.txt")
tmp.delete()
tmp.createNewFile()
tmp.writeText(log.content)
val res = withContext(Dispatchers.IO) {
FileUtil.moveFile(tmp.parentFile!!, application, FileUtil.getDefaultApplicationPath() + "/Exported Logs", false) {}
}
exported(File(res[0]))
}catch (e: Exception){
e.printStackTrace()
exported(null)
}
}
} }

View file

@ -79,6 +79,12 @@ class TemplatesAdapter(onItemClickListener: OnItemClickListener, activity: Activ
isVisible = item.preferredCommandTemplate isVisible = item.preferredCommandTemplate
} }
card.findViewById<TextView>(R.id.urlRegex).apply {
isVisible = item.urlRegex.isNotEmpty()
val txt = "URL Regex: ${item.urlRegex.joinToString(", ")}"
text = txt
}
if (checkedItems.contains(item.id)) { if (checkedItems.contains(item.id)) {
card.isChecked = true card.isChecked = true
card.strokeWidth = 5 card.strokeWidth = 5

View file

@ -29,6 +29,7 @@ import com.deniscerri.ytdl.database.viewmodel.LogViewModel
import com.deniscerri.ytdl.util.Extensions.enableFastScroll import com.deniscerri.ytdl.util.Extensions.enableFastScroll
import com.deniscerri.ytdl.util.Extensions.enableTextHighlight import com.deniscerri.ytdl.util.Extensions.enableTextHighlight
import com.deniscerri.ytdl.util.Extensions.setCustomTextSize import com.deniscerri.ytdl.util.Extensions.setCustomTextSize
import com.deniscerri.ytdl.util.FileUtil
import com.deniscerri.ytdl.work.DownloadWorker import com.deniscerri.ytdl.work.DownloadWorker
import com.google.android.material.appbar.MaterialToolbar import com.google.android.material.appbar.MaterialToolbar
import com.google.android.material.bottomappbar.BottomAppBar import com.google.android.material.bottomappbar.BottomAppBar
@ -176,6 +177,23 @@ class DownloadLogFragment : Fragment() {
R.id.text_size -> { R.id.text_size -> {
slider!!.isVisible = !slider.isVisible slider!!.isVisible = !slider.isVisible
} }
R.id.export_file -> {
logViewModel.exportToFile(logID!!) {f ->
if (f == null){
Snackbar.make(bottomAppBar, getString(R.string.couldnt_parse_file), Snackbar.LENGTH_LONG)
.setAnchorView(bottomAppBar)
.show()
}else{
val snack = Snackbar.make(bottomAppBar, getString(R.string.backup_created_successfully), Snackbar.LENGTH_LONG)
snack.setAnchorView(bottomAppBar)
snack.setAction(R.string.share) {
FileUtil.shareFileIntent(requireContext(), listOf(f.absolutePath))
}
snack.show()
}
}
}
} }
true true
} }
@ -248,8 +266,9 @@ class DownloadLogFragment : Fragment() {
fun onDownloadProgressEvent(event: DownloadWorker.WorkerProgress) { fun onDownloadProgressEvent(event: DownloadWorker.WorkerProgress) {
val progressBar = requireView().findViewById<LinearProgressIndicator>(R.id.progress) val progressBar = requireView().findViewById<LinearProgressIndicator>(R.id.progress)
if (event.logItemID == logID) { if (event.logItemID == logID) {
progressBar.isVisible = true progressBar.isVisible = event.progress < 100
progressBar.setProgress(event.progress, true) progressBar.setProgress(event.progress, true)
progressBar.isIndeterminate = event.progress == 0
} }
} }

View file

@ -217,17 +217,24 @@ class MainSettingsFragment : PreferenceFragmentCompat() {
} }
val currentTime = Calendar.getInstance() val currentTime = Calendar.getInstance()
val saveFile = File( val dir = File("${FileUtil.getCachePath(requireContext())}/Backups")
Environment.getExternalStoragePublicDirectory( dir.mkdirs()
Environment.DIRECTORY_DOWNLOADS), "YTDLnis_${BuildConfig.VERSION_NAME}_${currentTime.get(
Calendar.YEAR)}-${currentTime.get(Calendar.MONTH) + 1}-${currentTime.get( val saveFile = File("${dir.absolutePath}/YTDLnis_Backup_${BuildConfig.VERSION_NAME}_${currentTime.get(
Calendar.DAY_OF_MONTH)} [${currentTime.get(Calendar.MILLISECOND)}.json") Calendar.YEAR)}-${currentTime.get(Calendar.MONTH) + 1}-${currentTime.get(
Calendar.DAY_OF_MONTH)}_${currentTime.get(Calendar.HOUR_OF_DAY)}-${currentTime.get(Calendar.MINUTE)}-${currentTime.get(Calendar.SECOND)}.json")
saveFile.delete() saveFile.delete()
saveFile.createNewFile() saveFile.createNewFile()
saveFile.writeText(GsonBuilder().setPrettyPrinting().create().toJson(json)) saveFile.writeText(GsonBuilder().setPrettyPrinting().create().toJson(json))
val res = withContext(Dispatchers.IO) {
FileUtil.moveFile(saveFile.parentFile!!, requireContext(), FileUtil.getDefaultApplicationPath() + "/Backups", false) {}
}
val s = Snackbar.make(requireView(), getString(R.string.backup_created_successfully), Snackbar.LENGTH_LONG) val s = Snackbar.make(requireView(), getString(R.string.backup_created_successfully), Snackbar.LENGTH_LONG)
s.setAction(R.string.Open_File){ s.setAction(R.string.Open_File){
FileUtil.openFileIntent(requireActivity(), saveFile.absolutePath) FileUtil.openFileIntent(requireActivity(), res[0])
} }
s.show() s.show()
} }

View file

@ -324,6 +324,10 @@ object FileUtil {
return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)?.absolutePath + File.separator + "YTDLnis/Command" return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)?.absolutePath + File.separator + "YTDLnis/Command"
} }
fun getDefaultApplicationPath() : String {
return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)?.absolutePath + File.separator + "YTDLnis"
}
fun getDownloadArchivePath(context: Context) : String { fun getDownloadArchivePath(context: Context) : String {
var folder = PreferenceManager.getDefaultSharedPreferences(context).getString("download_archive_path", "")!! var folder = PreferenceManager.getDefaultSharedPreferences(context).getString("download_archive_path", "")!!
if (folder == "") { if (folder == "") {

View file

@ -475,7 +475,7 @@ class YTDLPUtil(private val context: Context, private val commandTemplateDao: Co
formatProper.format_note = format.getString("format_note") formatProper.format_note = format.getString("format_note")
}else{ }else{
if (!formatProper.format_note.endsWith("audio", true)){ if (!formatProper.format_note.endsWith("audio", true)){
formatProper.format_note = format.getString("format_note").uppercase().removeSuffix("AUDIO") + " AUDIO" formatProper.format_note = format.getString("format_note").uppercase().removeSuffix("AUDIO").trim() + " AUDIO"
} }
} }
@ -902,7 +902,7 @@ class YTDLPUtil(private val context: Context, private val commandTemplateDao: Co
} }
if (usePlaylistMetadata) { if (usePlaylistMetadata) {
metadataCommands.addOption("--parse-metadata", "%(album,playlist_title,playlist|)s:%(album)s") metadataCommands.addOption("--parse-metadata", "%(album,playlist_title,playlist|)s:%(meta_album)s")
} }

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android" <com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/command_card" android:id="@+id/command_card"
android:layout_width="match_parent" android:layout_width="match_parent"
android:checkable="true" android:checkable="true"
@ -46,6 +47,8 @@
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/content" app:layout_constraintTop_toBottomOf="@id/content"
app:layout_constraintHorizontal_bias="0.0" app:layout_constraintHorizontal_bias="0.0"
android:id="@+id/chipGroup"
app:chipSpacing="0dp"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
@ -91,7 +94,7 @@
<TextView <TextView
android:id="@+id/dataFetchingExtraCommands" android:id="@+id/dataFetchingExtraCommands"
style="@style/Widget.Material3.FloatingActionButton.Large.Tertiary" style="@style/Widget.Material3.FloatingActionButton.Large.Secondary"
android:visibility="gone" android:visibility="gone"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -109,10 +112,33 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/urlRegex"
style="@style/Widget.Material3.FloatingActionButton.Large.Tertiary"
android:layout_width="wrap_content"
android:visibility="gone"
android:layout_height="wrap_content"
android:text="URL Regex"
android:background="@drawable/rounded_corner"
android:backgroundTint="?attr/colorTertiaryContainer"
android:clickable="false"
android:gravity="center"
android:minWidth="30dp"
android:paddingHorizontal="5dp"
android:textSize="12sp"
android:textStyle="bold"
app:cornerRadius="10dp"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:ignore="HardcodedText" />
</com.google.android.material.chip.ChipGroup> </com.google.android.material.chip.ChipGroup>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>

View file

@ -40,6 +40,7 @@
android:visibility="gone" android:visibility="gone"
android:layout_width="0dp" android:layout_width="0dp"
android:indeterminate="true" android:indeterminate="true"
app:trackCornerRadius="20dp"
app:trackColor="#000" app:trackColor="#000"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:alpha="0.3" android:alpha="0.3"
@ -136,7 +137,7 @@
android:clickable="false" android:clickable="false"
android:ellipsize="end" android:ellipsize="end"
android:gravity="center" android:gravity="center"
android:maxLength="17" android:maxLength="7"
android:minWidth="30dp" android:minWidth="30dp"
android:paddingHorizontal="5dp" android:paddingHorizontal="5dp"
android:textStyle="bold" android:textStyle="bold"

View file

@ -21,5 +21,11 @@
android:icon="@drawable/ic_textformat" android:icon="@drawable/ic_textformat"
app:showAsAction="always" /> app:showAsAction="always" />
<item
android:id="@+id/export_file"
android:title="@string/export_file"
android:icon="@drawable/baseline_save_24"
app:showAsAction="always" />
</menu> </menu>