Skip to content

Commit

Permalink
feat: display full video sponsorblock categories
Browse files Browse the repository at this point in the history
  • Loading branch information
FineFindus committed Nov 17, 2024
1 parent a67c26a commit 0c5c020
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 3 deletions.
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 @@ -20,4 +20,8 @@ data class Segment(
) {
@Transient
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 @@ -1069,6 +1069,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
?.let {
initializeHighlight(it)
}
binding.descriptionLayout.setSegments(viewModel.segments)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ class PlayerViewModel(
segments =
RetrofitInstance.api.getSegments(
videoId,
JsonHelper.json.encodeToString(sponsorBlockConfig.keys)
JsonHelper.json.encodeToString(sponsorBlockConfig.keys),
"""["skip","mute","full","poi","chapter"]"""
).segments
}
}
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

0 comments on commit 0c5c020

Please sign in to comment.