Invidious is an alternative front-end to YouTube
Add 'paid' and 'premium' flags to API
Omar Roth1cfa1f65591c
diff --git a/src/invidious.cr b/src/invidious.crindex 8edbb715..33ce260e 100644--- a/src/invidious.cr+++ b/src/invidious.cr@@ -2245,6 +2245,8 @@ get "/api/v1/videos/:id" do |env|json.field "likeCount", video.likesjson.field "dislikeCount", video.dislikes+ json.field "paid", video.paid+ json.field "premium", video.premiumjson.field "isFamilyFriendly", video.is_family_friendlyjson.field "allowedRegions", video.allowed_regionsjson.field "genre", video.genre@@ -2602,6 +2604,8 @@ get "/api/v1/channels/:ucid" do |env|json.field "published", video.published.epochjson.field "publishedText", "#{recode_date(video.published)} ago"json.field "lengthSeconds", video.length_seconds+ json.field "paid", video.paid+ json.field "premium", video.premiumendendend@@ -2657,6 +2661,8 @@ endjson.field "published", video.published.epochjson.field "publishedText", "#{recode_date(video.published)} ago"json.field "lengthSeconds", video.length_seconds+ json.field "paid", video.paid+ json.field "premium", video.premiumendendend@@ -2704,6 +2710,8 @@ get "/api/v1/channels/search/:ucid" do |env|json.field "publishedText", "#{recode_date(item.published)} ago"json.field "lengthSeconds", item.length_secondsjson.field "liveNow", item.live_now+ json.field "paid", item.paid+ json.field "premium", item.premiumwhen SearchPlaylistjson.field "type", "playlist"json.field "title", item.title@@ -2825,6 +2833,8 @@ get "/api/v1/search" do |env|json.field "publishedText", "#{recode_date(item.published)} ago"json.field "lengthSeconds", item.length_secondsjson.field "liveNow", item.live_now+ json.field "paid", item.paid+ json.field "premium", item.premiumwhen SearchPlaylistjson.field "type", "playlist"json.field "title", item.titlediff --git a/src/invidious/helpers/helpers.cr b/src/invidious/helpers/helpers.crindex 20bf47ef..c887f1a2 100644--- a/src/invidious/helpers/helpers.cr+++ b/src/invidious/helpers/helpers.cr@@ -358,6 +358,18 @@ def extract_items(nodeset, ucid = nil)live_now = falseend+ if node.xpath_node(%q(.//span[text()="Premium"]))+ premium = true+ else+ premium = false+ end++ if node.xpath_node(%q(.//span[contains(text(), "Get YouTube Premium")]))+ paid = true+ else+ paid = false+ end+items << SearchVideo.new(title,id,@@ -368,7 +380,9 @@ def extract_items(nodeset, ucid = nil)description,description_html,length_seconds,- live_now+ live_now,+ paid,+ premium)endenddiff --git a/src/invidious/search.cr b/src/invidious/search.crindex 98d1cdfb..3f4274bb 100644--- a/src/invidious/search.cr+++ b/src/invidious/search.cr@@ -10,6 +10,8 @@ class SearchVideodescription_html: String,length_seconds: Int32,live_now: Bool,+ paid: Bool,+ premium: Bool,})enddiff --git a/src/invidious/videos.cr b/src/invidious/videos.crindex 1d823cc4..2e1a828c 100644--- a/src/invidious/videos.cr+++ b/src/invidious/videos.cr@@ -407,6 +407,23 @@ class Videoreturn @player_json.not_nil!end+ def paid+ reason = self.player_response["playabilityStatus"]?.try &.["reason"]?++ if reason == "This video requires payment to watch."+ paid = true+ else+ paid = false+ end++ return paid+ end++ def premium+ premium = self.player_response.to_s.includes? "Get YouTube without the ads."+ return premium+ end+def captionscaptions = [] of Captionif player_response["captions"]?