mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2022-08-14.git
synced 2024-08-15 00:53:20 +00:00
Add 'playlistThumbnail' to playlist objects
This commit is contained in:
parent
4c9975a7d9
commit
059f50dad4
4 changed files with 36 additions and 41 deletions
|
@ -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.title
|
||||
json.field "playlistId", playlist.id
|
||||
json.field "playlistThumbnail", playlist.thumbnail
|
||||
|
||||
json.field "author", playlist.author
|
||||
json.field "authorId", playlist.ucid
|
||||
|
|
|
@ -331,18 +331,8 @@ def extract_items(nodeset, ucid = nil, author_name = nil)
|
|||
next
|
||||
end
|
||||
|
||||
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)
|
|||
end
|
||||
|
||||
items << 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
|
||||
)
|
||||
end
|
||||
end
|
||||
|
@ -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"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -51,6 +51,7 @@ struct Playlist
|
|||
video_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 optional
|
||||
anchor = 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.utc
|
||||
|
||||
playlist = 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 playlist
|
||||
|
|
|
@ -117,6 +117,7 @@ struct SearchPlaylist
|
|||
json.field "type", "playlist"
|
||||
json.field "title", self.title
|
||||
json.field "playlistId", self.id
|
||||
json.field "playlistThumbnail", self.thumbnail
|
||||
|
||||
json.field "author", self.author
|
||||
json.field "authorId", self.ucid
|
||||
|
|
Loading…
Reference in a new issue