diff --git a/lib/av_player/track_extensions.rb b/lib/av_player/track_extensions.rb index b6aa860..459b755 100644 --- a/lib/av_player/track_extensions.rb +++ b/lib/av_player/track_extensions.rb @@ -5,7 +5,7 @@ module BerkeleyLibrary module AV - class Track + class Track # rubocop:disable Metrics/ClassLength include BerkeleyLibrary::Logging COLLECTION_RE = %r{(^[^/]+)/} @@ -78,20 +78,25 @@ def build_mpeg_dash_uri def find_hls_vtt_uri return unless hls_uri_exists? - return unless (hls_manifest = do_get(hls_uri, ignore_errors: true)) + return unless (hls_manifest_uri = hls_uri) + return unless (hls_manifest = do_get(hls_manifest_uri, ignore_errors: true)) + return unless (subtitle_list_uri = find_hls_subtitle_list_uri(hls_manifest)) + return unless (hls_subtitle_list = do_get(subtitle_list_uri, ignore_errors: true)) - playlist = M3u8::Playlist.read(hls_manifest) - vtt_manifest = playlist.items.find { |p| p.group_id == 'subs' } - hls_vtt_manifest_uri = hls_uri.merge(vtt_manifest.uri) - - return unless (hls_vtt_manifest = do_get(hls_vtt_manifest_uri, ignore_errors: true)) - - vtt_playlist = M3u8::Playlist.read(hls_vtt_manifest) + vtt_playlist = M3u8::Playlist.read(hls_subtitle_list) return unless (hls_vtt_path_relative = vtt_playlist.items.first.segment) hls_uri.merge(hls_vtt_path_relative) end + def find_hls_subtitle_list_uri(manifest) + return unless (playlist = M3u8::Playlist.read(manifest)) + return unless (subtitle_list = playlist.items.find { |p| p.group_id == 'subs' }) + return unless (subtitle_list_uri = subtitle_list.uri) + + hls_uri.merge(subtitle_list_uri) + end + def find_dash_vtt_uri return unless (dash_uri = mpeg_dash_uri) return unless (dash_manifest = do_get(dash_uri, ignore_errors: true))