Rename Caption struct to CaptionMetadata

The Caption object does not actually store any text lines for the
subtitles. Instead it stores the metadata needed to display and fetch
the actual captions from the YT timedtext API.

Therefore it may be wiser to rename the struct to be more reflective of
its current usage as well as the future usage once the current caption
retrival system is replaced via InnerTube's transcript API
This commit is contained in:
syeopite 2023-07-23 00:54:43 -07:00
parent 2e67b90540
commit 7e5935a9da
No known key found for this signature in database
GPG Key ID: A73C186DA3955A1A
4 changed files with 9 additions and 9 deletions

View File

@ -7,7 +7,7 @@ module Invidious::Frontend::WatchPage
getter full_videos : Array(Hash(String, JSON::Any))
getter video_streams : Array(Hash(String, JSON::Any))
getter audio_streams : Array(Hash(String, JSON::Any))
getter captions : Array(Invidious::Videos::Caption)
getter captions : Array(Invidious::Videos::CaptionMetadata)
def initialize(
@full_videos,

View File

@ -24,7 +24,7 @@ struct Video
property updated : Time
@[DB::Field(ignore: true)]
@captions = [] of Invidious::Videos::Caption
@captions = [] of Invidious::Videos::CaptionMetadata
@[DB::Field(ignore: true)]
property adaptive_fmts : Array(Hash(String, JSON::Any))?
@ -215,9 +215,9 @@ struct Video
keywords.includes? "YouTube Red"
end
def captions : Array(Invidious::Videos::Caption)
def captions : Array(Invidious::Videos::CaptionMetadata)
if @captions.empty? && @info.has_key?("captions")
@captions = Invidious::Videos::Caption.from_yt_json(info["captions"])
@captions = Invidious::Videos::CaptionMetadata.from_yt_json(info["captions"])
end
return @captions

View File

@ -1,7 +1,7 @@
require "json"
module Invidious::Videos
struct Caption
struct CaptionMetadata
property name : String
property language_code : String
property base_url : String
@ -10,12 +10,12 @@ module Invidious::Videos
end
# Parse the JSON structure from Youtube
def self.from_yt_json(container : JSON::Any) : Array(Caption)
def self.from_yt_json(container : JSON::Any) : Array(CaptionMetadata)
caption_tracks = container
.dig?("playerCaptionsTracklistRenderer", "captionTracks")
.try &.as_a
captions_list = [] of Caption
captions_list = [] of CaptionMetadata
return captions_list if caption_tracks.nil?
caption_tracks.each do |caption|
@ -25,7 +25,7 @@ module Invidious::Videos
language_code = caption["languageCode"].to_s
base_url = caption["baseUrl"].to_s
captions_list << Caption.new(name, language_code, base_url)
captions_list << CaptionMetadata.new(name, language_code, base_url)
end
return captions_list

View File

@ -89,7 +89,7 @@
<label for="captions[0]"><%= translate(locale, "preferences_captions_label") %></label>
<% preferences.captions.each_with_index do |caption, index| %>
<select class="pure-u-1-6" name="captions[<%= index %>]" id="captions[<%= index %>]">
<% Invidious::Videos::Caption::LANGUAGES.each do |option| %>
<% Invidious::Videos::CaptionMetadata::LANGUAGES.each do |option| %>
<option value="<%= option %>" <% if preferences.captions[index] == option %> selected <% end %>><%= translate(locale, option.blank? ? "none" : option) %></option>
<% end %>
</select>