diff --git a/source/api/Items.bs b/source/api/Items.bs index c61fd2557..d5dfdc6f7 100644 --- a/source/api/Items.bs +++ b/source/api/Items.bs @@ -13,7 +13,7 @@ function ItemGetPlaybackInfo(id as string, startTimeTicks = 0 as longinteger) return getJson(resp) end function -function ItemPostPlaybackInfo(id as string, mediaSourceId = "" as string, audioTrackIndex = -1 as integer, subtitleTrackIndex = -1 as integer, startTimeTicks = 0 as longinteger, forceLiveTVTranscode = false) +function ItemPostPlaybackInfo(id as string, mediaSourceId = "" as string, audioTrackIndex = -1 as integer, subtitleTrackIndex = -1 as integer, startTimeTicks = 0 as longinteger, forceMP3 = false) params = { "UserId": m.global.session.user.id, "StartTimeTicks": startTimeTicks, @@ -39,32 +39,22 @@ function ItemPostPlaybackInfo(id as string, mediaSourceId = "" as string, audioT myGLobal = m.global - if audioTrackIndex > -1 and myGLobal.session.video.json.MediaStreams <> invalid or forceLiveTVTranscode + if audioTrackIndex > -1 and myGLobal.session.video.json.MediaStreams <> invalid selectedAudioStream = myGLobal.session.video.json.MediaStreams[audioTrackIndex] - if selectedAudioStream <> invalid or forceLiveTVTranscode + if selectedAudioStream <> invalid params.AudioStreamIndex = audioTrackIndex ' force the server to transcode AAC profiles we don't support to MP3 instead of the usual AAC ' TODO: Remove this after server adds support for transcoding AAC from one profile to another - if forceLiveTVTranscode or selectedAudioStream.Codec <> invalid and LCase(selectedAudioStream.Codec) = "aac" - if forceLiveTVTranscode or selectedAudioStream.Profile <> invalid and LCase(selectedAudioStream.Profile) = "main" or LCase(selectedAudioStream.Profile) = "he-aac" - for each rule in deviceProfile.TranscodingProfiles - if rule.Container = "ts" or rule.Container = "mp4" - if rule.AudioCodec = "aac" - rule.AudioCodec = "mp3" - else if rule.AudioCodec.Left(4) = "aac," - rule.AudioCodec = mid(rule.AudioCodec, 5) - - if rule.AudioCodec.Left(3) <> "mp3" - rule.AudioCodec = "mp3," + rule.AudioCodec - end if - end if - end if - end for + if selectedAudioStream.Codec <> invalid and LCase(selectedAudioStream.Codec) = "aac" + if selectedAudioStream.Profile <> invalid and LCase(selectedAudioStream.Profile) = "main" or LCase(selectedAudioStream.Profile) = "he-aac" + forceMP3Audio(deviceProfile) end if end if end if + else if forceMP3 + forceMP3Audio(deviceProfile) end if req = APIRequest(Substitute("Items/{0}/PlaybackInfo", id), params) @@ -72,6 +62,22 @@ function ItemPostPlaybackInfo(id as string, mediaSourceId = "" as string, audioT return postJson(req, FormatJson({ "DeviceProfile": deviceProfile })) end function +sub forceMP3Audio(deviceProfile as object) + for each rule in deviceProfile.TranscodingProfiles + if rule.Container = "ts" or rule.Container = "mp3" + if rule.AudioCodec = "aac" + rule.AudioCodec = "mp2" + else if rule.AudioCodec.Left(3) = "aac," + rule.AudioCodec = mid(rule.AudioCodec, 4) + + if rule.AudioCodec.Left(2) <> "mp3" + rule.AudioCodec = "mp2," + rule.AudioCodec + end if + end if + end if + end for +end sub + ' Search across all libraries function searchMedia(query as string) if query <> ""