From c80658af99fc053216395102b9a8e23fa4103999 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20A=2E=20Matienzo?= Date: Tue, 2 Jul 2024 18:46:55 -0700 Subject: [PATCH] refactor new hls vtt private methods in track extensions --- lib/av_player/track_extensions.rb | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) 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))