From 74b285d0f76bf07bf51132afde8fbede94e24c0e Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Tue, 25 Sep 2018 10:28:40 -0500 Subject: [PATCH] Add author thumbnails to playlist endpoint --- src/invidious.cr | 14 ++++++++++++++ src/invidious/playlists.cr | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/src/invidious.cr b/src/invidious.cr index f49a40a8..d4b44558 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -2839,6 +2839,20 @@ get "/api/v1/playlists/:plid" do |env| json.field "authorId", playlist.ucid json.field "authorUrl", "/channel/#{playlist.ucid}" + json.field "authorThumbnails" do + json.array do + qualities = [32, 48, 76, 100, 176, 512] + + qualities.each do |quality| + json.object do + json.field "url", playlist.author_thumbnail.gsub("=s100-", "=s#{quality}-") + json.field "width", quality + json.field "height", quality + end + end + end + end + json.field "description", playlist.description json.field "descriptionHtml", playlist.description_html json.field "videoCount", playlist.video_count diff --git a/src/invidious/playlists.cr b/src/invidious/playlists.cr index d78d68bf..48bfc1ef 100644 --- a/src/invidious/playlists.cr +++ b/src/invidious/playlists.cr @@ -3,6 +3,7 @@ class Playlist title: String, id: String, author: String, + author_thumbnail: String, ucid: String, description: String, description_html: String, @@ -164,6 +165,8 @@ def fetch_playlist(plid) anchor = document.xpath_node(%q(//ul[@class="pl-header-details"])).not_nil! author = anchor.xpath_node(%q(.//li[1]/a)).not_nil!.content + author_thumbnail = document.xpath_node(%q(//img[@class="channel-header-profile-image"])).try &.["src"] + author_thumbnail ||= "" ucid = anchor.xpath_node(%q(.//li[1]/a)).not_nil!["href"].split("/")[2] video_count = anchor.xpath_node(%q(.//li[2])).not_nil!.content.delete("videos, ").to_i @@ -181,6 +184,7 @@ def fetch_playlist(plid) title, plid, author, + author_thumbnail, ucid, description, description_html,