Add 'paid' and 'premium' flags to API

This commit is contained in:
Omar Roth 2018-10-16 11:15:14 -05:00
parent 8b69e23471
commit 1cfa1f6559
4 changed files with 44 additions and 1 deletions

View file

@ -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

View file

@ -10,6 +10,8 @@ class SearchVideo
description_html: String,
length_seconds: Int32,
live_now: Bool,
paid: Bool,
premium: Bool,
})
end

View file

@ -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"]?