From dce5816b18e201a66419010a1b2e0e7e24a6f1db Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Wed, 31 Jul 2019 19:16:09 -0500 Subject: [PATCH] Fix image url extractor --- src/invidious.cr | 6 +++--- src/invidious/channels.cr | 3 ++- src/invidious/search.cr | 2 +- src/invidious/videos.cr | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index c43af729..d6479002 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -3739,7 +3739,7 @@ get "/api/v1/channels/:ucid" do |env| qualities.each do |quality| json.object do - json.field "url", channel.author_thumbnail.gsub("=s100-", "=s#{quality}-") + json.field "url", channel.author_thumbnail.gsub(/=\d+/, "=s#{quality}") json.field "width", quality json.field "height", quality end @@ -3781,7 +3781,7 @@ get "/api/v1/channels/:ucid" do |env| qualities.each do |quality| json.object do - json.field "url", related_channel.author_thumbnail.gsub("=s48-", "=s#{quality}-") + json.field "url", related_channel.author_thumbnail.gsub(/=\d+/, "=s#{quality}") json.field "width", quality json.field "height", quality end @@ -4079,7 +4079,7 @@ get "/api/v1/playlists/:plid" do |env| qualities.each do |quality| json.object do - json.field "url", playlist.author_thumbnail.gsub("=s100-", "=s#{quality}-") + json.field "url", playlist.author_thumbnail.gsub(/=\d+/, "=s#{quality}") json.field "width", quality json.field "height", quality end diff --git a/src/invidious/channels.cr b/src/invidious/channels.cr index 988b39f4..792ed288 100644 --- a/src/invidious/channels.cr +++ b/src/invidious/channels.cr @@ -804,12 +804,13 @@ def fetch_channel_community(ucid, continuation, locale, config, kemal_config, fo width = thumbnail["width"].as_i height = thumbnail["height"].as_i aspect_ratio = (width.to_f / height.to_f) + url = thumbnail["url"].as_s.gsub(/=w\d+-h\d+(-p)?(-nd)?(-df)?(-rwa)?/, "=s640") qualities = {320, 560, 640, 1280, 2000} qualities.each do |quality| json.object do - json.field "url", thumbnail["url"].as_s.gsub("=s640-", "=s#{quality}-") + json.field "url", url.gsub(/=s\d+/, "=s#{quality}") json.field "width", quality json.field "height", (quality / aspect_ratio).ceil.to_i end diff --git a/src/invidious/search.cr b/src/invidious/search.cr index 79bfd55a..1d4805bf 100644 --- a/src/invidious/search.cr +++ b/src/invidious/search.cr @@ -176,7 +176,7 @@ struct SearchChannel qualities.each do |quality| json.object do - json.field "url", self.author_thumbnail.gsub("=s176-", "=s#{quality}-") + json.field "url", self.author_thumbnail.gsub(/=\d+/, "=s#{quality}") json.field "width", quality json.field "height", quality end diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index ea02b938..49ff0494 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -319,7 +319,7 @@ struct Video qualities.each do |quality| json.object do - json.field "url", self.author_thumbnail.gsub("=s48-", "=s#{quality}-") + json.field "url", self.author_thumbnail.gsub(/=s\d+/, "=s#{quality}") json.field "width", quality json.field "height", quality end