mirror of
https://github.com/iv-org/invidious
synced 2024-11-09 01:10:27 +00:00
Add 'paid' and 'premium' flags to API
This commit is contained in:
parent
8b69e23471
commit
1cfa1f6559
@ -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
|
||||
|
@ -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
|
||||
|
@ -10,6 +10,8 @@ class SearchVideo
|
||||
description_html: String,
|
||||
length_seconds: Int32,
|
||||
live_now: Bool,
|
||||
paid: Bool,
|
||||
premium: Bool,
|
||||
})
|
||||
end
|
||||
|
||||
|
@ -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"]?
|
||||
|
Loading…
Reference in New Issue
Block a user