Skip to content

Commit

Permalink
✨ feat(YouTube): Improve YouTube Music scraping reliability
Browse files Browse the repository at this point in the history
🐛 fix(YouTube): Handle various client responses for signature
✨ feat(UI): Add share button to modal bottom sheet
🐛 fix(Player): Fix orientation issues in fullscreen mode
🐛 fix(Repository): Update visitor data after cookie change
✨ feat(version): Bump version to 0.2.9
🐛 fix(UI): Improve Video
  • Loading branch information
maxrave-dev committed Jan 19, 2025
1 parent 914ce48 commit f502493
Show file tree
Hide file tree
Showing 14 changed files with 380 additions and 285 deletions.
9 changes: 8 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@
public static int i(...);
public static int d(...);
public static int v(...);
}
}
# Please add these rules to your existing keep rules in order to suppress warning
# This is generated automatically by the Android Gradle plugin.
-dontwarn java.beans.BeanDescriptor
-dontwarn java.beans.BeanInfo
-dontwarn java.beans.IntrospectionException
-dontwarn java.beans.Introspector
-dontwarn java.beans.PropertyDescriptor
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ class MainRepository(
dataStoreManager.cookie.distinctUntilChanged().collectLatest { cookie ->
if (cookie.isNotEmpty()) {
youTube.cookie = cookie
youTube.visitorData()?.let {
youTube.visitorData = it
}
} else {
youTube.cookie = null
}
Expand Down
31 changes: 19 additions & 12 deletions app/src/main/java/com/maxrave/simpmusic/extension/UIExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -490,15 +490,17 @@ fun Context.findActivity(): ComponentActivity {
}

@Composable
fun PipListenerPreAPI12() {
fun PipListenerPreAPI12(isInFullscreen: Boolean) {
// [START android_compose_pip_pre12_listener]
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
val context = LocalContext.current
DisposableEffect(context) {
val onUserLeaveBehavior: () -> Unit = {
context
.findActivity()
.enterPictureInPictureMode(PictureInPictureParams.Builder().build())
if (isInFullscreen) {
context
.findActivity()
.enterPictureInPictureMode(PictureInPictureParams.Builder().build())
}
}
context.findActivity().addOnUserLeaveHintListener(
onUserLeaveBehavior,
Expand All @@ -518,20 +520,25 @@ fun PipListenerPreAPI12() {
/**
* Android 12 and above Picture in Picture mode
*/
fun Modifier.pipModifier(context: Context) =
this.onGloballyPositioned { layoutCoordinates ->
val builder = PictureInPictureParams.Builder()
fun Modifier.pipModifier(
context: Context,
isInFullscreen: Boolean,
) = this.onGloballyPositioned { layoutCoordinates ->
val builder = PictureInPictureParams.Builder()
Log.d("PiP", "isInFullscreen: $isInFullscreen")
if (isInFullscreen) {
val sourceRect = layoutCoordinates.boundsInWindow().toAndroidRectF().toRect()
builder.setSourceRectHint(sourceRect)
builder.setAspectRatio(
Rational(16, 9),
)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
builder.setAutoEnterEnabled(true)
}
Log.w("PiP info", "layoutCoordinates: $layoutCoordinates")
context.findActivity().setPictureInPictureParams(builder.build())
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
builder.setAutoEnterEnabled(isInFullscreen)
}
Log.w("PiP info", "layoutCoordinates: $layoutCoordinates")
context.findActivity().setPictureInPictureParams(builder.build())
}

@RequiresOptIn(
level = RequiresOptIn.Level.WARNING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,6 @@ class SimpleMediaServiceHandler(
}

fun getRelated(videoId: String) {
// Queue.clear()
coroutineScope.launch {
mainRepository.getRelatedData(videoId).collect { response ->
when (response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ package com.maxrave.simpmusic.ui.component
import android.os.Bundle
import android.widget.Toast
import androidx.compose.animation.Crossfade
import androidx.compose.foundation.MarqueeAnimationMode
import androidx.compose.foundation.basicMarquee
import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.fillMaxWidth
Expand Down Expand Up @@ -100,8 +104,9 @@ fun LibraryItem(
)
}
Column {
Box(
Row(
modifier = Modifier.padding(top = 15.dp, start = 10.dp, end = 10.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Text(
text = title,
Expand All @@ -111,13 +116,17 @@ fun LibraryItem(
Modifier
.fillMaxWidth()
.height(35.dp)
.align(Alignment.CenterStart),
.wrapContentHeight(align = Alignment.CenterVertically)
.weight(1f)
.basicMarquee(
iterations = Int.MAX_VALUE,
animationMode = MarqueeAnimationMode.Immediately,
).focusable(),
)
if (state.type is LibraryItemType.LocalPlaylist || state.type is LibraryItemType.YouTubePlaylist) {
TextButton(
modifier =
Modifier
.align(Alignment.CenterEnd)
.defaultMinSize(minWidth = 1.dp, minHeight = 1.dp),
onClick = {
if (state.type is LibraryItemType.LocalPlaylist) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.maxrave.simpmusic.ui.component

import android.os.Build
import android.util.Log
import android.view.TextureView
import androidx.compose.animation.Crossfade
Expand Down Expand Up @@ -29,6 +28,7 @@ import androidx.compose.ui.viewinterop.AndroidView
import androidx.media3.common.C
import androidx.media3.common.MediaItem
import androidx.media3.common.Player
import androidx.media3.common.Tracks
import androidx.media3.common.VideoSize
import androidx.media3.common.util.UnstableApi
import androidx.media3.datasource.DefaultDataSource
Expand All @@ -46,9 +46,7 @@ import coil3.request.crossfade
import coil3.toCoilUri
import com.maxrave.simpmusic.common.Config
import com.maxrave.simpmusic.extension.KeepScreenOn
import com.maxrave.simpmusic.extension.PipListenerPreAPI12
import com.maxrave.simpmusic.extension.getScreenSizeInfo
import com.maxrave.simpmusic.extension.pipModifier
import org.koin.compose.koinInject
import org.koin.core.qualifier.named
import kotlin.math.roundToInt
Expand Down Expand Up @@ -169,9 +167,7 @@ fun MediaPlayerView(
fun MediaPlayerView(
player: ExoPlayer,
modifier: Modifier = Modifier,
pipSupport: Boolean = false,
) {
val context = LocalContext.current
var videoRatio by rememberSaveable {
mutableFloatStateOf(16f / 9)
}
Expand All @@ -184,28 +180,30 @@ fun MediaPlayerView(
mutableStateOf(false)
}

if (pipSupport) {
PipListenerPreAPI12()
}

val playerListener =
remember {
object : Player.Listener {
override fun onVideoSizeChanged(videoSize: VideoSize) {
super.onVideoSizeChanged(videoSize)
Log.w("MediaPlayerView", "Video size changed: ${videoSize.width} / ${videoSize.height}")
if (videoSize.width != 0 && videoSize.height != 0) {
showArtwork = false
videoRatio = videoSize.width.toFloat() / videoSize.height.toFloat()
} else if (videoSize.width == 0) {
showArtwork = true
override fun onTracksChanged(tracks: Tracks) {
super.onTracksChanged(tracks)
if (!tracks.groups.isEmpty()) {
for (arrayIndex in 0 until tracks.groups.size) {
var done = false
for (groupIndex in 0 until tracks.groups[arrayIndex].length) {
val sampleMimeType = tracks.groups[arrayIndex].getTrackFormat(groupIndex).sampleMimeType
if (sampleMimeType != null && sampleMimeType.contains("video")) {
showArtwork = false
done = true
break
} else {
showArtwork = true
}
}
if (done) {
break
}
}
}
}

override fun onIsPlayingChanged(isPlaying: Boolean) {
super.onIsPlayingChanged(isPlaying)
keepScreenOn = isPlaying
}
}
}

Expand All @@ -218,24 +216,9 @@ fun MediaPlayerView(
LaunchedEffect(player) {
player.addListener(playerListener)
}
LaunchedEffect(true) {
player.videoSize.let {
if (it.width == 0) {
showArtwork = true
} else {
showArtwork = false
}
}
}

Box(
modifier.then(
if (pipSupport && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
Modifier.pipModifier(context)
} else {
Modifier
},
),
modifier = modifier,
contentAlignment = Alignment.Center,
) {
if (keepScreenOn) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat.startActivity
import androidx.core.text.isDigitsOnly
import androidx.media3.common.util.UnstableApi
import androidx.navigation.NavController
Expand Down Expand Up @@ -1218,6 +1219,24 @@ fun LocalPlaylistBottomSheet(
onDelete()
hideModalBottomSheet()
}
ActionButton(
icon = painterResource(id = R.drawable.baseline_share_24),
text = if (ytPlaylistId != null) R.string.share else R.string.sync_first,
enable = (ytPlaylistId != null),
) {
val shareIntent = Intent(Intent.ACTION_SEND)
shareIntent.type = "text/plain"
val url = "https://music.youtube.com/playlist?list=${
ytPlaylistId?.replaceFirst(
"VL",
"",
)
}"
shareIntent.putExtra(Intent.EXTRA_TEXT, url)
val chooserIntent =
Intent.createChooser(shareIntent, context.getString(R.string.share_url))
context.startActivity(chooserIntent)
}
EndOfModalBottomSheet()
}
}
Expand Down
Loading

0 comments on commit f502493

Please sign in to comment.