Merge pull request #567 from ultrasonic/semanticDownloadView

Use semantically correct API endpoint when streaming/downloading.
This commit is contained in:
Nite 2021-09-03 20:26:58 +02:00 committed by GitHub
commit f29db522d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 10 deletions

View File

@ -229,6 +229,19 @@ interface SubsonicAPIDefinition {
@Header("Range") offset: Long? = null
): Call<ResponseBody>
@Streaming
@GET("download.view")
fun download(
@Query("id") id: String,
@Query("maxBitRate") maxBitRate: Int? = null,
@Query("format") format: String? = null,
@Query("timeOffset") timeOffset: Int? = null,
@Query("size") videoSize: String? = null,
@Query("estimateContentLength") estimateContentLength: Boolean? = null,
@Query("converted") converted: Boolean? = null,
@Header("Range") offset: Long? = null
): Call<ResponseBody>
@GET("jukeboxControl.view")
fun jukeboxControl(
@Query("action") action: JukeboxAction,

View File

@ -275,9 +275,10 @@ class CachedMusicService(private val musicService: MusicService) : MusicService,
override fun getDownloadInputStream(
song: MusicDirectory.Entry,
offset: Long,
maxBitrate: Int
maxBitrate: Int,
save: Boolean
): Pair<InputStream, Boolean> {
return musicService.getDownloadInputStream(song, offset, maxBitrate)
return musicService.getDownloadInputStream(song, offset, maxBitrate, save)
}
@Throws(Exception::class)

View File

@ -251,8 +251,9 @@ class DownloadFile(
if (needsDownloading) {
// Attempt partial HTTP GET, appending to the file if it exists.
val (inStream, partial) = musicService
.getDownloadInputStream(song, partialFile.length(), desiredBitRate)
val (inStream, partial) = musicService.getDownloadInputStream(
song, partialFile.length(), desiredBitRate, save
)
inputStream = inStream

View File

@ -119,10 +119,10 @@ interface MusicService {
fun getDownloadInputStream(
song: MusicDirectory.Entry,
offset: Long,
maxBitrate: Int
maxBitrate: Int,
save: Boolean
): Pair<InputStream, Boolean>
// TODO: Refactor and remove this call (see RestMusicService implementation)
@Throws(Exception::class)
fun getVideoUrl(id: String): String?

View File

@ -465,7 +465,8 @@ class OfflineMusicService : MusicService, KoinComponent {
override fun getDownloadInputStream(
song: MusicDirectory.Entry,
offset: Long,
maxBitrate: Int
maxBitrate: Int,
save: Boolean
): Pair<InputStream, Boolean> {
throw OfflineException("getDownloadInputStream isn't available in offline mode")
}

View File

@ -15,6 +15,7 @@ import org.moire.ultrasonic.api.subsonic.ApiNotSupportedException
import org.moire.ultrasonic.api.subsonic.SubsonicAPIClient
import org.moire.ultrasonic.api.subsonic.models.AlbumListType.Companion.fromName
import org.moire.ultrasonic.api.subsonic.models.JukeboxAction
import org.moire.ultrasonic.api.subsonic.response.StreamResponse
import org.moire.ultrasonic.api.subsonic.throwOnFailure
import org.moire.ultrasonic.api.subsonic.toStreamResponse
import org.moire.ultrasonic.data.ActiveServerProvider
@ -427,12 +428,20 @@ open class RESTMusicService(
override fun getDownloadInputStream(
song: MusicDirectory.Entry,
offset: Long,
maxBitrate: Int
maxBitrate: Int,
save: Boolean
): Pair<InputStream, Boolean> {
val songOffset = if (offset < 0) 0 else offset
lateinit var response: StreamResponse
val response = API.stream(song.id, maxBitrate, offset = songOffset)
.execute().toStreamResponse()
// Use semantically correct call
if (save) {
response = API.download(song.id, maxBitrate, offset = songOffset)
.execute().toStreamResponse()
} else {
response = API.stream(song.id, maxBitrate, offset = songOffset)
.execute().toStreamResponse()
}
response.throwOnFailure()