diff options
| author | Omar Roth <omarroth@hotmail.com> | 2018-11-27 22:07:45 -0600 |
|---|---|---|
| committer | Omar Roth <omarroth@hotmail.com> | 2018-11-27 22:07:45 -0600 |
| commit | 6033e8aed18fe44dc70641297f83857982bf9343 (patch) | |
| tree | c26e69aec9b46d4b6371d2996357052912a208a9 | |
| parent | 32bd593a8a745422cab7ed9851d8a0e6ee21c040 (diff) | |
| download | invidious-6033e8aed18fe44dc70641297f83857982bf9343.tar.gz invidious-6033e8aed18fe44dc70641297f83857982bf9343.tar.bz2 invidious-6033e8aed18fe44dc70641297f83857982bf9343.zip | |
Add related_channels to /api/v1/channels
| -rw-r--r-- | src/invidious.cr | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/invidious.cr b/src/invidious.cr index 863e2a9a..724ba3a6 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -2713,6 +2713,29 @@ get "/api/v1/channels/:ucid" do |env| is_family_friendly = channel_html.xpath_node(%q(//meta[@itemprop="isFamilyFriendly"])).not_nil!["content"] == "True" allowed_regions = channel_html.xpath_node(%q(//meta[@itemprop="regionsAllowed"])).not_nil!["content"].split(",") + related_channels = channel_html.xpath_nodes(%q(//div[contains(@class, "branded-page-related-channels")]/ul/li)) + related_channels = related_channels.map do |node| + related_id = node["data-external-id"]? + related_id ||= "" + + anchor = node.xpath_node(%q(.//h3[contains(@class, "yt-lockup-title")]/a)) + related_title = anchor.try &.["title"] + related_title ||= "" + + related_author_url = anchor.try &.["href"] + related_author_url ||= "" + + related_author_thumbnail = node.xpath_node(%q(.//img)).try &.["data-thumb"] + related_author_thumbnail ||= "" + + { + id: related_id, + author: related_title, + author_url: related_author_url, + author_thumbnail: related_author_thumbnail, + } + end + total_views = 0_i64 sub_count = 0_i64 joined = Time.unix(0) @@ -2815,6 +2838,32 @@ get "/api/v1/channels/:ucid" do |env| end end end + + json.field "relatedChannels" do + json.array do + related_channels.each do |related_channel| + json.object do + json.field "author", related_channel[:author] + json.field "authorId", related_channel[:id] + json.field "authorUrl", related_channel[:author_url] + + json.field "authorThumbnails" do + json.array do + qualities = [32, 48, 76, 100, 176, 512] + + qualities.each do |quality| + json.object do + json.field "url", related_channel[:author_thumbnail].gsub("=s48-", "=s#{quality}-") + json.field "width", quality + json.field "height", quality + end + end + end + end + end + end + end + end end end |
