mirror of
https://git.nadeko.net/Fijxu/invidious.git
synced 2025-12-24 11:58:50 +00:00
Merge branch 'master' into stream-sort
This commit is contained in:
@@ -6,6 +6,22 @@ module Invidious::Routes::API::V1::Misc
|
||||
if !CONFIG.statistics_enabled
|
||||
return {"software" => SOFTWARE}.to_json
|
||||
else
|
||||
# Calculate playback success rate
|
||||
if (tracker = Invidious::Jobs::StatisticsRefreshJob::STATISTICS["playback"]?)
|
||||
tracker = tracker.as(Hash(String, Int64 | Float64))
|
||||
|
||||
if !tracker.empty?
|
||||
total_requests = tracker["totalRequests"]
|
||||
success_count = tracker["successfulRequests"]
|
||||
|
||||
if total_requests.zero?
|
||||
tracker["ratio"] = 1_i64
|
||||
else
|
||||
tracker["ratio"] = (success_count / (total_requests)).round(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return Invidious::Jobs::StatisticsRefreshJob::STATISTICS.to_json
|
||||
end
|
||||
end
|
||||
@@ -175,6 +191,8 @@ module Invidious::Routes::API::V1::Misc
|
||||
json.object do
|
||||
json.field "ucid", sub_endpoint["browseId"].as_s if sub_endpoint["browseId"]?
|
||||
json.field "videoId", sub_endpoint["videoId"].as_s if sub_endpoint["videoId"]?
|
||||
json.field "playlistId", sub_endpoint["playlistId"].as_s if sub_endpoint["playlistId"]?
|
||||
json.field "startTimeSeconds", sub_endpoint["startTimeSeconds"].as_i if sub_endpoint["startTimeSeconds"]?
|
||||
json.field "params", params.try &.as_s
|
||||
json.field "pageType", pageType
|
||||
end
|
||||
|
||||
@@ -32,11 +32,14 @@ module Invidious::Routes::API::V1::Search
|
||||
|
||||
begin
|
||||
client = HTTP::Client.new("suggestqueries-clients6.youtube.com")
|
||||
url = "/complete/search?client=youtube&hl=en&gl=#{region}&q=#{URI.encode_www_form(query)}&xssi=t&gs_ri=youtube&ds=yt"
|
||||
client.before_request { |r| add_yt_headers(r) }
|
||||
|
||||
url = "/complete/search?client=youtube&hl=en&gl=#{region}&q=#{URI.encode_www_form(query)}&gs_ri=youtube&ds=yt"
|
||||
|
||||
response = client.get(url).body
|
||||
client.close
|
||||
|
||||
body = JSON.parse(response[5..-1]).as_a
|
||||
body = JSON.parse(response[19..-2]).as_a
|
||||
suggestions = body[1].as_a[0..-2]
|
||||
|
||||
JSON.build do |json|
|
||||
|
||||
@@ -363,4 +363,47 @@ module Invidious::Routes::API::V1::Videos
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.clips(env)
|
||||
locale = env.get("preferences").as(Preferences).locale
|
||||
|
||||
env.response.content_type = "application/json"
|
||||
|
||||
clip_id = env.params.url["id"]
|
||||
region = env.params.query["region"]?
|
||||
proxy = {"1", "true"}.any? &.== env.params.query["local"]?
|
||||
|
||||
response = YoutubeAPI.resolve_url("https://www.youtube.com/clip/#{clip_id}")
|
||||
return error_json(400, "Invalid clip ID") if response["error"]?
|
||||
|
||||
video_id = response.dig?("endpoint", "watchEndpoint", "videoId").try &.as_s
|
||||
return error_json(400, "Invalid clip ID") if video_id.nil?
|
||||
|
||||
start_time = nil
|
||||
end_time = nil
|
||||
clip_title = nil
|
||||
|
||||
if params = response.dig?("endpoint", "watchEndpoint", "params").try &.as_s
|
||||
start_time, end_time, clip_title = parse_clip_parameters(params)
|
||||
end
|
||||
|
||||
begin
|
||||
video = get_video(video_id, region: region)
|
||||
rescue ex : NotFoundException
|
||||
return error_json(404, ex)
|
||||
rescue ex
|
||||
return error_json(500, ex)
|
||||
end
|
||||
|
||||
return JSON.build do |json|
|
||||
json.object do
|
||||
json.field "startTime", start_time
|
||||
json.field "endTime", end_time
|
||||
json.field "clipTitle", clip_title
|
||||
json.field "video" do
|
||||
Invidious::JSONify::APIv1.video(video, json, locale: locale, proxy: proxy)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user