Skip to content

Commit

Permalink
Subtitles: Prefer text-based options when available
Browse files Browse the repository at this point in the history
As we know, the roku video player does not support image-based
subtitles, so any attempt to play these results in transcoding.

As this is undesirable, this patch modifies the default subtitle
logic to prefer any text-based subtitles that match their user's
preference. If no such text-based subtitles exist, we then allow
image-based subtitles to be selected.
  • Loading branch information
cthelight committed Apr 17, 2022
1 parent 0e16c3a commit 3bc3422
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions source/utils/Subtitles.brs
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,43 @@ function defaultSubtitleTrackFromVid(video_id) as integer
meta = ItemMetaData(video_id)
if meta = invalid then return invalid
subtitles = sortSubtitles(meta.id, meta.json.MediaSources[0].MediaStreams)
return defaultSubtitleTrack(subtitles["all"]) ' Find correct subtitle track
default_text_subs = defaultSubtitleTrack(subtitles["all"], true) ' Find correct subtitle track (forced text)
if default_text_subs <> -1
return default_text_subs
else
return defaultSubtitleTrack(subtitles["all"]) ' if no appropriate text subs exist, allow non-text
end if
end function


' Identify the defaulty subtitle track
' Identify the default subtitle track
' if "requires_text" is true, only return a track if it is textual
' This allows forcing text subs, since roku requires transcoding of non-text subs
' returns the server-side track index for the appriate subtitle
function defaultSubtitleTrack(sorted_subtitles) as integer
function defaultSubtitleTrack(sorted_subtitles, require_text = false) as integer
if m.user.Configuration.SubtitleMode = "None"
return -1 ' No subtitles desired: select none
end if

for each item in sorted_subtitles
if m.user.Configuration.SubtitleMode = "Default" and (item.isForced or item.IsDefault or item.IsExternal)
return item.Index ' Finds first forced, or default, or external subs in sorted list
else if m.user.Configuration.SubtitleMode = "Always" and not item.IsForced
return item.Index ' Select the first non-forced subtitle option in the sorted list
else if m.user.Configuration.SubtitleMode = "OnlyForced" and item.IsForced
return item.Index ' Select the first forced subtitle option in the sorted list
else if m.user.Configuration.SubtitlePlaybackMode = "Smart" and (item.isForced or item.IsDefault or item.IsExternal)
' Simplified "Smart" logic here mimics Default (as that is fallback behavior normally)
' Avoids detecting preferred audio language (as is utilized in main client)
return item.Index
if (require_text and item.IsTextSubtitleStream) or not require_text
if m.user.Configuration.SubtitleMode = "Default" and (item.isForced or item.IsDefault or item.IsExternal)
return item.Index ' Finds first forced, or default, or external subs in sorted list
else if m.user.Configuration.SubtitleMode = "Always" and not item.IsForced
return item.Index ' Select the first non-forced subtitle option in the sorted list
else if m.user.Configuration.SubtitleMode = "OnlyForced" and item.IsForced
return item.Index ' Select the first forced subtitle option in the sorted list
else if m.user.Configuration.SubtitlePlaybackMode = "Smart" and (item.isForced or item.IsDefault or item.IsExternal)
' Simplified "Smart" logic here mimics Default (as that is fallback behavior normally)
' Avoids detecting preferred audio language (as is utilized in main client)
return item.Index
end if
end if
end for
return -1 ' Keep current default behavior of "None", if no correct subtitle is identified
end function

' The subtitle index on the server differes from the index we track locally
' The subtitle index on the server differs from the index we track locally
' This function converts the former into the latter
function getSubtitleSelIdxFromSubIdx(subtitles, sub_idx) as integer
selIdx = 0
Expand Down

0 comments on commit 3bc3422

Please sign in to comment.