Skip to content

Commit

Permalink
1.6.8
Browse files Browse the repository at this point in the history
  • Loading branch information
deniscerri committed Oct 29, 2023
1 parent 9c81b87 commit 99b2938
Show file tree
Hide file tree
Showing 14 changed files with 210 additions and 55 deletions.
16 changes: 8 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def properties = new Properties()
def versionMajor = 1
def versionMinor = 6
def versionPatch = 8
def versionBuild = 4 // bump for dogfood builds, public betas, etc.
def versionBuild = 0 // bump for dogfood builds, public betas, etc.
def versionExt = ""

if (versionBuild > 0){
Expand Down Expand Up @@ -130,13 +130,13 @@ dependencies {
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
implementation 'com.google.android.material:material:1.10.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.3.1'
implementation 'androidx.recyclerview:recyclerview:1.3.2'
implementation 'androidx.preference:preference-ktx:1.2.1'
implementation "androidx.navigation:navigation-fragment-ktx:$navVer"
implementation "androidx.navigation:navigation-ui-ktx:$navVer"
implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.test.ext:junit-ktx:1.1.5'
implementation 'androidx.compose.ui:ui-android:1.5.3'
implementation 'androidx.compose.ui:ui-android:1.5.4'
testImplementation "junit:junit:$junitVer"
androidTestImplementation "junit:junit:$junitVer"
androidTestImplementation "androidx.test.ext:junit:$androidJunitVer"
Expand All @@ -154,12 +154,12 @@ dependencies {

implementation "androidx.work:work-runtime-ktx:$workVer"

implementation "androidx.room:room-runtime:2.5.2"
implementation "androidx.room:room-ktx:2.5.2"
ksp "androidx.room:room-compiler:2.5.2"
implementation "androidx.room:room-runtime:$roomVer"
implementation "androidx.room:room-ktx:$roomVer"
ksp "androidx.room:room-compiler:$roomVer"
implementation 'androidx.paging:paging-runtime-ktx:3.2.1'
implementation "androidx.room:room-paging:2.5.2"
androidTestImplementation "androidx.room:room-testing:2.5.2"
implementation "androidx.room:room-paging:$roomVer"
androidTestImplementation "androidx.room:room-testing:$roomVer"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.2'
implementation "androidx.compose.runtime:runtime:$composeVer"
androidTestImplementation 'com.google.truth:truth:1.1.5'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.deniscerri.ytdlnis.database.repository
import com.deniscerri.ytdlnis.database.dao.LogDao
import com.deniscerri.ytdlnis.database.models.LogItem
import kotlinx.coroutines.flow.Flow
import java.util.regex.MatchResult
import java.util.regex.Pattern

class LogRepository(private val logDao: LogDao) {
val items : Flow<List<LogItem>> = logDao.getAllLogsFlow()
Expand Down Expand Up @@ -42,7 +44,22 @@ class LogRepository(private val logDao: LogDao) {
val item = getItem(id)
val log = item.content
//clean duplicate progress + add newline
//item.content = log.replace("(?s:.*\\n)?\\K\\[download\\]( *?)(\\d)(.*?)\\n(?!.*\\[download\\]( *?)(\\d)(.*?)\\n)".toRegex()).replac { it.contains("[download") }.joinToString("\n") + "\n${line}"
val lines = log.split("\n").toMutableList()
run loop@ {
for(i in lines.size - 1 downTo 0){
val l = lines[i]
if(l.contains("\\[download]( *?)(\\d)(.*?)".toRegex())){
lines[i] = ""
return@loop
}
}
}
val l = if (line.contains("[download]")) {
"[download]" + line.split("[download]").last()
}else {
line
}
item.content = lines.filter { it.isNotBlank() }.joinToString("\n") + "\n${l}"
logDao.update(item)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class CancelDownloadNotificationReceiver : BroadcastReceiver() {
val id = intent.getIntExtra("itemID", 0)
if (id > 0) {
runCatching {
Log.e("aa", id.toString())
val notificationUtil = NotificationUtil(c)
YoutubeDL.getInstance().destroyProcessById(id.toString())
notificationUtil.cancelDownloadNotification(id)
Expand All @@ -28,6 +27,9 @@ class CancelDownloadNotificationReceiver : BroadcastReceiver() {
item.status = DownloadRepository.Status.Cancelled.toString()
dbManager.downloadDao.update(item)
}
runCatching {
dbManager.terminalDao.delete(id.toLong())
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,14 @@ class CutVideoBottomSheetDialog(private val item: DownloadItem, private val urls
val currentTime = infoUtil.formatIntegerDuration(p, Locale.US)
durationText.text = "$currentTime / ${item.duration}"
val startTimestamp = convertStringToTimestamp(fromTextInput.editText!!.text.toString())
val endTimestamp = convertStringToTimestamp(toTextInput.editText!!.text.toString())
if (p >= endTimestamp){
player.prepare()
player.seekTo((startTimestamp * 1000).toLong())
if (toTextInput.editText!!.text.isNotBlank()){
val endTimestamp = convertStringToTimestamp(toTextInput.editText!!.text.toString())
if (p >= endTimestamp){
player.prepare()
player.seekTo((startTimestamp * 1000).toLong())
}
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,25 @@ class DownloadBottomSheetDialog(private var result: ResultItem, private val type
initUpdateData(view)
}else {
val usingGenericFormatsOrEmpty = result.formats.isEmpty() || result.formats.any { it.format_note.contains("ytdlnisgeneric") }
if (usingGenericFormatsOrEmpty && sharedPreferences.getBoolean("update_formats", false)){
if (usingGenericFormatsOrEmpty && sharedPreferences.getBoolean("update_formats", false) && !sharedPreferences.getBoolean("quick_download", false)){
initUpdateFormats(result.url)
}
}

CoroutineScope(Dispatchers.IO).launch{
downloadViewModel.uiState.collectLatest { res ->
if (res.errorMessage != null) {
UiUtil.handleDownloadsResponse(requireActivity() as MainActivity, res, downloadViewModel, historyViewModel)
withContext(Dispatchers.Main){
kotlin.runCatching {
UiUtil.handleDownloadsResponse(
requireActivity(),
requireActivity().lifecycleScope,
requireActivity().supportFragmentManager,
res,
downloadViewModel,
historyViewModel)
}
}
downloadViewModel.uiState.value = DownloadViewModel.DownloadsUiState(
errorMessage = null,
actions = null
Expand Down Expand Up @@ -432,7 +442,7 @@ class DownloadBottomSheetDialog(private var result: ResultItem, private val type
parentFragmentManager.addFragmentOnAttachListener { fragmentManager, fragment ->
dismiss()
}
playlistSelect.show(parentFragmentManager, "downloadMultipleSheet")
playlistSelect.show(parentFragmentManager, "downloadPlaylistSheet")
}
}else{
dismiss()
Expand All @@ -441,6 +451,7 @@ class DownloadBottomSheetDialog(private var result: ResultItem, private val type
}
shimmerLoading.setOnClickListener {
updateJob.cancel()
(updateItem.parent as LinearLayout).visibility = View.VISIBLE
}
updateJob.invokeOnCompletion {
requireActivity().runOnUiThread {
Expand All @@ -450,7 +461,6 @@ class DownloadBottomSheetDialog(private var result: ResultItem, private val type
shimmerLoadingSubtitle.visibility = View.GONE
shimmerLoading.stopShimmer()
shimmerLoadingSubtitle.stopShimmer()
(updateItem.parent as LinearLayout).visibility = View.VISIBLE
}
}
updateJob.start()
Expand Down Expand Up @@ -515,11 +525,7 @@ class DownloadBottomSheetDialog(private var result: ResultItem, private val type

private fun cleanUp(){
kotlin.runCatching {
repeat((parentFragmentManager.findFragmentByTag("downloadSingleSheet")?.fragmentManager?.backStackEntryCount?.minus(1))?: 0){
parentFragmentManager.findFragmentByTag("downloadSingleSheet")?.fragmentManager?.popBackStack()
}
parentFragmentManager.beginTransaction().remove(parentFragmentManager.findFragmentByTag("downloadSingleSheet")!!).commit()
if (activity is ShareActivity && !parentFragmentManager.fragments.map { it.tag }.contains("downloadMultipleSheet")){
if (activity is ShareActivity && !parentFragmentManager.fragments.map { it.tag }.contains("downloadPlaylistSheet")){
(activity as ShareActivity).finish()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import com.google.android.material.color.MaterialColors
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
import it.xabaras.android.recyclerview.swipedecorator.RecyclerViewSwipeDecorator
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -507,10 +508,20 @@ class DownloadMultipleBottomSheetDialog(private var items: MutableList<DownloadI
true
}

lifecycleScope.launch {
CoroutineScope(Dispatchers.IO).launch{
downloadViewModel.uiState.collectLatest { res ->
if (res.errorMessage != null) {
UiUtil.handleDownloadsResponse(requireActivity() as MainActivity, res, downloadViewModel, historyViewModel)
withContext(Dispatchers.Main){
kotlin.runCatching {
UiUtil.handleDownloadsResponse(
requireActivity(),
requireActivity().lifecycleScope,
requireActivity().supportFragmentManager,
res,
downloadViewModel,
historyViewModel)
}
}
downloadViewModel.uiState.value = DownloadViewModel.DownloadsUiState(
errorMessage = null,
actions = null
Expand Down Expand Up @@ -560,8 +571,7 @@ class DownloadMultipleBottomSheetDialog(private var items: MutableList<DownloadI

private fun cleanup(){
kotlin.runCatching {
parentFragmentManager.beginTransaction().remove(parentFragmentManager.findFragmentByTag("downloadMultipleSheet")!!).commit()
if (parentFragmentManager.fragments.size == 1){
if (activity is ShareActivity){
(activity as ShareActivity).finish()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ class SelectPlaylistItemsDialog(private val items: List<ResultItem?>, private va
if (checkedResultItems.size == 1){
val resultItem = resultViewModel.getItemByURL(checkedResultItems[0]!!.url)
val bottomSheet = DownloadBottomSheetDialog(resultItem, type)
parentFragmentManager.addFragmentOnAttachListener { fragmentManager, fragment ->
dismiss()
}
bottomSheet.show(parentFragmentManager, "downloadSingleSheet")
}else{
val downloadItems = mutableListOf<DownloadItem>()
Expand All @@ -171,6 +174,9 @@ class SelectPlaylistItemsDialog(private val items: List<ResultItem?>, private va
}

val bottomSheet = DownloadMultipleBottomSheetDialog(downloadItems)
parentFragmentManager.addFragmentOnAttachListener { fragmentManager, fragment ->
dismiss()
}
bottomSheet.show(parentFragmentManager, "downloadMultipleSheet")
}

Expand Down Expand Up @@ -216,10 +222,10 @@ class SelectPlaylistItemsDialog(private val items: List<ResultItem?>, private va

private fun cleanup(){
kotlin.runCatching {
parentFragmentManager.beginTransaction().remove(parentFragmentManager.findFragmentByTag("downloadPlaylistSheet")!!).commit()
}
if (activity is ShareActivity){
(activity as ShareActivity).finishAffinity()
val movedToMultipleOrSingleSheet = parentFragmentManager.fragments.map { it.tag }.contains("downloadMultipleSheet") || parentFragmentManager.fragments.map { it.tag }.contains("downloadSingleSheet")
if (activity is ShareActivity && !movedToMultipleOrSingleSheet){
(activity as ShareActivity).finish()
}
}
}

Expand Down
26 changes: 13 additions & 13 deletions app/src/main/java/com/deniscerri/ytdlnis/util/InfoUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1095,22 +1095,22 @@ class InfoUtil(private val context: Context) {
request.addOption("--write-description")
}

if (downloadItem.playlistTitle.isNotBlank()){
request.addOption("--parse-metadata","${downloadItem.playlistTitle.split("[")[0]}:%(playlist)s")
runCatching {
request.addOption("--parse-metadata",
downloadItem.playlistTitle
.substring(
downloadItem.playlistTitle.indexOf("[") + 1,
downloadItem.playlistTitle.indexOf("]"),
) + ":%(playlist_index)s"
)
}
}

downloadItem.customFileNameTemplate = downloadItem.customFileNameTemplate.replace("%(uploader)s", "%(uploader,channel)s")
}

if (downloadItem.playlistTitle.isNotBlank()){
request.addOption("--parse-metadata","${downloadItem.playlistTitle.split("[")[0]}:%(playlist)s")
runCatching {
request.addOption("--parse-metadata",
downloadItem.playlistTitle
.substring(
downloadItem.playlistTitle.indexOf("[") + 1,
downloadItem.playlistTitle.indexOf("]"),
) + ":%(playlist_index)s"
)
}
}

when(type){
DownloadViewModel.Type.audio -> {
val supportedContainers = context.resources.getStringArray(R.array.audio_containers)
Expand Down
32 changes: 32 additions & 0 deletions app/src/main/java/com/deniscerri/ytdlnis/util/NotificationUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,38 @@ class NotificationUtil(var context: Context) {
e.printStackTrace()
}
}
fun updateTerminalDownloadNotification(
id: Int,
desc: String,
progress: Int,
title: String?,
channel : String
) {

val notificationBuilder = getBuilder(channel)
var contentText = ""
contentText += desc.replace("\\[.*?\\] ".toRegex(), "")

val cancelIntent = Intent(context, CancelDownloadNotificationReceiver::class.java)
cancelIntent.putExtra("itemID", id)
val cancelNotificationPendingIntent = PendingIntent.getBroadcast(
context,
id,
cancelIntent,
PendingIntent.FLAG_IMMUTABLE
)

try {
notificationBuilder.setProgress(100, progress, false)
.setContentTitle(title)
.setStyle(NotificationCompat.BigTextStyle().bigText(contentText))
.clearActions()
.addAction(0, resources.getString(R.string.cancel), cancelNotificationPendingIntent)
notificationManager.notify(id, notificationBuilder.build())
} catch (e: Exception) {
e.printStackTrace()
}
}

fun cancelDownloadNotification(id: Int) {
notificationManager.cancel(id)
Expand Down
12 changes: 5 additions & 7 deletions app/src/main/java/com/deniscerri/ytdlnis/util/UiUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ import androidx.core.view.isVisible
import androidx.documentfile.provider.DocumentFile
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.RecyclerView
import com.afollestad.materialdialogs.utils.MDUtil.getStringArray
import com.deniscerri.ytdlnis.MainActivity
import com.deniscerri.ytdlnis.R
import com.deniscerri.ytdlnis.database.models.CommandTemplate
import com.deniscerri.ytdlnis.database.models.DownloadItem
Expand Down Expand Up @@ -1341,7 +1339,7 @@ object UiUtil {

private var textHighLightSchemes = listOf(
ColorScheme(Pattern.compile("([\"'])(?:\\\\1|.)*?\\1"), Color.parseColor("#FC8500")),
ColorScheme(Pattern.compile("yt-dlp"), Color.parseColor("#FF0000")),
ColorScheme(Pattern.compile("yt-dlp"), Color.parseColor("#77eb09")),
ColorScheme(Pattern.compile("(https?://(?:www\\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\\.[^\\s]{2,}|www\\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\\.[^\\s]{2,}|https?://(?:www\\.|(?!www))[a-zA-Z0-9]+\\.[^\\s]{2,}|www\\.[a-zA-Z0-9]+\\.[^\\s]{2,})"), Color.parseColor("#b5942f")),
ColorScheme(Pattern.compile("\\d+(\\.\\d)?%"), Color.parseColor("#43a564"))
)
Expand Down Expand Up @@ -1407,7 +1405,7 @@ object UiUtil {
}

@SuppressLint("SetTextI18n")
fun handleDownloadsResponse(context: MainActivity, it: DownloadViewModel.DownloadsUiState, downloadViewModel: DownloadViewModel, historyViewModel: HistoryViewModel){
fun handleDownloadsResponse(context: Activity, lifecycleScope: CoroutineScope, supportFragmentManager: FragmentManager, it: DownloadViewModel.DownloadsUiState, downloadViewModel: DownloadViewModel, historyViewModel: HistoryViewModel){
val downloadAnywayAction = it.actions?.first { it.second == DownloadViewModel.DownloadsAction.DOWNLOAD_ANYWAY}
if (downloadAnywayAction != null){
if (downloadAnywayAction.third == null) return
Expand Down Expand Up @@ -1454,7 +1452,7 @@ object UiUtil {
resultItemID: Long,
item: DownloadItem
) {
context.lifecycleScope.launch {
lifecycleScope.launch {
val idx = downloads.indexOfFirst { it.id == item.id }
downloads[idx] = item
withContext(Dispatchers.Main){
Expand All @@ -1464,7 +1462,7 @@ object UiUtil {
}
}
val bottomSheet = ConfigureDownloadBottomSheetDialog(resultItem, downloadItem, onItemUpdated)
bottomSheet.show(context.supportFragmentManager, "configureDownloadSingleSheet")
bottomSheet.show(supportFragmentManager, "configureDownloadSingleSheet")
}

if (historyItem != null){
Expand Down Expand Up @@ -1507,7 +1505,7 @@ object UiUtil {
}

errDialog.setNegativeButton(R.string.schedule) { d:DialogInterface?, _:Int ->
showDatePicker(context.supportFragmentManager) { calendar ->
showDatePicker(supportFragmentManager) { calendar ->
CoroutineScope(Dispatchers.IO).launch {
val items = mutableListOf<DownloadItem>()
linearLayout.children.forEach {view ->
Expand Down
Loading

0 comments on commit 99b2938

Please sign in to comment.