mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2022-03-16.git
synced 2024-08-15 00:53:18 +00:00
Add JSON mapping for captions
This commit is contained in:
parent
f3646dc0bb
commit
6c71227766
4 changed files with 39 additions and 18 deletions
|
@ -87,6 +87,7 @@ CAPTION_LANGUAGES = [
|
|||
"Somali",
|
||||
"Southern Sotho",
|
||||
"Spanish",
|
||||
"Spanish (Latin America)",
|
||||
"Sundanese",
|
||||
"Swahili",
|
||||
"Swedish",
|
||||
|
@ -164,10 +165,16 @@ class Video
|
|||
def captions
|
||||
player_response = JSON.parse(self.info["player_response"])
|
||||
|
||||
captions = [] of Caption
|
||||
if player_response["captions"]?
|
||||
captions = player_response["captions"]["playerCaptionsTracklistRenderer"]["captionTracks"]?.try &.as_a
|
||||
caption_list = player_response["captions"]["playerCaptionsTracklistRenderer"]["captionTracks"].as_a
|
||||
|
||||
caption_list.each do |caption|
|
||||
caption = Caption.from_json(caption.to_json)
|
||||
caption.name.simpleText = caption.name.simpleText.split(" - ")[0]
|
||||
captions << caption
|
||||
end
|
||||
end
|
||||
captions ||= [] of JSON::Any
|
||||
|
||||
return captions
|
||||
end
|
||||
|
@ -207,6 +214,20 @@ class Video
|
|||
})
|
||||
end
|
||||
|
||||
class Caption
|
||||
JSON.mapping(
|
||||
name: CaptionName,
|
||||
baseUrl: String,
|
||||
languageCode: String
|
||||
)
|
||||
end
|
||||
|
||||
class CaptionName
|
||||
JSON.mapping(
|
||||
simpleText: String,
|
||||
)
|
||||
end
|
||||
|
||||
def get_video(id, db, refresh = true)
|
||||
if db.query_one?("SELECT EXISTS (SELECT true FROM videos WHERE id = $1)", id, as: Bool)
|
||||
video = db.query_one("SELECT * FROM videos WHERE id = $1", id, as: Video)
|
||||
|
|
|
@ -56,8 +56,8 @@ video, #my_video, .video-js, .vjs-default-skin
|
|||
<% end %>
|
||||
|
||||
<% captions.each do |caption| %>
|
||||
<track kind="captions" src="/api/v1/captions/<%= video.id %>?label=<%= caption["name"]["simpleText"] %>"
|
||||
label="<%= caption["name"]["simpleText"]%> ">
|
||||
<track kind="captions" src="/api/v1/captions/<%= video.id %>?label=<%= caption.name.simpleText %>"
|
||||
label="<%= caption.name.simpleText %> ">
|
||||
<% end %>
|
||||
<% end %>
|
||||
</video>
|
||||
|
|
|
@ -61,14 +61,14 @@
|
|||
<% end %>
|
||||
|
||||
<% preferred_captions.each_with_index do |caption, i| %>
|
||||
<track kind="captions" src="/api/v1/captions/<%= video.id %>?label=<%= caption["name"]["simpleText"] %>"
|
||||
label="<%= caption["name"]["simpleText"]%>" <% if i == 0 %>default<% end %>>
|
||||
<track kind="captions" src="/api/v1/captions/<%= video.id %>?label=<%= caption.name.simpleText %>"
|
||||
label="<%= caption.name.simpleText %>" <% if i == 0 %>default<% end %>>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% captions.each do |caption| %>
|
||||
<track kind="captions" src="/api/v1/captions/<%= video.id %>?label=<%= caption["name"]["simpleText"] %>"
|
||||
label="<%= caption["name"]["simpleText"]%>">
|
||||
<track kind="captions" src="/api/v1/captions/<%= video.id %>?label=<%= caption.name.simpleText %>"
|
||||
label="<%= caption.name.simpleText %>">
|
||||
<% end %>
|
||||
<% end %>
|
||||
</video>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue