Channel: Render age restricted channels
This commit is contained in:
parent
e319c35f09
commit
96ade642fa
@ -15,7 +15,8 @@ record AboutChannel,
|
|||||||
allowed_regions : Array(String),
|
allowed_regions : Array(String),
|
||||||
tabs : Array(String),
|
tabs : Array(String),
|
||||||
tags : Array(String),
|
tags : Array(String),
|
||||||
verified : Bool
|
verified : Bool,
|
||||||
|
is_age_gated : Bool
|
||||||
|
|
||||||
def get_about_info(ucid, locale) : AboutChannel
|
def get_about_info(ucid, locale) : AboutChannel
|
||||||
begin
|
begin
|
||||||
@ -45,7 +46,22 @@ def get_about_info(ucid, locale) : AboutChannel
|
|||||||
end
|
end
|
||||||
|
|
||||||
tags = [] of String
|
tags = [] of String
|
||||||
|
tab_names = [] of String
|
||||||
|
total_views = 0_i64
|
||||||
|
joined = Time.unix(0)
|
||||||
|
|
||||||
|
if ageGate = initdata.dig?("contents", "twoColumnBrowseResultsRenderer", "tabs", 0, "tabRenderer", "content", "sectionListRenderer", "contents", 0, "channelAgeGateRenderer")
|
||||||
|
description_node = nil
|
||||||
|
author = ageGate["channelTitle"].as_s
|
||||||
|
ucid = initdata["responseContext"]["serviceTrackingParams"][0]["params"][0]["value"].as_s
|
||||||
|
author_url = "https://www.youtube.com/channel/" + ucid
|
||||||
|
author_thumbnail = ageGate["avatar"]["thumbnails"][0]["url"].as_s
|
||||||
|
banner = nil
|
||||||
|
is_family_friendly = false
|
||||||
|
is_age_gated = true
|
||||||
|
tab_names = ["videos", "shorts", "streams"]
|
||||||
|
auto_generated = false
|
||||||
|
else
|
||||||
if auto_generated
|
if auto_generated
|
||||||
author = initdata["header"]["interactiveTabbedHeaderRenderer"]["title"]["simpleText"].as_s
|
author = initdata["header"]["interactiveTabbedHeaderRenderer"]["title"]["simpleText"].as_s
|
||||||
author_url = initdata["microformat"]["microformatDataRenderer"]["urlCanonical"].as_s
|
author_url = initdata["microformat"]["microformatDataRenderer"]["urlCanonical"].as_s
|
||||||
@ -84,29 +100,6 @@ def get_about_info(ucid, locale) : AboutChannel
|
|||||||
end
|
end
|
||||||
|
|
||||||
is_family_friendly = initdata["microformat"]["microformatDataRenderer"]["familySafe"].as_bool
|
is_family_friendly = initdata["microformat"]["microformatDataRenderer"]["familySafe"].as_bool
|
||||||
|
|
||||||
allowed_regions = initdata
|
|
||||||
.dig?("microformat", "microformatDataRenderer", "availableCountries")
|
|
||||||
.try &.as_a.map(&.as_s) || [] of String
|
|
||||||
|
|
||||||
description = !description_node.nil? ? description_node.as_s : ""
|
|
||||||
description_html = HTML.escape(description)
|
|
||||||
|
|
||||||
if !description_node.nil?
|
|
||||||
if description_node.as_h?.nil?
|
|
||||||
description_node = text_to_parsed_content(description_node.as_s)
|
|
||||||
end
|
|
||||||
description_html = parse_content(description_node)
|
|
||||||
if description_html == "" && description != ""
|
|
||||||
description_html = HTML.escape(description)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
total_views = 0_i64
|
|
||||||
joined = Time.unix(0)
|
|
||||||
|
|
||||||
tab_names = [] of String
|
|
||||||
|
|
||||||
if tabs_json = initdata["contents"]["twoColumnBrowseResultsRenderer"]["tabs"]?
|
if tabs_json = initdata["contents"]["twoColumnBrowseResultsRenderer"]["tabs"]?
|
||||||
# Get the name of the tabs available on this channel
|
# Get the name of the tabs available on this channel
|
||||||
tab_names = tabs_json.as_a.compact_map do |entry|
|
tab_names = tabs_json.as_a.compact_map do |entry|
|
||||||
@ -147,6 +140,24 @@ def get_about_info(ucid, locale) : AboutChannel
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
allowed_regions = initdata
|
||||||
|
.dig?("microformat", "microformatDataRenderer", "availableCountries")
|
||||||
|
.try &.as_a.map(&.as_s) || [] of String
|
||||||
|
|
||||||
|
description = !description_node.nil? ? description_node.as_s : ""
|
||||||
|
description_html = HTML.escape(description)
|
||||||
|
|
||||||
|
if !description_node.nil?
|
||||||
|
if description_node.as_h?.nil?
|
||||||
|
description_node = text_to_parsed_content(description_node.as_s)
|
||||||
|
end
|
||||||
|
description_html = parse_content(description_node)
|
||||||
|
if description_html == "" && description != ""
|
||||||
|
description_html = HTML.escape(description)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
sub_count = 0
|
sub_count = 0
|
||||||
|
|
||||||
@ -177,6 +188,7 @@ def get_about_info(ucid, locale) : AboutChannel
|
|||||||
tabs: tab_names,
|
tabs: tab_names,
|
||||||
tags: tags,
|
tags: tags,
|
||||||
verified: author_verified || false,
|
verified: author_verified || false,
|
||||||
|
is_age_gated: is_age_gated || false,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -46,8 +46,14 @@ struct PlaylistVideo
|
|||||||
XML.build { |xml| to_xml(xml) }
|
XML.build { |xml| to_xml(xml) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_json(locale : String?, json : JSON::Builder)
|
||||||
|
to_json(json)
|
||||||
|
end
|
||||||
|
|
||||||
def to_json(json : JSON::Builder, index : Int32? = nil)
|
def to_json(json : JSON::Builder, index : Int32? = nil)
|
||||||
json.object do
|
json.object do
|
||||||
|
json.field "type", "video"
|
||||||
|
|
||||||
json.field "title", self.title
|
json.field "title", self.title
|
||||||
json.field "videoId", self.id
|
json.field "videoId", self.id
|
||||||
|
|
||||||
@ -67,6 +73,7 @@ struct PlaylistVideo
|
|||||||
end
|
end
|
||||||
|
|
||||||
json.field "lengthSeconds", self.length_seconds
|
json.field "lengthSeconds", self.length_seconds
|
||||||
|
json.field "liveNow", self.live_now
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -27,11 +27,22 @@ module Invidious::Routes::API::V1::Channels
|
|||||||
# Retrieve "sort by" setting from URL parameters
|
# Retrieve "sort by" setting from URL parameters
|
||||||
sort_by = env.params.query["sort_by"]?.try &.downcase || "newest"
|
sort_by = env.params.query["sort_by"]?.try &.downcase || "newest"
|
||||||
|
|
||||||
|
if channel.is_age_gated
|
||||||
|
begin
|
||||||
|
playlist = get_playlist(channel.ucid.sub("UC", "UULF"))
|
||||||
|
videos = get_playlist_videos(playlist, offset: 0)
|
||||||
|
rescue ex : InfoException
|
||||||
|
# playlist doesnt exist.
|
||||||
|
videos = [] of PlaylistVideo
|
||||||
|
end
|
||||||
|
next_continuation = nil
|
||||||
|
else
|
||||||
begin
|
begin
|
||||||
videos, _ = Channel::Tabs.get_videos(channel, sort_by: sort_by)
|
videos, _ = Channel::Tabs.get_videos(channel, sort_by: sort_by)
|
||||||
rescue ex
|
rescue ex
|
||||||
return error_json(500, ex)
|
return error_json(500, ex)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
JSON.build do |json|
|
JSON.build do |json|
|
||||||
# TODO: Refactor into `to_json` for InvidiousChannel
|
# TODO: Refactor into `to_json` for InvidiousChannel
|
||||||
@ -84,6 +95,7 @@ module Invidious::Routes::API::V1::Channels
|
|||||||
json.field "joined", channel.joined.to_unix
|
json.field "joined", channel.joined.to_unix
|
||||||
|
|
||||||
json.field "autoGenerated", channel.auto_generated
|
json.field "autoGenerated", channel.auto_generated
|
||||||
|
json.field "ageGated", channel.is_age_gated
|
||||||
json.field "isFamilyFriendly", channel.is_family_friendly
|
json.field "isFamilyFriendly", channel.is_family_friendly
|
||||||
json.field "description", html_to_content(channel.description_html)
|
json.field "description", html_to_content(channel.description_html)
|
||||||
json.field "descriptionHtml", channel.description_html
|
json.field "descriptionHtml", channel.description_html
|
||||||
@ -142,6 +154,16 @@ module Invidious::Routes::API::V1::Channels
|
|||||||
sort_by = env.params.query["sort_by"]?.try &.downcase || "newest"
|
sort_by = env.params.query["sort_by"]?.try &.downcase || "newest"
|
||||||
continuation = env.params.query["continuation"]?
|
continuation = env.params.query["continuation"]?
|
||||||
|
|
||||||
|
if channel.is_age_gated
|
||||||
|
begin
|
||||||
|
playlist = get_playlist(channel.ucid.sub("UC", "UULF"))
|
||||||
|
videos = get_playlist_videos(playlist, offset: 0)
|
||||||
|
rescue ex : InfoException
|
||||||
|
# playlist doesnt exist.
|
||||||
|
videos = [] of PlaylistVideo
|
||||||
|
end
|
||||||
|
next_continuation = nil
|
||||||
|
else
|
||||||
begin
|
begin
|
||||||
videos, next_continuation = Channel::Tabs.get_60_videos(
|
videos, next_continuation = Channel::Tabs.get_60_videos(
|
||||||
channel, continuation: continuation, sort_by: sort_by
|
channel, continuation: continuation, sort_by: sort_by
|
||||||
@ -149,6 +171,7 @@ module Invidious::Routes::API::V1::Channels
|
|||||||
rescue ex
|
rescue ex
|
||||||
return error_json(500, ex)
|
return error_json(500, ex)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return JSON.build do |json|
|
return JSON.build do |json|
|
||||||
json.object do
|
json.object do
|
||||||
@ -176,6 +199,16 @@ module Invidious::Routes::API::V1::Channels
|
|||||||
# Retrieve continuation from URL parameters
|
# Retrieve continuation from URL parameters
|
||||||
continuation = env.params.query["continuation"]?
|
continuation = env.params.query["continuation"]?
|
||||||
|
|
||||||
|
if channel.is_age_gated
|
||||||
|
begin
|
||||||
|
playlist = get_playlist(channel.ucid.sub("UC", "UUSH"))
|
||||||
|
videos = get_playlist_videos(playlist, offset: 0)
|
||||||
|
rescue ex : InfoException
|
||||||
|
# playlist doesnt exist.
|
||||||
|
videos = [] of PlaylistVideo
|
||||||
|
end
|
||||||
|
next_continuation = nil
|
||||||
|
else
|
||||||
begin
|
begin
|
||||||
videos, next_continuation = Channel::Tabs.get_shorts(
|
videos, next_continuation = Channel::Tabs.get_shorts(
|
||||||
channel, continuation: continuation
|
channel, continuation: continuation
|
||||||
@ -183,6 +216,7 @@ module Invidious::Routes::API::V1::Channels
|
|||||||
rescue ex
|
rescue ex
|
||||||
return error_json(500, ex)
|
return error_json(500, ex)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return JSON.build do |json|
|
return JSON.build do |json|
|
||||||
json.object do
|
json.object do
|
||||||
@ -211,6 +245,16 @@ module Invidious::Routes::API::V1::Channels
|
|||||||
sort_by = env.params.query["sort_by"]?.try &.downcase || "newest"
|
sort_by = env.params.query["sort_by"]?.try &.downcase || "newest"
|
||||||
continuation = env.params.query["continuation"]?
|
continuation = env.params.query["continuation"]?
|
||||||
|
|
||||||
|
if channel.is_age_gated
|
||||||
|
begin
|
||||||
|
playlist = get_playlist(channel.ucid.sub("UC", "UULV"))
|
||||||
|
videos = get_playlist_videos(playlist, offset: 0)
|
||||||
|
rescue ex : InfoException
|
||||||
|
# playlist doesnt exist.
|
||||||
|
videos = [] of PlaylistVideo
|
||||||
|
end
|
||||||
|
next_continuation = nil
|
||||||
|
else
|
||||||
begin
|
begin
|
||||||
videos, next_continuation = Channel::Tabs.get_60_livestreams(
|
videos, next_continuation = Channel::Tabs.get_60_livestreams(
|
||||||
channel, continuation: continuation, sort_by: sort_by
|
channel, continuation: continuation, sort_by: sort_by
|
||||||
@ -218,6 +262,7 @@ module Invidious::Routes::API::V1::Channels
|
|||||||
rescue ex
|
rescue ex
|
||||||
return error_json(500, ex)
|
return error_json(500, ex)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return JSON.build do |json|
|
return JSON.build do |json|
|
||||||
json.object do
|
json.object do
|
||||||
|
@ -36,13 +36,25 @@ module Invidious::Routes::Channels
|
|||||||
items = items.select(SearchPlaylist)
|
items = items.select(SearchPlaylist)
|
||||||
items.each(&.author = "")
|
items.each(&.author = "")
|
||||||
else
|
else
|
||||||
sort_options = {"newest", "oldest", "popular"}
|
|
||||||
|
|
||||||
# Fetch items and continuation token
|
# Fetch items and continuation token
|
||||||
|
if channel.is_age_gated
|
||||||
|
sort_by = ""
|
||||||
|
sort_options = [] of String
|
||||||
|
begin
|
||||||
|
playlist = get_playlist(channel.ucid.sub("UC", "UULF"))
|
||||||
|
items = get_playlist_videos(playlist, offset: 0)
|
||||||
|
rescue ex : InfoException
|
||||||
|
# playlist doesnt exist.
|
||||||
|
items = [] of PlaylistVideo
|
||||||
|
end
|
||||||
|
next_continuation = nil
|
||||||
|
else
|
||||||
|
sort_options = {"newest", "oldest", "popular"}
|
||||||
items, next_continuation = Channel::Tabs.get_videos(
|
items, next_continuation = Channel::Tabs.get_videos(
|
||||||
channel, continuation: continuation, sort_by: (sort_by || "newest")
|
channel, continuation: continuation, sort_by: (sort_by || "newest")
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
selected_tab = Frontend::ChannelPage::TabsAvailable::Videos
|
selected_tab = Frontend::ChannelPage::TabsAvailable::Videos
|
||||||
templated "channel"
|
templated "channel"
|
||||||
@ -58,6 +70,18 @@ module Invidious::Routes::Channels
|
|||||||
return env.redirect "/channel/#{channel.ucid}"
|
return env.redirect "/channel/#{channel.ucid}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if channel.is_age_gated
|
||||||
|
sort_by = ""
|
||||||
|
sort_options = [] of String
|
||||||
|
begin
|
||||||
|
playlist = get_playlist(channel.ucid.sub("UC", "UUSH"))
|
||||||
|
items = get_playlist_videos(playlist, offset: 0)
|
||||||
|
rescue ex : InfoException
|
||||||
|
# playlist doesnt exist.
|
||||||
|
items = [] of PlaylistVideo
|
||||||
|
end
|
||||||
|
next_continuation = nil
|
||||||
|
else
|
||||||
# TODO: support sort option for shorts
|
# TODO: support sort option for shorts
|
||||||
sort_by = ""
|
sort_by = ""
|
||||||
sort_options = [] of String
|
sort_options = [] of String
|
||||||
@ -66,6 +90,7 @@ module Invidious::Routes::Channels
|
|||||||
items, next_continuation = Channel::Tabs.get_shorts(
|
items, next_continuation = Channel::Tabs.get_shorts(
|
||||||
channel, continuation: continuation
|
channel, continuation: continuation
|
||||||
)
|
)
|
||||||
|
end
|
||||||
|
|
||||||
selected_tab = Frontend::ChannelPage::TabsAvailable::Shorts
|
selected_tab = Frontend::ChannelPage::TabsAvailable::Shorts
|
||||||
templated "channel"
|
templated "channel"
|
||||||
@ -81,6 +106,18 @@ module Invidious::Routes::Channels
|
|||||||
return env.redirect "/channel/#{channel.ucid}"
|
return env.redirect "/channel/#{channel.ucid}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if channel.is_age_gated
|
||||||
|
sort_by = ""
|
||||||
|
sort_options = [] of String
|
||||||
|
begin
|
||||||
|
playlist = get_playlist(channel.ucid.sub("UC", "UULV"))
|
||||||
|
items = get_playlist_videos(playlist, offset: 0)
|
||||||
|
rescue ex : InfoException
|
||||||
|
# playlist doesnt exist.
|
||||||
|
items = [] of PlaylistVideo
|
||||||
|
end
|
||||||
|
next_continuation = nil
|
||||||
|
else
|
||||||
sort_by = env.params.query["sort_by"]?.try &.downcase || "newest"
|
sort_by = env.params.query["sort_by"]?.try &.downcase || "newest"
|
||||||
sort_options = {"newest", "oldest", "popular"}
|
sort_options = {"newest", "oldest", "popular"}
|
||||||
|
|
||||||
@ -88,6 +125,7 @@ module Invidious::Routes::Channels
|
|||||||
items, next_continuation = Channel::Tabs.get_60_livestreams(
|
items, next_continuation = Channel::Tabs.get_60_livestreams(
|
||||||
channel, continuation: continuation, sort_by: sort_by
|
channel, continuation: continuation, sort_by: sort_by
|
||||||
)
|
)
|
||||||
|
end
|
||||||
|
|
||||||
selected_tab = Frontend::ChannelPage::TabsAvailable::Streams
|
selected_tab = Frontend::ChannelPage::TabsAvailable::Streams
|
||||||
templated "channel"
|
templated "channel"
|
||||||
|
Loading…
Reference in New Issue
Block a user