Use semantically correct API endpoint when streaming/downloading.

Fixes #257
This commit is contained in:
tzugen 2021-08-28 11:38:44 +02:00
parent 029f0fa4da
commit ad81f3bf6d
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
6 changed files with 37 additions and 12 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

@ -250,8 +250,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
@ -337,8 +338,8 @@ class DownloadFile(
// Download the largest size that we can display in the UI
imageLoaderProvider.getImageLoader().cacheCoverArt(song)
}
} catch (e: Exception) {
Timber.e(e, "Failed to get cover art.")
} catch (all: Exception) {
Timber.e(all, "Failed to get cover art.")
}
}

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()