Skip to content

Commit

Permalink
Merge branch 'dev' into release/0.7.x
Browse files Browse the repository at this point in the history
  • Loading branch information
mikooomich committed Jan 17, 2025
2 parents 78b0ae5 + d1faa1f commit 27fec3b
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ interface PlaylistsDao {
LEFT JOIN playlist_song_map psm ON p.id = psm.playlistId
LEFT JOIN song s ON psm.songId = s.id
WHERE name LIKE '%' || :query || '%'
AND s.inLibrary IS NOT NULL
GROUP BY p.id
LIMIT :previewSize
""")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ class QueueBoard(queues: MutableList<MultiQueueObject> = ArrayList()) {
) {
val listPos = if (pos < 0) {
0
} else if (pos >= q.queue.size) {
} else if (pos > q.queue.size) {
q.queue.size - 1
} else {
pos
Expand Down
28 changes: 15 additions & 13 deletions app/src/main/java/com/dd3boh/outertune/playback/MusicService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,9 @@ class MusicService : MediaLibraryService(),
fun initQueue() {
if (dataStore.get(PersistentQueueKey, true)) {
queueBoard = QueueBoard(database.readQueue().toMutableList())
isShuffleEnabled.value = queueBoard.getCurrentQueue()?.shuffled ?: false
if (queueBoard.getAllQueues().isNotEmpty()) {
val queue = queueBoard.getCurrentQueue()
if (queue != null) {
isShuffleEnabled.value = queue.shuffled
queueBoard.initialized = true
}
queueBoard.getCurrentQueue()?.let {
isShuffleEnabled.value = it.shuffled
queueBoard.initialized = true
}
}
}
Expand Down Expand Up @@ -508,6 +504,7 @@ class MusicService : MediaLibraryService(),
fun playQueue(queue: Queue, playWhenReady: Boolean = true, replace: Boolean = false, title: String? = null) {
if (!queueBoard.initialized) {
initQueue()
queueBoard.initialized = true
}
queueTitle = title
queuePlaylistId = queue.playlistId
Expand Down Expand Up @@ -554,9 +551,12 @@ class MusicService : MediaLibraryService(),
* Add items to queue, right after current playing item
*/
fun enqueueNext(items: List<MediaItem>) {
println("wtf "+ "ENQUEUNE NEXT CALLED " + queueBoard.initialized)
if (!queueBoard.initialized) {

// when enqueuing next when player isn't active, play as a new song
if (items.isNotEmpty()) {
println("wtf "+ "PLAYING FROMe")
CoroutineScope(Dispatchers.Main).launch {
playQueue(
ListQueue(
Expand Down Expand Up @@ -834,12 +834,14 @@ class MusicService : MediaLibraryService(),
// TODO: support playlist id
if (mediaItem.metadata?.isLocal != true) {
CoroutineScope(Dispatchers.IO).launch {
val playerResponse = YTPlayerUtils.playerResponseForMetadata(mediaItem.mediaId, null).getOrNull()
if (playerResponse?.playabilityStatus?.status == "OK") {
YouTube.registerPlayback(
playlistId = null,
playbackTracking = playerResponse.playbackTracking?.videostatsPlaybackUrl?.baseUrl!!
)
val playbackUrl = database.format(mediaItem.mediaId).first()?.playbackUrl
?: YTPlayerUtils.playerResponseForMetadata(mediaItem.mediaId, null).getOrNull()?.playbackTracking?.videostatsPlaybackUrl?.baseUrl

playbackUrl?.let {
YouTube.registerPlayback(null, playbackUrl)
.onFailure {
reportException(it)
}
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions app/src/main/java/com/dd3boh/outertune/utils/YTPlayerUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.zionhuang.innertube.NewPipeUtils
import com.zionhuang.innertube.YouTube
import com.zionhuang.innertube.models.YouTubeClient
import com.zionhuang.innertube.models.YouTubeClient.Companion.IOS
import com.zionhuang.innertube.models.YouTubeClient.Companion.WEB_CREATOR
import com.zionhuang.innertube.models.YouTubeClient.Companion.TVHTML5_SIMPLY_EMBEDDED_PLAYER
import com.zionhuang.innertube.models.YouTubeClient.Companion.WEB_REMIX
import com.zionhuang.innertube.models.response.PlayerResponse
import com.dd3boh.outertune.constants.AudioQuality
Expand All @@ -33,7 +33,10 @@ object YTPlayerUtils {
/**
* Clients used for fallback streams in case the streams of the main client do not work.
*/
private val STREAM_FALLBACK_CLIENTS: Array<YouTubeClient> = arrayOf(WEB_CREATOR, IOS)
private val STREAM_FALLBACK_CLIENTS: Array<YouTubeClient> = arrayOf(
TVHTML5_SIMPLY_EMBEDDED_PLAYER,
IOS,
)

data class PlaybackData(
val audioConfig: PlayerResponse.PlayerConfig.AudioConfig?,
Expand Down
6 changes: 3 additions & 3 deletions innertube/src/main/java/com/zionhuang/innertube/InnerTube.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ class InnerTube {
}

defaultRequest {
url("https://music.youtube.com/youtubei/v1/")
url(YouTubeClient.API_URL_YOUTUBE_MUSIC)
}
}

private fun HttpRequestBuilder.ytClient(client: YouTubeClient, setLogin: Boolean = false) {
contentType(ContentType.Application.Json)
headers {
append("X-Goog-Api-Format-Version", "1")
append("X-YouTube-Client-Name", client.clientId)
append("X-YouTube-Client-Name", client.clientId /* Not a typo. The Client-Name header does contain the client id. */)
append("X-YouTube-Client-Version", client.clientVersion)
append("X-Origin", YouTubeClient.ORIGIN_YOUTUBE_MUSIC)
append("Referer", YouTubeClient.REFERER_YOUTUBE_MUSIC)
Expand Down Expand Up @@ -126,7 +126,7 @@ class InnerTube {
setBody(
PlayerBody(
context = client.toContext(locale, visitorData).let {
if (client == YouTubeClient.TVHTML5) {
if (client.isEmbedded) {
it.copy(
thirdParty = Context.ThirdParty(
embedUrl = "https://www.youtube.com/watch?v=${videoId}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ data class YouTubeClient(
val loginSupported: Boolean = false,
val loginRequired: Boolean = false,
val useSignatureTimestamp: Boolean = false,
val isEmbedded: Boolean = false,
// val origin: String? = null,
// val referer: String? = null,
) {
Expand Down Expand Up @@ -62,14 +63,15 @@ data class YouTubeClient(
useSignatureTimestamp = true,
)

val TVHTML5 = YouTubeClient(
val TVHTML5_SIMPLY_EMBEDDED_PLAYER = YouTubeClient(
clientName = "TVHTML5_SIMPLY_EMBEDDED_PLAYER",
clientVersion = "2.0",
clientId = "85",
userAgent = "Mozilla/5.0 (PlayStation; PlayStation 4/12.00) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.4 Safari/605.1.15",
loginSupported = true,
loginRequired = true,
useSignatureTimestamp = true,
isEmbedded = true,
)

val IOS = YouTubeClient(
Expand Down

This file was deleted.

0 comments on commit 27fec3b

Please sign in to comment.