Invidious is an alternative front-end to YouTube
Add 'playlistThumbnail' to playlist objects
Omar Roth059f50dad477
diff --git a/src/invidious.cr b/src/invidious.crindex 143be96d..0203e3b8 100644--- a/src/invidious.cr+++ b/src/invidious.cr@@ -4101,8 +4101,10 @@ get "/api/v1/playlists/:plid" do |env|response = JSON.build do |json|json.object do+ json.field "type", "playlist"json.field "title", playlist.titlejson.field "playlistId", playlist.id+ json.field "playlistThumbnail", playlist.thumbnailjson.field "author", playlist.authorjson.field "authorId", playlist.uciddiff --git a/src/invidious/helpers/helpers.cr b/src/invidious/helpers/helpers.crindex 20ff2de6..331f6360 100644--- a/src/invidious/helpers/helpers.cr+++ b/src/invidious/helpers/helpers.cr@@ -331,18 +331,8 @@ def extract_items(nodeset, ucid = nil, author_name = nil)nextend- anchor = node.xpath_node(%q(.//div[contains(@class, "yt-lockup-byline")]/a))- if anchor- author = anchor.content.strip- author_id = anchor["href"].split("/")[-1]- end-- author ||= author_name- author_id ||= ucid-- author ||= ""- author_id ||= ""-+ author_id = node.xpath_node(%q(.//div[contains(@class, "yt-lockup-byline")]/a)).try &.["href"].split("/")[-1] || ucid || ""+ author = node.xpath_node(%q(.//div[contains(@class, "yt-lockup-byline")]/a)).try &.content.strip || author_name || ""description_html = node.xpath_node(%q(.//div[contains(@class, "yt-lockup-description")])).try &.to_s || ""tile = node.xpath_node(%q(.//div[contains(@class, "yt-lockup-tile")]))@@ -401,13 +391,13 @@ def extract_items(nodeset, ucid = nil, author_name = nil)playlist_thumbnail ||= node.xpath_node(%q(.//span/img)).try &.["src"]items << SearchPlaylist.new(- title,- plid,- author,- author_id,- video_count,- videos,- playlist_thumbnail+ title: title,+ id: plid,+ author: author,+ ucid: author_id,+ video_count: video_count,+ videos: videos,+ thumbnail: playlist_thumbnail)when .includes? "yt-lockup-channel"author = title.strip@@ -577,13 +567,13 @@ def extract_shelf_items(nodeset, ucid = nil, author_name = nil)enditems << SearchPlaylist.new(- playlist_title,- plid,- author_name,- ucid,- video_count,- videos,- playlist_thumbnail+ title: playlist_title,+ id: plid,+ author: author_name,+ ucid: ucid,+ video_count: video_count,+ videos: videos,+ thumbnail: playlist_thumbnail)endend@@ -592,13 +582,13 @@ def extract_shelf_items(nodeset, ucid = nil, author_name = nil)plid = HTTP::Params.parse(URI.parse(id).query.not_nil!)["list"]items << SearchPlaylist.new(- title,- plid,- author_name,- ucid,- videos.size,- videos,- "/vi/#{videos[0].id}/mqdefault.jpg"+ title: title,+ id: plid,+ author: author_name,+ ucid: ucid,+ video_count: videos.size,+ videos: videos,+ thumbnail: "https://i.ytimg.com/vi/#{videos[0].id}/mqdefault.jpg")endenddiff --git a/src/invidious/playlists.cr b/src/invidious/playlists.crindex d28a4149..7965d990 100644--- a/src/invidious/playlists.cr+++ b/src/invidious/playlists.cr@@ -51,6 +51,7 @@ struct Playlistvideo_count: Int32,views: Int64,updated: Time,+ thumbnail: String?,})end@@ -223,6 +224,9 @@ def fetch_playlist(plid, locale)description_html = document.xpath_node(%q(//span[@class="pl-header-description-text"]/div/div[1])).try &.to_s ||document.xpath_node(%q(//span[@class="pl-header-description-text"])).try &.to_s || ""+ playlist_thumbnail = document.xpath_node(%q(//div[@class="pl-header-thumb"]/img)).try &.["data-thumb"]? ||+ document.xpath_node(%q(//div[@class="pl-header-thumb"]/img)).try &.["src"]+# YouTube allows anonymous playlists, so most of this can be empty or optionalanchor = document.xpath_node(%q(//ul[@class="pl-header-details"]))author = anchor.try &.xpath_node(%q(.//li[1]/a)).try &.content@@ -234,15 +238,12 @@ def fetch_playlist(plid, locale)video_count = anchor.try &.xpath_node(%q(.//li[2])).try &.content.gsub(/\D/, "").to_i?video_count ||= 0- views = anchor.try &.xpath_node(%q(.//li[3])).try &.content.delete("No views, ").to_i64?++ views = anchor.try &.xpath_node(%q(.//li[3])).try &.content.gsub(/\D/, "").to_i64?views ||= 0_i64- updated = anchor.try &.xpath_node(%q(.//li[4])).try &.content.lchop("Last updated on ").lchop("Updated ")- if updated- updated = decode_date(updated)- else- updated = Time.utc- end+ updated = anchor.try &.xpath_node(%q(.//li[4])).try &.content.lchop("Last updated on ").lchop("Updated ").try { |date| decode_date(date) }+ updated ||= Time.utcplaylist = Playlist.new(title: title,@@ -253,7 +254,8 @@ def fetch_playlist(plid, locale)description_html: description_html,video_count: video_count,views: views,- updated: updated+ updated: updated,+ thumbnail: playlist_thumbnail,)return playlistdiff --git a/src/invidious/search.cr b/src/invidious/search.crindex 784e3897..7a36f32e 100644--- a/src/invidious/search.cr+++ b/src/invidious/search.cr@@ -117,6 +117,7 @@ struct SearchPlaylistjson.field "type", "playlist"json.field "title", self.titlejson.field "playlistId", self.id+ json.field "playlistThumbnail", self.thumbnailjson.field "author", self.authorjson.field "authorId", self.ucid