mirror of
https://gitea.invidious.io/iv-org/invidious.git
synced 2024-08-15 00:53:41 +00:00
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:
parent
2e67b90540
commit
7e5935a9da
4 changed files with 9 additions and 9 deletions
|
@ -7,7 +7,7 @@ module Invidious::Frontend::WatchPage
|
||||||
getter full_videos : Array(Hash(String, JSON::Any))
|
getter full_videos : Array(Hash(String, JSON::Any))
|
||||||
getter video_streams : Array(Hash(String, JSON::Any))
|
getter video_streams : Array(Hash(String, JSON::Any))
|
||||||
getter audio_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(
|
def initialize(
|
||||||
@full_videos,
|
@full_videos,
|
||||||
|
|
|
@ -24,7 +24,7 @@ struct Video
|
||||||
property updated : Time
|
property updated : Time
|
||||||
|
|
||||||
@[DB::Field(ignore: true)]
|
@[DB::Field(ignore: true)]
|
||||||
@captions = [] of Invidious::Videos::Caption
|
@captions = [] of Invidious::Videos::CaptionMetadata
|
||||||
|
|
||||||
@[DB::Field(ignore: true)]
|
@[DB::Field(ignore: true)]
|
||||||
property adaptive_fmts : Array(Hash(String, JSON::Any))?
|
property adaptive_fmts : Array(Hash(String, JSON::Any))?
|
||||||
|
@ -215,9 +215,9 @@ struct Video
|
||||||
keywords.includes? "YouTube Red"
|
keywords.includes? "YouTube Red"
|
||||||
end
|
end
|
||||||
|
|
||||||
def captions : Array(Invidious::Videos::Caption)
|
def captions : Array(Invidious::Videos::CaptionMetadata)
|
||||||
if @captions.empty? && @info.has_key?("captions")
|
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
|
end
|
||||||
|
|
||||||
return @captions
|
return @captions
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require "json"
|
require "json"
|
||||||
|
|
||||||
module Invidious::Videos
|
module Invidious::Videos
|
||||||
struct Caption
|
struct CaptionMetadata
|
||||||
property name : String
|
property name : String
|
||||||
property language_code : String
|
property language_code : String
|
||||||
property base_url : String
|
property base_url : String
|
||||||
|
@ -10,12 +10,12 @@ module Invidious::Videos
|
||||||
end
|
end
|
||||||
|
|
||||||
# Parse the JSON structure from Youtube
|
# 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
|
caption_tracks = container
|
||||||
.dig?("playerCaptionsTracklistRenderer", "captionTracks")
|
.dig?("playerCaptionsTracklistRenderer", "captionTracks")
|
||||||
.try &.as_a
|
.try &.as_a
|
||||||
|
|
||||||
captions_list = [] of Caption
|
captions_list = [] of CaptionMetadata
|
||||||
return captions_list if caption_tracks.nil?
|
return captions_list if caption_tracks.nil?
|
||||||
|
|
||||||
caption_tracks.each do |caption|
|
caption_tracks.each do |caption|
|
||||||
|
@ -25,7 +25,7 @@ module Invidious::Videos
|
||||||
language_code = caption["languageCode"].to_s
|
language_code = caption["languageCode"].to_s
|
||||||
base_url = caption["baseUrl"].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
|
end
|
||||||
|
|
||||||
return captions_list
|
return captions_list
|
||||||
|
|
|
@ -89,7 +89,7 @@
|
||||||
<label for="captions[0]"><%= translate(locale, "preferences_captions_label") %></label>
|
<label for="captions[0]"><%= translate(locale, "preferences_captions_label") %></label>
|
||||||
<% preferences.captions.each_with_index do |caption, index| %>
|
<% preferences.captions.each_with_index do |caption, index| %>
|
||||||
<select class="pure-u-1-6" name="captions[<%= index %>]" id="captions[<%= 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>
|
<option value="<%= option %>" <% if preferences.captions[index] == option %> selected <% end %>><%= translate(locale, option.blank? ? "none" : option) %></option>
|
||||||
<% end %>
|
<% end %>
|
||||||
</select>
|
</select>
|
||||||
|
|
Loading…
Reference in a new issue