Skip to content

Commit

Permalink
FIXES
Browse files Browse the repository at this point in the history
1.The videos are not visible on the home screen, but they are visible on the same server in libretube.

2.Open download card late on YouTube.

3.When you enter the end time or a higher value there and confirm, the application is closed and the error..

4.The home page player and cut player do not open. When the cut player opens, the video often stops

5.The cutting player does not do its work exactly.
  • Loading branch information
deniscerri committed Jul 30, 2023
1 parent 8a42b3f commit 444f0cc
Show file tree
Hide file tree
Showing 18 changed files with 185 additions and 74 deletions.
2 changes: 1 addition & 1 deletion 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 = 3
def versionBuild = 15 // bump for dogfood builds, public betas, etc.
def versionBuild = 17 // bump for dogfood builds, public betas, etc.
def versionExt = ""

if (versionBuild > 0){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import java.io.File
import java.util.Locale
import java.util.UUID
import java.util.concurrent.TimeUnit
import kotlin.random.Random
import kotlin.random.nextInt


class DownloadViewModel(application: Application) : AndroidViewModel(application) {
Expand Down Expand Up @@ -149,7 +152,13 @@ class DownloadViewModel(application: Application) : AndroidViewModel(application
}

suspend fun updateDownload(item: DownloadItem){
repository.update(item)
if (sharedPreferences.getBoolean("incognito", false)){
if (item.status == DownloadRepository.Status.Cancelled.toString() || item.status == DownloadRepository.Status.Error.toString()){
repository.delete(item)
}
}else{
repository.update(item)
}
}

fun getItemByID(id: Long) : DownloadItem {
Expand Down Expand Up @@ -485,6 +494,8 @@ class DownloadViewModel(application: Application) : AndroidViewModel(application
if (it.status != DownloadRepository.Status.Paused.toString()) it.status = DownloadRepository.Status.Queued.toString()
if (activeAndQueuedDownloads.firstOrNull{d ->
d.id = 0
d.logID = null
d.customFileNameTemplate = it.customFileNameTemplate
d.status = DownloadRepository.Status.Queued.toString()
d.toString() == it.toString()
} != null) {
Expand All @@ -506,6 +517,9 @@ class DownloadViewModel(application: Application) : AndroidViewModel(application
Toast.makeText(context, context.getString(R.string.download_already_exists), Toast.LENGTH_LONG).show()
}
}

val workManager = WorkManager.getInstance(context)

queuedItems.forEach {
val currentTime = System.currentTimeMillis()
var delay = if (it.downloadStartTime != 0L){
Expand All @@ -518,19 +532,20 @@ class DownloadViewModel(application: Application) : AndroidViewModel(application

val workRequest = OneTimeWorkRequestBuilder<DownloadWorker>()
.setInputData(Data.Builder().putLong("id", it.id).build())
.addTag(it.id.toString())
.addTag("download")
.setConstraints(workConstraints.build())
.setInitialDelay(delay, TimeUnit.SECONDS)
.build()

WorkManager.getInstance(context).beginUniqueWork(
it.id.toString(),
ExistingWorkPolicy.KEEP,
workManager.enqueueUniqueWork(
Random.nextInt(1000000000).toString(),
ExistingWorkPolicy.REPLACE,
workRequest
).enqueue()

)
}


val isCurrentNetworkMetered = (context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager).isActiveNetworkMetered
if (!allowMeteredNetworks && isCurrentNetworkMetered){
Looper.prepare().run {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ class CancelDownloadNotificationReceiver : BroadcastReceiver() {
val message = intent.getStringExtra("cancel")
val id = intent.getIntExtra("workID", 0)
if (message != null) {
val notificationUtil = NotificationUtil(c)
notificationUtil.cancelDownloadNotification(id)
YoutubeDL.getInstance().destroyProcessById(id.toString())
runCatching {
val notificationUtil = NotificationUtil(c)
notificationUtil.cancelDownloadNotification(id)
YoutubeDL.getInstance().destroyProcessById(id.toString())

val dbManager = DBManager.getInstance(c)
CoroutineScope(Dispatchers.IO).launch{
val item = dbManager.downloadDao.getDownloadById(id.toLong())
item.status = DownloadRepository.Status.Cancelled.toString()
dbManager.downloadDao.update(item)
val dbManager = DBManager.getInstance(c)
CoroutineScope(Dispatchers.IO).launch{
val item = dbManager.downloadDao.getDownloadById(id.toLong())
item.status = DownloadRepository.Status.Cancelled.toString()
dbManager.downloadDao.update(item)
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ class PauseDownloadNotificationReceiver : BroadcastReceiver() {
override fun onReceive(c: Context, intent: Intent) {
val id = intent.getIntExtra("workID", 0)
if (id != 0) {
val title = intent.getStringExtra("title")
val notificationUtil = NotificationUtil(c)
notificationUtil.cancelDownloadNotification(id)
YoutubeDL.getInstance().destroyProcessById(id.toString())
notificationUtil.createResumeDownload(id, title, NotificationUtil.DOWNLOAD_SERVICE_CHANNEL_ID)
runCatching {
val title = intent.getStringExtra("title")
val notificationUtil = NotificationUtil(c)
notificationUtil.cancelDownloadNotification(id)
YoutubeDL.getInstance().destroyProcessById(id.toString())
notificationUtil.createResumeDownload(id, title, NotificationUtil.DOWNLOAD_SERVICE_CHANNEL_ID)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.content.Context
import android.content.DialogInterface
import android.content.Intent
import android.content.SharedPreferences
import android.graphics.Color
import android.os.Bundle
import android.util.DisplayMetrics
import android.view.LayoutInflater
Expand All @@ -26,10 +27,14 @@ import com.deniscerri.ytdlnis.util.UiUtil
import com.google.android.material.bottomappbar.BottomAppBar
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.neo.highlight.core.Highlight
import com.neo.highlight.util.listener.HighlightTextWatcher
import com.neo.highlight.util.scheme.ColorScheme
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.util.*
import java.util.regex.Pattern


class AddExtraCommandsDialog(private val item: DownloadItem, private val callback: ExtraCommandsListener) : BottomSheetDialogFragment() {
Expand Down Expand Up @@ -81,11 +86,32 @@ class AddExtraCommandsDialog(private val item: DownloadItem, private val callbac
val text = view.findViewById<EditText>(R.id.command)
val templates = view.findViewById<Button>(R.id.commands)
val shortcuts = view.findViewById<Button>(R.id.shortcuts)
val currentCommand = infoUtil.buildYoutubeDLRequest(item).buildCommand().joinToString(" ")
view.findViewById<TextView>(R.id.currentText)?.text = currentCommand
val currentCommand = infoUtil.parseYTDLRequestString(infoUtil.buildYoutubeDLRequest(item))
val currentText = view.findViewById<TextView>(R.id.currentText)
currentText?.text = currentCommand


//init syntax highlighter
val highlight = Highlight()
val highlightWatcher = HighlightTextWatcher()

val schemes = listOf(
ColorScheme(Pattern.compile("([\"'])(?:\\\\1|.)*?\\1"), Color.parseColor("#FC8500")),
ColorScheme(Pattern.compile("yt-dlp"), Color.parseColor("#00FF00")),
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"))
)

highlight.addScheme(
*schemes.map { it }.toTypedArray()
)
highlightWatcher.addScheme(
*schemes.map { it }.toTypedArray()
)
highlight.setSpan(currentText)
currentText.addTextChangedListener(highlightWatcher)

text?.setText(item.extraCommands)

val imm = activity?.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
text!!.postDelayed({
text.setSelection(text.length())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,21 @@ import android.graphics.Color
import android.net.Uri
import android.os.Bundle
import android.util.DisplayMetrics
import android.util.Range
import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View
import android.widget.*
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.children
import androidx.lifecycle.lifecycleScope
import androidx.media3.common.AudioAttributes
import androidx.media3.common.C
import androidx.media3.common.MediaItem.fromUri
import androidx.media3.common.Player
import androidx.media3.datasource.DefaultDataSource
import androidx.media3.datasource.cronet.CronetDataSource
import androidx.media3.exoplayer.DefaultLoadControl
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.exoplayer.source.DefaultMediaSourceFactory
import androidx.media3.exoplayer.source.MediaSource
import androidx.media3.exoplayer.source.MergingMediaSource
import androidx.media3.exoplayer.trackselection.DefaultTrackSelector
import androidx.media3.ui.PlayerView
import com.deniscerri.ytdlnis.App
import com.deniscerri.ytdlnis.R
import com.deniscerri.ytdlnis.database.models.ChapterItem
import com.deniscerri.ytdlnis.database.models.DownloadItem
Expand All @@ -54,14 +47,12 @@ import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.chromium.net.CronetEngine
import java.lang.reflect.Type
import java.util.*
import java.util.concurrent.Executors
import kotlin.properties.Delegates


class CutVideoBottomSheetDialog(private val item: DownloadItem, private var urls : String?, private var chapters: List<ChapterItem>?, private val listener: VideoCutListener) : BottomSheetDialogFragment() {
class CutVideoBottomSheetDialog(private val item: DownloadItem, private val urls : String?, private var chapters: List<ChapterItem>?, private val listener: VideoCutListener) : BottomSheetDialogFragment() {
private lateinit var behavior: BottomSheetBehavior<View>
private lateinit var infoUtil: InfoUtil
private lateinit var player: ExoPlayer
Expand Down Expand Up @@ -279,7 +270,7 @@ class CutVideoBottomSheetDialog(private val item: DownloadItem, private var urls
toTextInput.editText!!.setTextAndRecalculateWidth(endTimestampString)


okBtn.isEnabled = !(values[0] == 0F && values[1] == 100F)
okBtn.isEnabled = values[0] != 0F && values[1] != 100F

try {
player.seekTo((startTimestamp * 1000).toLong())
Expand All @@ -294,26 +285,29 @@ class CutVideoBottomSheetDialog(private val item: DownloadItem, private var urls
if ((event!!.action == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER)) {

val startTimestamp = (rangeSlider.valueFrom.toInt() * timeSeconds) / 100
var startTimestamp = (rangeSlider.valueFrom.toInt() * timeSeconds) / 100
val endTimestamp = (rangeSlider.valueTo.toInt() * timeSeconds) / 100

fromTextInput.editText!!.clearFocus()
val seconds = convertStringToTimestamp(fromTextInput.editText!!.text.toString())
var seconds = convertStringToTimestamp(fromTextInput.editText!!.text.toString())
val endSeconds = convertStringToTimestamp(toTextInput.editText!!.text.toString())

val startValue = (seconds.toFloat() / endTimestamp) * 100
var startValue = (seconds.toFloat() / endTimestamp) * 100
val endValue = (endSeconds.toFloat() / endTimestamp) * 100

if (seconds == 0) {
fromTextInput.editText!!.setTextAndRecalculateWidth(infoUtil.formatIntegerDuration(startTimestamp, Locale.US))
}else if (startValue > 100){
startTimestamp = 0
seconds = 0
fromTextInput.editText!!.setTextAndRecalculateWidth(infoUtil.formatIntegerDuration(startTimestamp, Locale.US))
startValue = 0F
}

rangeSlider.setValues(startValue, endValue)
okBtn.isEnabled = !(startValue == 0F && endValue == 100F)
okBtn.isEnabled = startValue != 0F && endValue != 100F
try {
player.seekTo((((startValue * timeSeconds) / 100) * 1000).toLong())
player.seekTo(seconds.toLong() * 1000)
player.play()
}catch (ignored: Exception) {}

Expand All @@ -331,14 +325,19 @@ class CutVideoBottomSheetDialog(private val item: DownloadItem, private var urls
(keyCode == KeyEvent.KEYCODE_ENTER)) {

val values = rangeSlider.values
val endTimestamp = (rangeSlider.valueTo.toInt() * timeSeconds) / 100
var endTimestamp = (rangeSlider.valueTo.toInt() * timeSeconds) / 100

toTextInput.editText!!.clearFocus()
val startSeconds = convertStringToTimestamp(fromTextInput.editText!!.text.toString())
val seconds = convertStringToTimestamp(toTextInput.editText!!.text.toString())

val startValue = (startSeconds.toFloat() / endTimestamp) * 100
val endValue = (seconds.toFloat() / endTimestamp) * 100
var endValue = (seconds.toFloat() / endTimestamp) * 100
if (endValue > 100F){
endTimestamp = timeSeconds
toTextInput.editText!!.setTextAndRecalculateWidth(infoUtil.formatIntegerDuration(endTimestamp, Locale.US))
endValue = 100F
}

if (seconds == 0) {
toTextInput.editText!!.setTextAndRecalculateWidth(infoUtil.formatIntegerDuration(endTimestamp, Locale.US))
Expand All @@ -347,9 +346,9 @@ class CutVideoBottomSheetDialog(private val item: DownloadItem, private var urls
}

rangeSlider.setValues(startValue, endValue)
okBtn.isEnabled = !(startValue == 0F && endValue == 100F)
okBtn.isEnabled = startValue != 0F && endValue != 100F
try {
player.seekTo((((startValue * timeSeconds) / 100) * 1000).toLong())
player.seekTo(startSeconds.toLong() * 1000)
player.play()
}catch (ignored: Exception) {}

Expand Down Expand Up @@ -543,10 +542,8 @@ class CutVideoBottomSheetDialog(private val item: DownloadItem, private var urls

private fun videoProgress(player: ExoPlayer?) = flow {
while (true) {
runCatching {
emit((player!!.currentPosition / 1000).toInt())
delay(1000)
}
emit((player!!.currentPosition / 1000).toInt())
delay(1000)
}
}.flowOn(Dispatchers.Main)

Expand Down Expand Up @@ -587,4 +584,4 @@ class CutVideoBottomSheetDialog(private val item: DownloadItem, private var urls

interface VideoCutListener{
fun onChangeCut(list: List<String>)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ class DownloadMultipleBottomSheetDialog(private var results: List<ResultItem?>,
}
items.forEachIndexed { index, i ->
i.allFormats.clear()
if (formatCollection.isNotEmpty() && formatCollection[index].isNotEmpty()) i.allFormats.addAll(formatCollection[index])
if (formatCollection.size == items.size && formatCollection[index].isNotEmpty()) {
runCatching {
i.allFormats.addAll(formatCollection[index])
}
}
i.format = selectedFormats[index].format
if (i.type == DownloadViewModel.Type.video) selectedFormats[index].audioFormats?.map { it.format_id }?.let { i.videoPreferences.audioFormatIDs.addAll(it) }
}
Expand Down
Loading

0 comments on commit 444f0cc

Please sign in to comment.