Skip to content

Commit

Permalink
Playlists: Use subtitle when author is missing (#4025)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamantazFox committed Sep 18, 2023
2 parents bf35200 + afb04c3 commit bb14f79
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/invidious/playlists.cr
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ struct Playlist
property views : Int64
property updated : Time
property thumbnail : String?
property subtitle : String?

def to_json(offset, json : JSON::Builder, video_id : String? = nil)
json.object do
Expand All @@ -100,6 +101,7 @@ struct Playlist
json.field "author", self.author
json.field "authorId", self.ucid
json.field "authorUrl", "/channel/#{self.ucid}"
json.field "subtitle", self.subtitle

json.field "authorThumbnails" do
json.array do
Expand Down Expand Up @@ -356,6 +358,8 @@ def fetch_playlist(plid : String)
updated = Time.utc
video_count = 0

subtitle = extract_text(initial_data.dig?("header", "playlistHeaderRenderer", "subtitle"))

playlist_info["stats"]?.try &.as_a.each do |stat|
text = stat["runs"]?.try &.as_a.map(&.["text"].as_s).join("") || stat["simpleText"]?.try &.as_s
next if !text
Expand Down Expand Up @@ -397,6 +401,7 @@ def fetch_playlist(plid : String)
views: views,
updated: updated,
thumbnail: thumbnail,
subtitle: subtitle,
})
end

Expand Down
7 changes: 6 additions & 1 deletion src/invidious/views/playlist.ecr
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@
</b>
<% else %>
<b>
<a href="/channel/<%= playlist.ucid %>"><%= author %></a> |
<% if !author.empty? %>
<a href="/channel/<%= playlist.ucid %>"><%= author %></a> |
<% elsif !playlist.subtitle.nil? %>
<% subtitle = playlist.subtitle || "" %>
<span><%= HTML.escape(subtitle[0..subtitle.rindex("") || subtitle.size]) %></span> |
<% end %>
<%= translate_count(locale, "generic_videos_count", playlist.video_count) %> |
<%= translate(locale, "Updated `x` ago", recode_date(playlist.updated, locale)) %>
</b>
Expand Down

0 comments on commit bb14f79

Please sign in to comment.