summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2018-10-16 11:15:14 -0500
committerOmar Roth <omarroth@hotmail.com>2018-10-16 11:15:14 -0500
commit1cfa1f65591cc02c96778b0783114cad2e202e36 (patch)
tree822ae3eb531e2ae81da8eb7e67e7c8fc613aaad6
parent8b69e2347108996baf9ceefa03f2a111fe15f1b2 (diff)
downloadinvidious-1cfa1f65591cc02c96778b0783114cad2e202e36.tar.gz
invidious-1cfa1f65591cc02c96778b0783114cad2e202e36.tar.bz2
invidious-1cfa1f65591cc02c96778b0783114cad2e202e36.zip
Add 'paid' and 'premium' flags to API
-rw-r--r--src/invidious.cr10
-rw-r--r--src/invidious/helpers/helpers.cr16
-rw-r--r--src/invidious/search.cr2
-rw-r--r--src/invidious/videos.cr17
4 files changed, 44 insertions, 1 deletions
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"]?