diff --git a/src/invidious/helpers/helpers.cr b/src/invidious/helpers/helpers.cr index 1cd40d41..1ed33d9e 100644 --- a/src/invidious/helpers/helpers.cr +++ b/src/invidious/helpers/helpers.cr @@ -232,13 +232,22 @@ def extract_items(nodeset, ucid = nil, author_name = nil) ) end + playlist_thumbnail = node.xpath_node(%q(.//div/span/img)).try &.["data-thumb"]? + playlist_thumbnail ||= node.xpath_node(%q(.//div/span/img)).try &.["src"] + if !playlist_thumbnail || playlist_thumbnail.empty? + thumbnail_id = videos[0]?.try &.id + else + thumbnail_id = playlist_thumbnail.match(/\/vi\/(?[a-zA-Z0-9_-]{11})\/\w+\.jpg/).try &.["video_id"] + end + items << SearchPlaylist.new( title, plid, author, author_id, video_count, - videos + videos, + thumbnail_id ) when .includes? "yt-lockup-channel" author = title.strip @@ -399,13 +408,22 @@ def extract_shelf_items(nodeset, ucid = nil, author_name = nil) playlist_title ||= "" plid ||= "" + playlist_thumbnail = child_node.xpath_node(%q(.//span/img)).try &.["data-thumb"]? + playlist_thumbnail ||= child_node.xpath_node(%q(.//span/img)).try &.["src"] + if !playlist_thumbnail || playlist_thumbnail.empty? + thumbnail_id = videos[0]?.try &.id + else + thumbnail_id = playlist_thumbnail.match(/\/vi\/(?[a-zA-Z0-9_-]{11})\/\w+\.jpg/).try &.["video_id"] + end + items << SearchPlaylist.new( playlist_title, plid, author_name, ucid, 50, - Array(SearchPlaylistVideo).new + Array(SearchPlaylistVideo).new, + thumbnail_id ) end end @@ -419,7 +437,8 @@ def extract_shelf_items(nodeset, ucid = nil, author_name = nil) author_name, ucid, videos.size, - videos + videos, + videos[0].try &.id ) end end diff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.cr index 3123b1d2..eb8fa80a 100644 --- a/src/invidious/helpers/utils.cr +++ b/src/invidious/helpers/utils.cr @@ -162,6 +162,23 @@ def number_with_separator(number) number.to_s.reverse.gsub(/(\d{3})(?=\d)/, "\\1,").reverse end +def short_text_to_number(short_text) + case short_text + when .ends_with? "M" + number = short_text.rstrip(" mM").to_f + number *= 1000000 + when .ends_with? "K" + number = short_text.rstrip(" kK").to_f + number *= 1000 + else + number = short_text.rstrip(" ") + end + + number = number.to_i + + return number +end + def number_to_short_text(number) seperated = number_with_separator(number).gsub(",", ".").split("") text = seperated.first(2).join diff --git a/src/invidious/search.cr b/src/invidious/search.cr index ec97cf85..63cce4de 100644 --- a/src/invidious/search.cr +++ b/src/invidious/search.cr @@ -25,12 +25,13 @@ end class SearchPlaylist add_mapping({ - title: String, - id: String, - author: String, - ucid: String, - video_count: Int32, - videos: Array(SearchPlaylistVideo), + title: String, + id: String, + author: String, + ucid: String, + video_count: Int32, + videos: Array(SearchPlaylistVideo), + thumbnail_id: String?, }) end diff --git a/src/invidious/views/components/item.ecr b/src/invidious/views/components/item.ecr index 51aa7193..fe48834f 100644 --- a/src/invidious/views/components/item.ecr +++ b/src/invidious/views/components/item.ecr @@ -16,7 +16,7 @@
<%= item.description_html %>
<% when SearchPlaylist %> <% if item.id.starts_with? "RD" %> - <% url = "/mix?list=#{item.id}&continuation=#{item.videos[0]?.try &.id}" %> + <% url = "/mix?list=#{item.id}&continuation=#{item.thumbnail_id}" %> <% else %> <% url = "/playlist?list=#{item.id}" %> <% end %> @@ -24,7 +24,7 @@ <% if env.get?("user") && env.get("user").as(User).preferences.thin_mode %> <% else %>
- +

<%= number_with_separator(item.video_count) %> videos

<% end %>