mirror of
https://github.com/iv-org/invidious.git
synced 2024-11-02 17:03:25 +05:30
Clean useless database arguments (4/5)
This commit is contained in:
parent
40ed4a0506
commit
d74873fed1
@ -793,7 +793,7 @@ post "/data_control" do |env|
|
|||||||
next if !video_id
|
next if !video_id
|
||||||
|
|
||||||
begin
|
begin
|
||||||
video = get_video(video_id, PG_DB)
|
video = get_video(video_id)
|
||||||
rescue ex
|
rescue ex
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
@ -60,7 +60,7 @@ def html_to_content(description_html : String)
|
|||||||
return description
|
return description
|
||||||
end
|
end
|
||||||
|
|
||||||
def cache_annotation(db, id, annotations)
|
def cache_annotation(id, annotations)
|
||||||
if !CONFIG.cache_annotations
|
if !CONFIG.cache_annotations
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -99,7 +99,7 @@ def create_notification_stream(env, topics, connection_channel)
|
|||||||
published = Time.utc - Time::Span.new(days: time_span[0], hours: time_span[1], minutes: time_span[2], seconds: time_span[3])
|
published = Time.utc - Time::Span.new(days: time_span[0], hours: time_span[1], minutes: time_span[2], seconds: time_span[3])
|
||||||
video_id = TEST_IDS[rand(TEST_IDS.size)]
|
video_id = TEST_IDS[rand(TEST_IDS.size)]
|
||||||
|
|
||||||
video = get_video(video_id, PG_DB)
|
video = get_video(video_id)
|
||||||
video.published = published
|
video.published = published
|
||||||
response = JSON.parse(video.to_json(locale, nil))
|
response = JSON.parse(video.to_json(locale, nil))
|
||||||
|
|
||||||
@ -176,7 +176,7 @@ def create_notification_stream(env, topics, connection_channel)
|
|||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
video = get_video(video_id, PG_DB)
|
video = get_video(video_id)
|
||||||
video.published = Time.unix(published)
|
video.published = Time.unix(published)
|
||||||
response = JSON.parse(video.to_json(locale, nil))
|
response = JSON.parse(video.to_json(locale, nil))
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ module Invidious::Routes::API::Manifest
|
|||||||
unique_res = env.params.query["unique_res"]?.try { |q| (q == "true" || q == "1").to_unsafe }
|
unique_res = env.params.query["unique_res"]?.try { |q| (q == "true" || q == "1").to_unsafe }
|
||||||
|
|
||||||
begin
|
begin
|
||||||
video = get_video(id, PG_DB, region: region)
|
video = get_video(id, region: region)
|
||||||
rescue ex : VideoRedirect
|
rescue ex : VideoRedirect
|
||||||
return env.redirect env.request.resource.gsub(id, ex.video_id)
|
return env.redirect env.request.resource.gsub(id, ex.video_id)
|
||||||
rescue ex
|
rescue ex
|
||||||
|
@ -245,7 +245,7 @@ module Invidious::Routes::API::V1::Authenticated
|
|||||||
end
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
video = get_video(video_id, PG_DB)
|
video = get_video(video_id)
|
||||||
rescue ex
|
rescue ex
|
||||||
return error_json(500, ex)
|
return error_json(500, ex)
|
||||||
end
|
end
|
||||||
|
@ -8,7 +8,7 @@ module Invidious::Routes::API::V1::Videos
|
|||||||
region = env.params.query["region"]?
|
region = env.params.query["region"]?
|
||||||
|
|
||||||
begin
|
begin
|
||||||
video = get_video(id, PG_DB, region: region)
|
video = get_video(id, region: region)
|
||||||
rescue ex : VideoRedirect
|
rescue ex : VideoRedirect
|
||||||
env.response.headers["Location"] = env.request.resource.gsub(id, ex.video_id)
|
env.response.headers["Location"] = env.request.resource.gsub(id, ex.video_id)
|
||||||
return error_json(302, "Video is unavailable", {"videoId" => ex.video_id})
|
return error_json(302, "Video is unavailable", {"videoId" => ex.video_id})
|
||||||
@ -36,7 +36,7 @@ module Invidious::Routes::API::V1::Videos
|
|||||||
# getting video info.
|
# getting video info.
|
||||||
|
|
||||||
begin
|
begin
|
||||||
video = get_video(id, PG_DB, region: region)
|
video = get_video(id, region: region)
|
||||||
rescue ex : VideoRedirect
|
rescue ex : VideoRedirect
|
||||||
env.response.headers["Location"] = env.request.resource.gsub(id, ex.video_id)
|
env.response.headers["Location"] = env.request.resource.gsub(id, ex.video_id)
|
||||||
return error_json(302, "Video is unavailable", {"videoId" => ex.video_id})
|
return error_json(302, "Video is unavailable", {"videoId" => ex.video_id})
|
||||||
@ -157,7 +157,7 @@ module Invidious::Routes::API::V1::Videos
|
|||||||
region = env.params.query["region"]?
|
region = env.params.query["region"]?
|
||||||
|
|
||||||
begin
|
begin
|
||||||
video = get_video(id, PG_DB, region: region)
|
video = get_video(id, region: region)
|
||||||
rescue ex : VideoRedirect
|
rescue ex : VideoRedirect
|
||||||
env.response.headers["Location"] = env.request.resource.gsub(id, ex.video_id)
|
env.response.headers["Location"] = env.request.resource.gsub(id, ex.video_id)
|
||||||
return error_json(302, "Video is unavailable", {"videoId" => ex.video_id})
|
return error_json(302, "Video is unavailable", {"videoId" => ex.video_id})
|
||||||
@ -271,7 +271,7 @@ module Invidious::Routes::API::V1::Videos
|
|||||||
|
|
||||||
annotations = response.body
|
annotations = response.body
|
||||||
|
|
||||||
cache_annotation(PG_DB, id, annotations)
|
cache_annotation(id, annotations)
|
||||||
end
|
end
|
||||||
else # "youtube"
|
else # "youtube"
|
||||||
response = YT_POOL.client &.get("/annotations_invideo?video_id=#{id}")
|
response = YT_POOL.client &.get("/annotations_invideo?video_id=#{id}")
|
||||||
|
@ -30,7 +30,7 @@ module Invidious::Routes::Embed
|
|||||||
id = env.params.url["id"]
|
id = env.params.url["id"]
|
||||||
|
|
||||||
plid = env.params.query["list"]?.try &.gsub(/[^a-zA-Z0-9_-]/, "")
|
plid = env.params.query["list"]?.try &.gsub(/[^a-zA-Z0-9_-]/, "")
|
||||||
continuation = process_continuation(PG_DB, env.params.query, plid, id)
|
continuation = process_continuation(env.params.query, plid, id)
|
||||||
|
|
||||||
if md = env.params.query["playlist"]?
|
if md = env.params.query["playlist"]?
|
||||||
.try &.match(/[a-zA-Z0-9_-]{11}(,[a-zA-Z0-9_-]{11})*/)
|
.try &.match(/[a-zA-Z0-9_-]{11}(,[a-zA-Z0-9_-]{11})*/)
|
||||||
@ -119,7 +119,7 @@ module Invidious::Routes::Embed
|
|||||||
subscriptions ||= [] of String
|
subscriptions ||= [] of String
|
||||||
|
|
||||||
begin
|
begin
|
||||||
video = get_video(id, PG_DB, region: params.region)
|
video = get_video(id, region: params.region)
|
||||||
rescue ex : VideoRedirect
|
rescue ex : VideoRedirect
|
||||||
return env.redirect env.request.resource.gsub(id, ex.video_id)
|
return env.redirect env.request.resource.gsub(id, ex.video_id)
|
||||||
rescue ex
|
rescue ex
|
||||||
|
@ -393,7 +393,7 @@ module Invidious::Routes::Feeds
|
|||||||
published = Time.parse_rfc3339(entry.xpath_node("published").not_nil!.content)
|
published = Time.parse_rfc3339(entry.xpath_node("published").not_nil!.content)
|
||||||
updated = Time.parse_rfc3339(entry.xpath_node("updated").not_nil!.content)
|
updated = Time.parse_rfc3339(entry.xpath_node("updated").not_nil!.content)
|
||||||
|
|
||||||
video = get_video(id, PG_DB, force_refresh: true)
|
video = get_video(id, force_refresh: true)
|
||||||
|
|
||||||
# Deliver notifications to `/api/v1/auth/notifications`
|
# Deliver notifications to `/api/v1/auth/notifications`
|
||||||
payload = {
|
payload = {
|
||||||
|
@ -345,7 +345,7 @@ module Invidious::Routes::Playlists
|
|||||||
video_id = env.params.query["video_id"]
|
video_id = env.params.query["video_id"]
|
||||||
|
|
||||||
begin
|
begin
|
||||||
video = get_video(video_id, PG_DB)
|
video = get_video(video_id)
|
||||||
rescue ex
|
rescue ex
|
||||||
if redirect
|
if redirect
|
||||||
return error_template(500, ex)
|
return error_template(500, ex)
|
||||||
|
@ -263,7 +263,7 @@ module Invidious::Routes::VideoPlayback
|
|||||||
haltf env, status_code: 400, response: "TESTING"
|
haltf env, status_code: 400, response: "TESTING"
|
||||||
end
|
end
|
||||||
|
|
||||||
video = get_video(id, PG_DB, region: region)
|
video = get_video(id, region: region)
|
||||||
|
|
||||||
fmt = video.fmt_stream.find(nil) { |f| f["itag"].as_i == itag } || video.adaptive_fmts.find(nil) { |f| f["itag"].as_i == itag }
|
fmt = video.fmt_stream.find(nil) { |f| f["itag"].as_i == itag } || video.adaptive_fmts.find(nil) { |f| f["itag"].as_i == itag }
|
||||||
url = fmt.try &.["url"]?.try &.as_s
|
url = fmt.try &.["url"]?.try &.as_s
|
||||||
|
@ -39,7 +39,7 @@ module Invidious::Routes::Watch
|
|||||||
end
|
end
|
||||||
|
|
||||||
plid = env.params.query["list"]?.try &.gsub(/[^a-zA-Z0-9_-]/, "")
|
plid = env.params.query["list"]?.try &.gsub(/[^a-zA-Z0-9_-]/, "")
|
||||||
continuation = process_continuation(PG_DB, env.params.query, plid, id)
|
continuation = process_continuation(env.params.query, plid, id)
|
||||||
|
|
||||||
nojs = env.params.query["nojs"]?
|
nojs = env.params.query["nojs"]?
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ module Invidious::Routes::Watch
|
|||||||
env.params.query.delete_all("listen")
|
env.params.query.delete_all("listen")
|
||||||
|
|
||||||
begin
|
begin
|
||||||
video = get_video(id, PG_DB, region: params.region)
|
video = get_video(id, region: params.region)
|
||||||
rescue ex : VideoRedirect
|
rescue ex : VideoRedirect
|
||||||
return env.redirect env.request.resource.gsub(id, ex.video_id)
|
return env.redirect env.request.resource.gsub(id, ex.video_id)
|
||||||
rescue ex
|
rescue ex
|
||||||
|
@ -993,7 +993,7 @@ def extract_video_info(video_id : String, proxy_region : String? = nil, context_
|
|||||||
return params
|
return params
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_video(id, db, refresh = true, region = nil, force_refresh = false)
|
def get_video(id, refresh = true, region = nil, force_refresh = false)
|
||||||
if (video = Invidious::Database::Videos.select(id)) && !region
|
if (video = Invidious::Database::Videos.select(id)) && !region
|
||||||
# If record was last updated over 10 minutes ago, or video has since premiered,
|
# If record was last updated over 10 minutes ago, or video has since premiered,
|
||||||
# refresh (expire param in response lasts for 6 hours)
|
# refresh (expire param in response lasts for 6 hours)
|
||||||
@ -1056,7 +1056,7 @@ def itag_to_metadata?(itag : JSON::Any)
|
|||||||
return VIDEO_FORMATS[itag.to_s]?
|
return VIDEO_FORMATS[itag.to_s]?
|
||||||
end
|
end
|
||||||
|
|
||||||
def process_continuation(db, query, plid, id)
|
def process_continuation(query, plid, id)
|
||||||
continuation = nil
|
continuation = nil
|
||||||
if plid
|
if plid
|
||||||
if index = query["index"]?.try &.to_i?
|
if index = query["index"]?.try &.to_i?
|
||||||
|
Loading…
Reference in New Issue
Block a user