diff --git a/src/invidious.cr b/src/invidious.cr index 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.likes json.field "dislikeCount", video.dislikes + json.field "paid", video.paid + json.field "premium", video.premium json.field "isFamilyFriendly", video.is_family_friendly json.field "allowedRegions", video.allowed_regions json.field "genre", video.genre @@ -2602,6 +2604,8 @@ get "/api/v1/channels/:ucid" do |env| json.field "published", video.published.epoch json.field "publishedText", "#{recode_date(video.published)} ago" json.field "lengthSeconds", video.length_seconds + json.field "paid", video.paid + json.field "premium", video.premium end end end @@ -2657,6 +2661,8 @@ end json.field "published", video.published.epoch json.field "publishedText", "#{recode_date(video.published)} ago" json.field "lengthSeconds", video.length_seconds + json.field "paid", video.paid + json.field "premium", video.premium end end end @@ -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_seconds json.field "liveNow", item.live_now + json.field "paid", item.paid + json.field "premium", item.premium when SearchPlaylist json.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_seconds json.field "liveNow", item.live_now + json.field "paid", item.paid + json.field "premium", item.premium when SearchPlaylist json.field "type", "playlist" json.field "title", item.title diff --git a/src/invidious/helpers/helpers.cr b/src/invidious/helpers/helpers.cr index 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 = false end + 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 ) end end diff --git a/src/invidious/search.cr b/src/invidious/search.cr index 98d1cdfb..3f4274bb 100644 --- a/src/invidious/search.cr +++ b/src/invidious/search.cr @@ -10,6 +10,8 @@ class SearchVideo description_html: String, length_seconds: Int32, live_now: Bool, + paid: Bool, + premium: Bool, }) end diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index 1d823cc4..2e1a828c 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -407,6 +407,23 @@ class Video return @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 captions captions = [] of Caption if player_response["captions"]?