Skip to content

Commit

Permalink
Add Range header to YouTube Music stream request (closes #290)
Browse files Browse the repository at this point in the history
  • Loading branch information
25huizengek1 committed May 17, 2024
1 parent 6ecfb18 commit 6f1d8d6
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1301,8 +1301,12 @@ class PlayerService : InvincibleService(), Player.Listener, PlaybackStatsListene
.setUri(url.toUri())
.build()
.let { spec ->
(chunkLength ?: format.contentLength)?.let {
spec.subrange(dataSpec.uriPositionOffset, it)
(chunkLength ?: format.contentLength)?.let { length ->
val start = dataSpec.uriPositionOffset

spec
.subrange(start, length)
.withAdditionalHeaders(mapOf("Range" to "$start-${start + length}"))
} ?: spec
}
}
Expand Down

5 comments on commit 6f1d8d6

@th3y
Copy link

@th3y th3y commented on 6f1d8d6 May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Persist the slow download in bigger audio files (More than 10 Mb)
If, for example, the audio file is 30 MB, it should open 3 instances to precache the audio in 3 different chunks (So it should download in 3 parts of 10 Mb)
First downloader instance: Range=0-10000
Second downloader instance on queue: Range=10001-20000
Third downloader instance on queue: Range=20001=30000

@25huizengek1
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand, the player already uses this kind of chunking, and I guess the download manager could use something like that, but parallelism is already used so it kind of defeats the purpose if we'd implement this, no?

@th3y
Copy link

@th3y th3y commented on 6f1d8d6 May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it defeats the purpose of the current implementation for files with less than 10 MB, because it takes the whole chunk, making the download really fast in this scenary. I think the current/main issue comes with files with more than 10MB size.

@th3y
Copy link

@th3y th3y commented on 6f1d8d6 May 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using subrange and additional header, we could also modify the Url and add the parameter

format.url + "&range=0-${format.contentLength ?: 10000000}"

instead of format.url, from
val url = when (val status = body.playabilityStatus?.status) { "OK" -> format?.let {} in fun createYouTubeDataSourceResolverFactory()

@25huizengek1
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.