Update:iOS stream and download URLs to use new API endpoints

This commit is contained in:
advplyr
2023-06-04 12:21:40 -05:00
parent a8ac4970cc
commit fbcb8620f9
2 changed files with 34 additions and 13 deletions
+15 -4
View File
@@ -347,10 +347,21 @@ public class AbsDownloader: CAPPlugin, URLSessionDownloadDelegate {
}
private func urlForTrack(item: LibraryItem, track: AudioTrack) -> URL {
// filename needs to be encoded otherwise would just use contentUrl
let relPath = track.metadata?.relPath ?? ""
let filepathEncoded = relPath.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed)
let urlstr = "\(Store.serverConfig!.address)/s/item/\(item.id)/\(filepathEncoded ?? "")?token=\(Store.serverConfig!.token)"
// TODO: Future server release should include ino with AudioFile or FileMetadata
let trackPath = track.metadata?.path ?? ""
var audioFileIno = ""
if (item.mediaType == "podcast") {
let podcastEpisodes = item.media?.episodes ?? List<PodcastEpisode>()
let matchingEpisode = podcastEpisodes.first(where: { $0.audioFile?.metadata?.path == trackPath })
audioFileIno = matchingEpisode?.audioFile?.ino ?? ""
} else {
let audioFiles = item.media?.audioFiles ?? List<AudioFile>()
let matchingAudioFile = audioFiles.first(where: { $0.metadata?.path == trackPath })
audioFileIno = matchingAudioFile?.ino ?? ""
}
let urlstr = "\(Store.serverConfig!.address)/api/items/\(item.id)/file/\(audioFileIno)/download?token=\(Store.serverConfig!.token)"
return URL(string: urlstr)!
}