Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jimdogx committed Nov 18, 2024
1 parent 89160be commit fae538e
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions source/api/Items.bs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -39,39 +39,45 @@ 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)
req.SetRequest("POST")
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 <> ""
Expand Down

0 comments on commit fae538e

Please sign in to comment.