Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/src/main/java/com/github/libretube/api/PipedApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ interface PipedApi {
@GET("sponsors/{videoId}")
suspend fun getSegments(
@Path("videoId") videoId: String,
@Query("category") category: String
@Query("category") category: String,
@Query("actionType") actionType: String? = null
): SegmentData

@GET("dearrow")
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/github/libretube/api/obj/Segment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ data class Segment(
@Transient
@IgnoredOnParcel
val segmentStartAndEnd = FloatFloatPair(segment[0], segment[1])

companion object {
const val TYPE_FULL = "full"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ object PlayerHelper {
*/
private val sbDefaultValues = mapOf(
"sponsor" to SbSkipOptions.AUTOMATIC,
"selfpromo" to SbSkipOptions.AUTOMATIC
"selfpromo" to SbSkipOptions.AUTOMATIC,
"exclusive_access" to SbSkipOptions.AUTOMATIC,
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ open class OnlinePlayerService : AbstractPlayerService() {
if (sponsorBlockConfig.isEmpty()) return@runCatching
sponsorBlockSegments = RetrofitInstance.api.getSegments(
videoId,
JsonHelper.json.encodeToString(sponsorBlockConfig.keys)
JsonHelper.json.encodeToString(sponsorBlockConfig.keys),
"""["skip","mute","full","poi","chapter"]"""
).segments

withContext(Dispatchers.Main) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
val segments: List<Segment>? = mediaMetadata.extras?.parcelableList(IntentData.segments)
viewModel.segments = segments.orEmpty()

binding.descriptionLayout.setSegments(viewModel.segments)
playerBinding.exoProgress.setSegments(viewModel.segments)
playerBinding.sbToggle.isVisible = true
viewModel.segments.firstOrNull { it.category == PlayerHelper.SPONSOR_HIGHLIGHT_CATEGORY }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager
import com.github.libretube.R
import com.github.libretube.api.obj.Segment
import com.github.libretube.api.obj.Streams
import com.github.libretube.databinding.DescriptionLayoutBinding
import com.github.libretube.enums.SbSkipOptions
import com.github.libretube.extensions.formatShort
import com.github.libretube.helpers.ClipboardHelper
import com.github.libretube.helpers.PlayerHelper
import com.github.libretube.ui.activities.VideoTagsAdapter
import com.github.libretube.util.HtmlParser
import com.github.libretube.util.LinkHandler
Expand All @@ -40,6 +43,23 @@ class DescriptionLayout(
}
}

fun setSegments(segments: List<Segment>) {
if (PlayerHelper.getSponsorBlockCategories()[SB_SPONSOR_CATEGORY] == SbSkipOptions.OFF) {
// only show the badge if the user requested to show sponsors
return
}

val segment = segments.filter { it.actionType == Segment.TYPE_FULL }.firstNotNullOfOrNull {
when (it.category) {
"sponsor" -> context.getString(R.string.category_sponsor)
"exclusive_access" -> context.getString(R.string.category_exclusive_access)
else -> null
}
}
binding.playerSponsorBadge.isVisible = segment != null
binding.playerSponsorBadge.text = segment
}

@SuppressLint("SetTextI18n")
fun setStreams(streams: Streams) {
this.streams = streams
Expand Down Expand Up @@ -149,5 +169,6 @@ class DescriptionLayout(

companion object {
private const val ANIMATION_DURATION = 250L
private const val SB_SPONSOR_CATEGORY = "sponsor_category"
}
}
17 changes: 17 additions & 0 deletions app/src/main/res/layout/description_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@
android:orientation="vertical"
android:paddingVertical="12dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal"
android:paddingHorizontal="12dp">

<com.google.android.material.chip.Chip
android:id="@+id/player_sponsor_badge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checkable="false"
android:visibility="gone"
android:text="Sponsor"/>

</LinearLayout>

<LinearLayout
android:id="@+id/player_title_layout"
android:layout_width="match_parent"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@
<item>filler</item>
<item>music_offtopic</item>
<item>preview</item>
<item>exclusive_access</item>
</string-array>

<string-array name="sponsorBlockSegmentNames">
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
<string name="category_preview_summary">For segments detailing future content without additional info. If it includes clips that only appear here, this is very likely the wrong category</string>
<string name="category_highlight">Show video highlight</string>
<string name="category_highlight_summary">Could either be the advertised title, the thumbnail or the most interesting part of the video. You can skip to it by tapping on it in the chapters section</string>
<string name="category_exclusive_access">Exclusive Access</string>
<string name="license">License</string>
<string name="color_accent">Accents</string>
<string name="color_red">Resting red</string>
Expand Down
Loading