mirror of
https://github.com/iv-org/invidious.git
synced 2025-06-28 01:28:30 +00:00
feat: Instead of music, fetch subscription related videoids
This commit is contained in:
parent
8fd0b82c38
commit
c582e72ebc
@ -8,7 +8,7 @@ module Invidious::Routes::API::V1::Feeds
|
|||||||
trending_type = env.params.query["type"]?
|
trending_type = env.params.query["type"]?
|
||||||
|
|
||||||
begin
|
begin
|
||||||
trending, plid = fetch_trending(trending_type, region, locale)
|
trending, plid = fetch_trending(trending_type, region, locale, env)
|
||||||
rescue ex
|
rescue ex
|
||||||
return error_json(500, ex)
|
return error_json(500, ex)
|
||||||
end
|
end
|
||||||
|
@ -52,7 +52,7 @@ module Invidious::Routes::Feeds
|
|||||||
region ||= env.get("preferences").as(Preferences).region
|
region ||= env.get("preferences").as(Preferences).region
|
||||||
|
|
||||||
begin
|
begin
|
||||||
trending, plid = fetch_trending(trending_type, region, locale)
|
trending, plid = fetch_trending(trending_type, region, locale, env)
|
||||||
rescue ex
|
rescue ex
|
||||||
return error_template(500, ex)
|
return error_template(500, ex)
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
def fetch_trending(trending_type, region, locale)
|
def fetch_trending(trending_type, region, locale, env)
|
||||||
region ||= "US"
|
region ||= "US"
|
||||||
region = region.upcase
|
region = region.upcase
|
||||||
|
|
||||||
@ -6,7 +6,8 @@ def fetch_trending(trending_type, region, locale)
|
|||||||
|
|
||||||
case trending_type.try &.downcase
|
case trending_type.try &.downcase
|
||||||
when "music"
|
when "music"
|
||||||
params = "4gINGgt5dG1hX2NoYXJ0cw%3D%3D"
|
# params = "4gINGgt5dG1hX2NoYXJ0cw%3D%3D"
|
||||||
|
return fetch_subscription_related_videoids(env, region, locale)
|
||||||
when "gaming"
|
when "gaming"
|
||||||
params = "4gIcGhpnYW1pbmdfY29ycHVzX21vc3RfcG9wdWxhcg%3D%3D"
|
params = "4gIcGhpnYW1pbmdfY29ycHVzX21vc3RfcG9wdWxhcg%3D%3D"
|
||||||
when "movies"
|
when "movies"
|
||||||
@ -40,3 +41,33 @@ def fetch_trending(trending_type, region, locale)
|
|||||||
# Deduplicate items before returning results
|
# Deduplicate items before returning results
|
||||||
return extracted.select(SearchVideo).uniq!(&.id), plid
|
return extracted.select(SearchVideo).uniq!(&.id), plid
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def fetch_subscription_related_videoids(env, region, locale)
|
||||||
|
user = env.get("user").as(Invidious::User)
|
||||||
|
channel_videos, notifications = get_subscription_feed(user, 5, 1)
|
||||||
|
|
||||||
|
videos = [] of SearchVideo
|
||||||
|
channel_videos.each do |video|
|
||||||
|
video = get_video(video.id)
|
||||||
|
related = video.related_videos
|
||||||
|
related.each do |related_video|
|
||||||
|
related_id = related_video["id"]
|
||||||
|
videos << SearchVideo.new({
|
||||||
|
title: related_video["title"],
|
||||||
|
id: related_video["id"],
|
||||||
|
author: related_video["author"],
|
||||||
|
ucid: related_video["ucid"]? || "",
|
||||||
|
published: related_video["published"]?.try { |p| Time.parse_rfc3339(p) } || Time.utc,
|
||||||
|
views: related_video["view_count"]?.try &.to_i64 || 0_i64,
|
||||||
|
description_html: "", # not available
|
||||||
|
length_seconds: related_video["length_seconds"]?.try &.to_i || 0,
|
||||||
|
premiere_timestamp: nil,
|
||||||
|
author_verified: related_video["author_verified"]? == "true",
|
||||||
|
author_thumbnail: related_video["author_thumbnail"]?,
|
||||||
|
badges: VideoBadges::None,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return videos.uniq!(&.id), nil
|
||||||
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user