forked from Fijxu/invidious
Videos: Completly disable annotations due to archive.org being down
Closes #15
This commit is contained in:
parent
eb2670fe49
commit
cf5028d09a
1 changed files with 42 additions and 41 deletions
|
@ -263,59 +263,60 @@ module Invidious::Routes::API::V1::Videos
|
||||||
|
|
||||||
annotations = ""
|
annotations = ""
|
||||||
|
|
||||||
case source
|
# case source
|
||||||
when "archive"
|
# when "archive"
|
||||||
if CONFIG.cache_annotations && (cached_annotation = Invidious::Database::Annotations.select(id))
|
# if CONFIG.cache_annotations && (cached_annotation = Invidious::Database::Annotations.select(id))
|
||||||
annotations = cached_annotation.annotations
|
# annotations = cached_annotation.annotations
|
||||||
else
|
# else
|
||||||
index = CHARS_SAFE.index!(id[0]).to_s.rjust(2, '0')
|
# index = CHARS_SAFE.index!(id[0]).to_s.rjust(2, '0')
|
||||||
|
|
||||||
# IA doesn't handle leading hyphens,
|
# # IA doesn't handle leading hyphens,
|
||||||
# so we use https://archive.org/details/youtubeannotations_64
|
# # so we use https://archive.org/details/youtubeannotations_64
|
||||||
if index == "62"
|
# if index == "62"
|
||||||
index = "64"
|
# index = "64"
|
||||||
id = id.sub(/^-/, 'A')
|
# id = id.sub(/^-/, 'A')
|
||||||
end
|
# end
|
||||||
|
|
||||||
file = URI.encode_www_form("#{id[0, 3]}/#{id}.xml")
|
# file = URI.encode_www_form("#{id[0, 3]}/#{id}.xml")
|
||||||
|
|
||||||
location = make_client(ARCHIVE_URL, &.get("/download/youtubeannotations_#{index}/#{id[0, 2]}.tar/#{file}"))
|
# location = make_client(ARCHIVE_URL, &.get("/download/youtubeannotations_#{index}/#{id[0, 2]}.tar/#{file}"))
|
||||||
|
|
||||||
if !location.headers["Location"]?
|
# if !location.headers["Location"]?
|
||||||
env.response.status_code = location.status_code
|
# env.response.status_code = location.status_code
|
||||||
end
|
# end
|
||||||
|
|
||||||
response = make_client(URI.parse(location.headers["Location"]), &.get(location.headers["Location"]))
|
# response = make_client(URI.parse(location.headers["Location"]), &.get(location.headers["Location"]))
|
||||||
|
|
||||||
if response.body.empty?
|
# if response.body.empty?
|
||||||
haltf env, 404
|
# haltf env, 404
|
||||||
end
|
# end
|
||||||
|
|
||||||
if response.status_code != 200
|
# if response.status_code != 200
|
||||||
haltf env, response.status_code
|
# haltf env, response.status_code
|
||||||
end
|
# end
|
||||||
|
|
||||||
annotations = response.body
|
# annotations = response.body
|
||||||
|
|
||||||
cache_annotation(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}")
|
||||||
|
|
||||||
if response.status_code != 200
|
# if response.status_code != 200
|
||||||
haltf env, response.status_code
|
# haltf env, response.status_code
|
||||||
end
|
# end
|
||||||
|
|
||||||
annotations = response.body
|
# annotations = response.body
|
||||||
end
|
# end
|
||||||
|
|
||||||
etag = sha256(annotations)[0, 16]
|
# etag = sha256(annotations)[0, 16]
|
||||||
if env.request.headers["If-None-Match"]?.try &.== etag
|
# if env.request.headers["If-None-Match"]?.try &.== etag
|
||||||
haltf env, 304
|
# haltf env, 304
|
||||||
else
|
# else
|
||||||
env.response.headers["ETag"] = etag
|
# env.response.headers["ETag"] = etag
|
||||||
annotations
|
# annotations
|
||||||
end
|
# end
|
||||||
|
annotations
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.comments(env)
|
def self.comments(env)
|
||||||
|
|
Loading…
Reference in a new issue