diff --git a/config/sql/videos.sql b/config/sql/videos.sql index 2a02ccdfe..b94405e9b 100644 --- a/config/sql/videos.sql +++ b/config/sql/videos.sql @@ -23,6 +23,7 @@ CREATE TABLE public.videos genre_url text COLLATE pg_catalog."default", license text COLLATE pg_catalog."default", sub_count_text text COLLATE pg_catalog."default", + author_thumbnail text COLLATE pg_catalog."default", CONSTRAINT videos_pkey PRIMARY KEY (id) ) WITH ( diff --git a/src/invidious.cr b/src/invidious.cr index 74c708209..b5312e5b9 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -2298,6 +2298,21 @@ get "/api/v1/videos/:id" do |env| json.field "author", video.author json.field "authorId", video.ucid json.field "authorUrl", "/channel/#{video.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", video.author_thumbnail.gsub("=s48-", "=s#{quality}-") + json.field "width", quality + json.field "height", quality + end + end + end + end + json.field "subCountText", video.sub_count_text json.field "lengthSeconds", video.info["length_seconds"].to_i diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index 864466a3c..28b0922b8 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -457,9 +457,10 @@ class Video genre: String, genre_url: String, license: String, - sub_count_text: { + sub_count_text: String, + author_thumbnail: { type: String, - default: "0", + default: "", }, }) end @@ -491,12 +492,20 @@ def get_video(id, db, proxies = {} of String => Array({ip: String, port: Int32}) video = fetch_video(id, proxies) video_array = video.to_a + # Migration point + video_array = video_array[0..-2] + args = arg_array(video_array[1..-1], 2) + # Migration point + # db.exec("UPDATE videos SET (info,updated,title,views,likes,dislikes,wilson_score,\ + # published,description,language,author,ucid,allowed_regions,is_family_friendly,\ + # genre,genre_url,license,sub_count_text,author_thumbnail)\ + # = (#{args}) WHERE id = $1", video_array) db.exec("UPDATE videos SET (info,updated,title,views,likes,dislikes,wilson_score,\ - published,description,language,author,ucid,allowed_regions,is_family_friendly,\ - genre,genre_url,license,sub_count_text)\ - = (#{args}) WHERE id = $1", video_array) + published,description,language,author,ucid,allowed_regions,is_family_friendly,\ + genre,genre_url,license,sub_count_text)\ + = (#{args}) WHERE id = $1", video_array) rescue ex db.exec("DELETE FROM videos * WHERE id = $1", id) raise ex @@ -506,6 +515,9 @@ def get_video(id, db, proxies = {} of String => Array({ip: String, port: Int32}) video = fetch_video(id, proxies) video_array = video.to_a + # Migration point + video_array = video_array[0..-2] + args = arg_array(video_array) db.exec("INSERT INTO videos VALUES (#{args}) ON CONFLICT (id) DO NOTHING", video_array) @@ -673,8 +685,15 @@ def fetch_video(id, proxies) sub_count_text = "0" end + author_thumbnail = html.xpath_node(%(//img[@alt="#{author}"])) + if author_thumbnail + author_thumbnail = author_thumbnail["data-thumb"] + else + author_thumbnail = "" + end + video = Video.new(id, info, Time.now, title, views, likes, dislikes, wilson_score, published, description, - nil, author, ucid, allowed_regions, is_family_friendly, genre, genre_url, license, sub_count_text) + nil, author, ucid, allowed_regions, is_family_friendly, genre, genre_url, license, sub_count_text, author_thumbnail) return video end