Skip to content

Commit

Permalink
refactor new hls vtt private methods in track extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
anarchivist committed Jul 3, 2024
1 parent c73cd20 commit c80658a
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions lib/av_player/track_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

module BerkeleyLibrary
module AV
class Track
class Track # rubocop:disable Metrics/ClassLength
include BerkeleyLibrary::Logging

COLLECTION_RE = %r{(^[^/]+)/}
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit c80658a

Please sign in to comment.