mirror of
https://github.com/iv-org/invidious.git
synced 2024-06-07 19:40:52 +00:00
Refactor structure of caption.cr
Rename CaptionsMetadata to Metadata Nest Metadata under Captions Unnest LANGUAGES constant from Metadata to main Captions module
This commit is contained in:
parent
3509752b79
commit
1f7592e599
@ -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::CaptionMetadata)
|
||||
getter captions : Array(Invidious::Videos::Captions::Metadata)
|
||||
|
||||
def initialize(
|
||||
@full_videos,
|
||||
|
@ -24,7 +24,7 @@ struct Video
|
||||
property updated : Time
|
||||
|
||||
@[DB::Field(ignore: true)]
|
||||
@captions = [] of Invidious::Videos::CaptionMetadata
|
||||
@captions = [] of Invidious::Videos::Captions::Metadata
|
||||
|
||||
@[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::CaptionMetadata)
|
||||
def captions : Array(Invidious::Videos::Captions::Metadata)
|
||||
if @captions.empty? && @info.has_key?("captions")
|
||||
@captions = Invidious::Videos::CaptionMetadata.from_yt_json(info["captions"])
|
||||
@captions = Invidious::Videos::Captions::Metadata.from_yt_json(info["captions"])
|
||||
end
|
||||
|
||||
return @captions
|
||||
|
@ -1,7 +1,8 @@
|
||||
require "json"
|
||||
|
||||
module Invidious::Videos
|
||||
struct CaptionMetadata
|
||||
module Captions
|
||||
struct Metadata
|
||||
property name : String
|
||||
property language_code : String
|
||||
property base_url : String
|
||||
@ -12,12 +13,12 @@ module Invidious::Videos
|
||||
end
|
||||
|
||||
# Parse the JSON structure from Youtube
|
||||
def self.from_yt_json(container : JSON::Any) : Array(CaptionMetadata)
|
||||
def self.from_yt_json(container : JSON::Any) : Array(Captions::Metadata)
|
||||
caption_tracks = container
|
||||
.dig?("playerCaptionsTracklistRenderer", "captionTracks")
|
||||
.try &.as_a
|
||||
|
||||
captions_list = [] of CaptionMetadata
|
||||
captions_list = [] of Captions::Metadata
|
||||
return captions_list if caption_tracks.nil?
|
||||
|
||||
caption_tracks.each do |caption|
|
||||
@ -32,7 +33,7 @@ module Invidious::Videos
|
||||
auto_generated = true
|
||||
end
|
||||
|
||||
captions_list << CaptionMetadata.new(name, language_code, base_url, auto_generated)
|
||||
captions_list << Captions::Metadata.new(name, language_code, base_url, auto_generated)
|
||||
end
|
||||
|
||||
return captions_list
|
||||
@ -103,6 +104,7 @@ module Invidious::Videos
|
||||
end
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
# List of all caption languages available on Youtube.
|
||||
LANGUAGES = {
|
||||
|
@ -37,7 +37,7 @@ module Invidious::Videos
|
||||
# Convert into array of TranscriptLine
|
||||
lines = self.parse(initial_data)
|
||||
|
||||
# Taken from Invidious::Videos::CaptionMetadata.timedtext_to_vtt()
|
||||
# Taken from Invidious::Videos::Captions::Metadata.timedtext_to_vtt()
|
||||
vtt = String.build do |vtt|
|
||||
vtt << <<-END_VTT
|
||||
WEBVTT
|
||||
|
@ -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::CaptionMetadata::LANGUAGES.each do |option| %>
|
||||
<% Invidious::Videos::Captions::LANGUAGES.each do |option| %>
|
||||
<option value="<%= option %>" <% if preferences.captions[index] == option %> selected <% end %>><%= translate(locale, option.blank? ? "none" : option) %></option>
|
||||
<% end %>
|
||||
</select>
|
||||
|
Loading…
Reference in New Issue
Block a user