diff --git a/app/src/main/java/com/github/libretube/api/obj/Segment.kt b/app/src/main/java/com/github/libretube/api/obj/Segment.kt index 7b5cfed2d..95410f2ae 100644 --- a/app/src/main/java/com/github/libretube/api/obj/Segment.kt +++ b/app/src/main/java/com/github/libretube/api/obj/Segment.kt @@ -12,7 +12,8 @@ data class Segment( val segment: List = listOf(), val userID: String? = null, val videoDuration: Double? = null, - val votes: Int? = null + val votes: Int? = null, + var skipped: Boolean = false ) { val segmentStartAndEnd = segment[0] to segment[1] } diff --git a/app/src/main/java/com/github/libretube/enums/SbSkipOptions.kt b/app/src/main/java/com/github/libretube/enums/SbSkipOptions.kt index e94947c46..e923cdf96 100644 --- a/app/src/main/java/com/github/libretube/enums/SbSkipOptions.kt +++ b/app/src/main/java/com/github/libretube/enums/SbSkipOptions.kt @@ -4,5 +4,6 @@ enum class SbSkipOptions { OFF, VISIBLE, MANUAL, - AUTOMATIC + AUTOMATIC, + AUTOMATIC_ONCE } diff --git a/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt b/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt index d827da78b..ec949518e 100644 --- a/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt @@ -484,7 +484,7 @@ object PlayerHelper { context: Context, segments: List, sponsorBlockConfig: MutableMap - ): Long? { + ): Segment? { for (segment in segments.filter { it.category != SPONSOR_HIGHLIGHT_CATEGORY }) { val (start, end) = segment.segmentStartAndEnd val (segmentStart, segmentEnd) = (start * 1000f).toLong() to (end * 1000f).toLong() @@ -493,7 +493,12 @@ object PlayerHelper { if ((duration - currentPosition).absoluteValue < 500) continue if (currentPosition in segmentStart until segmentEnd) { - if (sponsorBlockConfig[segment.category] == SbSkipOptions.AUTOMATIC) { + if (sponsorBlockConfig[segment.category] == SbSkipOptions.AUTOMATIC || + ( + sponsorBlockConfig[segment.category] == SbSkipOptions.AUTOMATIC_ONCE && + segment.skipped == false + ) + ) { if (sponsorBlockNotifications) { runCatching { Toast.makeText(context, R.string.segment_skipped, Toast.LENGTH_SHORT) @@ -501,8 +506,14 @@ object PlayerHelper { } } seekTo(segmentEnd) - } else if (sponsorBlockConfig[segment.category] == SbSkipOptions.MANUAL) { - return segmentEnd + segment.skipped = true + } else if (sponsorBlockConfig[segment.category] == SbSkipOptions.MANUAL || + ( + sponsorBlockConfig[segment.category] == SbSkipOptions.AUTOMATIC_ONCE && + segment.skipped == true + ) + ) { + return segment } } } diff --git a/app/src/main/java/com/github/libretube/services/DownloadService.kt b/app/src/main/java/com/github/libretube/services/DownloadService.kt index 35e7a1725..8922ceecd 100644 --- a/app/src/main/java/com/github/libretube/services/DownloadService.kt +++ b/app/src/main/java/com/github/libretube/services/DownloadService.kt @@ -40,6 +40,18 @@ import com.github.libretube.receivers.NotificationReceiver.Companion.ACTION_DOWN import com.github.libretube.receivers.NotificationReceiver.Companion.ACTION_DOWNLOAD_RESUME import com.github.libretube.receivers.NotificationReceiver.Companion.ACTION_DOWNLOAD_STOP import com.github.libretube.ui.activities.MainActivity +import java.io.File +import java.net.HttpURLConnection +import java.net.SocketTimeoutException +import java.net.URL +import java.nio.file.Path +import java.nio.file.StandardOpenOption +import java.util.concurrent.Executors +import kotlin.io.path.absolute +import kotlin.io.path.createFile +import kotlin.io.path.deleteIfExists +import kotlin.io.path.fileSize +import kotlin.math.min import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -54,18 +66,6 @@ import kotlinx.coroutines.withContext import okio.buffer import okio.sink import okio.source -import java.io.File -import java.net.HttpURLConnection -import java.net.SocketTimeoutException -import java.net.URL -import java.nio.file.Path -import java.nio.file.StandardOpenOption -import java.util.concurrent.Executors -import kotlin.io.path.absolute -import kotlin.io.path.createFile -import kotlin.io.path.deleteIfExists -import kotlin.io.path.fileSize -import kotlin.math.min /** * Download service with custom implementation of downloading using [HttpURLConnection]. @@ -205,7 +205,7 @@ class DownloadService : LifecycleService() { notificationBuilder .setContentText( totalRead.formatAsFileSize() + " / " + - item.downloadSize.formatAsFileSize() + item.downloadSize.formatAsFileSize() ) .setProgress( item.downloadSize.toInt(), diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt index b1b75396a..af54ea881 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt @@ -676,11 +676,12 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { if (!sponsorBlockEnabled || segments.isEmpty()) return exoPlayer.checkForSegments(requireContext(), segments, sponsorBlockConfig) - ?.let { segmentEnd -> + ?.let { segment -> if (viewModel.isMiniPlayerVisible.value == true) return@let binding.sbSkipBtn.isVisible = true binding.sbSkipBtn.setOnClickListener { - exoPlayer.seekTo(segmentEnd) + exoPlayer.seekTo((segment.segmentStartAndEnd.second * 1000f).toLong()) + segment.skipped = true } return } diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml index 5c3e34ace..6ac4587d2 100644 --- a/app/src/main/res/values/array.xml +++ b/app/src/main/res/values/array.xml @@ -446,6 +446,7 @@ @string/visible @string/manual @string/automatic + @string/automatic_once @@ -453,6 +454,7 @@ visible manual automatic + automatic_once diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index aad505270..05a9113eb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -430,6 +430,7 @@ Off Manual Automatic + Automatic once Show in seek bar Fallback to Piped proxy Load videos via the proxy if connecting to YouTube directly doesn\'t work for the current video (increases the initial loading times). If disabled, YouTube music content likely won\'t play due to YT restrictions.