|
|
@ -1385,7 +1385,8 @@ get "/mark_watched" do |env|
|
|
|
|
|
|
|
|
|
|
|
|
id = env.params.query["id"]?
|
|
|
|
id = env.params.query["id"]?
|
|
|
|
if !id
|
|
|
|
if !id
|
|
|
|
halt env, status_code: 400
|
|
|
|
env.response.status_code = 400
|
|
|
|
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
redirect = env.params.query["redirect"]?
|
|
|
|
redirect = env.params.query["redirect"]?
|
|
|
@ -1415,7 +1416,8 @@ get "/mark_unwatched" do |env|
|
|
|
|
|
|
|
|
|
|
|
|
id = env.params.query["id"]?
|
|
|
|
id = env.params.query["id"]?
|
|
|
|
if !id
|
|
|
|
if !id
|
|
|
|
halt env, status_code: 400
|
|
|
|
env.response.status_code = 400
|
|
|
|
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
redirect = env.params.query["redirect"]?
|
|
|
|
redirect = env.params.query["redirect"]?
|
|
|
@ -2071,7 +2073,8 @@ get "/feed/channel/:ucid" do |env|
|
|
|
|
author, ucid, auto_generated = get_about_info(ucid, locale)
|
|
|
|
author, ucid, auto_generated = get_about_info(ucid, locale)
|
|
|
|
rescue ex
|
|
|
|
rescue ex
|
|
|
|
error_message = ex.message
|
|
|
|
error_message = ex.message
|
|
|
|
halt env, status_code: 500, response: error_message
|
|
|
|
env.response.status_code = 500
|
|
|
|
|
|
|
|
next error_message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
client = make_client(YT_URL)
|
|
|
|
client = make_client(YT_URL)
|
|
|
@ -2181,12 +2184,14 @@ get "/feed/private" do |env|
|
|
|
|
token = env.params.query["token"]?
|
|
|
|
token = env.params.query["token"]?
|
|
|
|
|
|
|
|
|
|
|
|
if !token
|
|
|
|
if !token
|
|
|
|
halt env, status_code: 403
|
|
|
|
env.response.status_code = 403
|
|
|
|
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
user = PG_DB.query_one?("SELECT * FROM users WHERE token = $1", token.strip, as: User)
|
|
|
|
user = PG_DB.query_one?("SELECT * FROM users WHERE token = $1", token.strip, as: User)
|
|
|
|
if !user
|
|
|
|
if !user
|
|
|
|
halt env, status_code: 403
|
|
|
|
env.response.status_code = 403
|
|
|
|
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
max_results = env.params.query["max_results"]?.try &.to_i?
|
|
|
|
max_results = env.params.query["max_results"]?.try &.to_i?
|
|
|
@ -2342,17 +2347,20 @@ get "/feed/webhook/:token" do |env|
|
|
|
|
|
|
|
|
|
|
|
|
# The hub will sometimes check if we're still subscribed after delivery errors
|
|
|
|
# The hub will sometimes check if we're still subscribed after delivery errors
|
|
|
|
if Time.now.to_unix - time.to_i > 432000
|
|
|
|
if Time.now.to_unix - time.to_i > 432000
|
|
|
|
halt env, status_code: 400
|
|
|
|
env.response.status_code = 400
|
|
|
|
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if OpenSSL::HMAC.hexdigest(:sha1, HMAC_KEY, data) != signature
|
|
|
|
if OpenSSL::HMAC.hexdigest(:sha1, HMAC_KEY, data) != signature
|
|
|
|
halt env, status_code: 400
|
|
|
|
env.response.status_code = 400
|
|
|
|
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
ucid = HTTP::Params.parse(URI.parse(topic).query.not_nil!)["channel_id"]
|
|
|
|
ucid = HTTP::Params.parse(URI.parse(topic).query.not_nil!)["channel_id"]
|
|
|
|
PG_DB.exec("UPDATE channels SET subscribed = $1 WHERE id = $2", Time.now, ucid)
|
|
|
|
PG_DB.exec("UPDATE channels SET subscribed = $1 WHERE id = $2", Time.now, ucid)
|
|
|
|
|
|
|
|
|
|
|
|
halt env, status_code: 200, response: challenge
|
|
|
|
env.response.status_code = 200
|
|
|
|
|
|
|
|
next challenge
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
post "/feed/webhook/:token" do |env|
|
|
|
|
post "/feed/webhook/:token" do |env|
|
|
|
@ -2362,7 +2370,8 @@ post "/feed/webhook/:token" do |env|
|
|
|
|
|
|
|
|
|
|
|
|
if signature != OpenSSL::HMAC.hexdigest(:sha1, HMAC_KEY, body)
|
|
|
|
if signature != OpenSSL::HMAC.hexdigest(:sha1, HMAC_KEY, body)
|
|
|
|
logger.write("#{token} : Invalid signature")
|
|
|
|
logger.write("#{token} : Invalid signature")
|
|
|
|
halt env, status_code: 200
|
|
|
|
env.response.status_code = 200
|
|
|
|
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
spawn do
|
|
|
|
spawn do
|
|
|
@ -2388,7 +2397,8 @@ post "/feed/webhook/:token" do |env|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
halt env, status_code: 200
|
|
|
|
env.response.status_code = 200
|
|
|
|
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Channels
|
|
|
|
# Channels
|
|
|
@ -2550,19 +2560,17 @@ get "/api/v1/stats" do |env|
|
|
|
|
|
|
|
|
|
|
|
|
if !config.statistics_enabled
|
|
|
|
if !config.statistics_enabled
|
|
|
|
error_message = {"error" => "Statistics are not enabled."}.to_json
|
|
|
|
error_message = {"error" => "Statistics are not enabled."}.to_json
|
|
|
|
halt env, status_code: 400, response: error_message
|
|
|
|
env.response.status_code = 400
|
|
|
|
|
|
|
|
next error_message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if statistics["error"]?
|
|
|
|
if statistics["error"]?
|
|
|
|
halt env, status_code: 500, response: statistics.to_json
|
|
|
|
env.response.status_code = 500
|
|
|
|
|
|
|
|
next statistics.to_json
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if env.params.query["pretty"]? && env.params.query["pretty"] == "1"
|
|
|
|
|
|
|
|
statistics.to_pretty_json
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
statistics.to_json
|
|
|
|
statistics.to_json
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get "/api/v1/captions/:id" do |env|
|
|
|
|
get "/api/v1/captions/:id" do |env|
|
|
|
|
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
|
|
|
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
|
|
@ -2578,7 +2586,8 @@ get "/api/v1/captions/:id" do |env|
|
|
|
|
rescue ex : VideoRedirect
|
|
|
|
rescue ex : VideoRedirect
|
|
|
|
next env.redirect "/api/v1/captions/#{ex.message}"
|
|
|
|
next env.redirect "/api/v1/captions/#{ex.message}"
|
|
|
|
rescue ex
|
|
|
|
rescue ex
|
|
|
|
halt env, status_code: 500
|
|
|
|
env.response.status_code = 500
|
|
|
|
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
captions = video.captions
|
|
|
|
captions = video.captions
|
|
|
@ -2604,12 +2613,8 @@ get "/api/v1/captions/:id" do |env|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if env.params.query["pretty"]? && env.params.query["pretty"] == "1"
|
|
|
|
|
|
|
|
next JSON.parse(response).to_pretty_json
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
next response
|
|
|
|
next response
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
env.response.content_type = "text/vtt"
|
|
|
|
env.response.content_type = "text/vtt"
|
|
|
|
|
|
|
|
|
|
|
@ -2620,7 +2625,8 @@ get "/api/v1/captions/:id" do |env|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if caption.empty?
|
|
|
|
if caption.empty?
|
|
|
|
halt env, status_code: 404
|
|
|
|
env.response.status_code = 404
|
|
|
|
|
|
|
|
next
|
|
|
|
else
|
|
|
|
else
|
|
|
|
caption = caption[0]
|
|
|
|
caption = caption[0]
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -2690,7 +2696,8 @@ get "/api/v1/comments/:id" do |env|
|
|
|
|
comments = fetch_youtube_comments(id, PG_DB, continuation, proxies, format, locale, region)
|
|
|
|
comments = fetch_youtube_comments(id, PG_DB, continuation, proxies, format, locale, region)
|
|
|
|
rescue ex
|
|
|
|
rescue ex
|
|
|
|
error_message = {"error" => ex.message}.to_json
|
|
|
|
error_message = {"error" => ex.message}.to_json
|
|
|
|
halt env, status_code: 500, response: error_message
|
|
|
|
env.response.status_code = 500
|
|
|
|
|
|
|
|
next error_message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
next comments
|
|
|
|
next comments
|
|
|
@ -2708,18 +2715,15 @@ get "/api/v1/comments/:id" do |env|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if !reddit_thread || !comments
|
|
|
|
if !reddit_thread || !comments
|
|
|
|
halt env, status_code: 404
|
|
|
|
env.response.status_code = 404
|
|
|
|
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if format == "json"
|
|
|
|
if format == "json"
|
|
|
|
reddit_thread = JSON.parse(reddit_thread.to_json).as_h
|
|
|
|
reddit_thread = JSON.parse(reddit_thread.to_json).as_h
|
|
|
|
reddit_thread["comments"] = JSON.parse(comments.to_json)
|
|
|
|
reddit_thread["comments"] = JSON.parse(comments.to_json)
|
|
|
|
|
|
|
|
|
|
|
|
if env.params.query["pretty"]? && env.params.query["pretty"] == "1"
|
|
|
|
|
|
|
|
next reddit_thread.to_pretty_json
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
next reddit_thread.to_json
|
|
|
|
next reddit_thread.to_json
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
else
|
|
|
|
response = {
|
|
|
|
response = {
|
|
|
|
"title" => reddit_thread.title,
|
|
|
|
"title" => reddit_thread.title,
|
|
|
@ -2727,14 +2731,10 @@ get "/api/v1/comments/:id" do |env|
|
|
|
|
"contentHtml" => content_html,
|
|
|
|
"contentHtml" => content_html,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if env.params.query["pretty"]? && env.params.query["pretty"] == "1"
|
|
|
|
|
|
|
|
next response.to_pretty_json
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
next response.to_json
|
|
|
|
next response.to_json
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get "/api/v1/insights/:id" do |env|
|
|
|
|
get "/api/v1/insights/:id" do |env|
|
|
|
|
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
|
|
|
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
|
|
@ -2743,7 +2743,8 @@ get "/api/v1/insights/:id" do |env|
|
|
|
|
env.response.content_type = "application/json"
|
|
|
|
env.response.content_type = "application/json"
|
|
|
|
|
|
|
|
|
|
|
|
error_message = {"error" => "YouTube has removed publicly-available analytics."}.to_json
|
|
|
|
error_message = {"error" => "YouTube has removed publicly-available analytics."}.to_json
|
|
|
|
halt env, status_code: 410, response: error_message
|
|
|
|
env.response.status_code = 410
|
|
|
|
|
|
|
|
next error_message
|
|
|
|
|
|
|
|
|
|
|
|
client = make_client(YT_URL)
|
|
|
|
client = make_client(YT_URL)
|
|
|
|
headers = HTTP::Headers.new
|
|
|
|
headers = HTTP::Headers.new
|
|
|
@ -2820,12 +2821,8 @@ get "/api/v1/insights/:id" do |env|
|
|
|
|
"graphData" => graph_data,
|
|
|
|
"graphData" => graph_data,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if env.params.query["pretty"]? && env.params.query["pretty"] == "1"
|
|
|
|
|
|
|
|
next response.to_pretty_json
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
next response.to_json
|
|
|
|
next response.to_json
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get "/api/v1/videos/:id" do |env|
|
|
|
|
get "/api/v1/videos/:id" do |env|
|
|
|
|
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
|
|
|
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
|
|
@ -2841,7 +2838,8 @@ get "/api/v1/videos/:id" do |env|
|
|
|
|
next env.redirect "/api/v1/videos/#{ex.message}"
|
|
|
|
next env.redirect "/api/v1/videos/#{ex.message}"
|
|
|
|
rescue ex
|
|
|
|
rescue ex
|
|
|
|
error_message = {"error" => ex.message}.to_json
|
|
|
|
error_message = {"error" => ex.message}.to_json
|
|
|
|
halt env, status_code: 500, response: error_message
|
|
|
|
env.response.status_code = 500
|
|
|
|
|
|
|
|
next error_message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
fmt_stream = video.fmt_stream(decrypt_function)
|
|
|
|
fmt_stream = video.fmt_stream(decrypt_function)
|
|
|
@ -3029,12 +3027,8 @@ get "/api/v1/videos/:id" do |env|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if env.params.query["pretty"]? && env.params.query["pretty"] == "1"
|
|
|
|
|
|
|
|
JSON.parse(video_info).to_pretty_json
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
video_info
|
|
|
|
video_info
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get "/api/v1/trending" do |env|
|
|
|
|
get "/api/v1/trending" do |env|
|
|
|
|
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
|
|
|
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
|
|
@ -3048,7 +3042,8 @@ get "/api/v1/trending" do |env|
|
|
|
|
trending = fetch_trending(trending_type, proxies, region, locale)
|
|
|
|
trending = fetch_trending(trending_type, proxies, region, locale)
|
|
|
|
rescue ex
|
|
|
|
rescue ex
|
|
|
|
error_message = {"error" => ex.message}.to_json
|
|
|
|
error_message = {"error" => ex.message}.to_json
|
|
|
|
halt env, status_code: 500, response: error_message
|
|
|
|
env.response.status_code = 500
|
|
|
|
|
|
|
|
next error_message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
videos = JSON.build do |json|
|
|
|
|
videos = JSON.build do |json|
|
|
|
@ -3080,12 +3075,8 @@ get "/api/v1/trending" do |env|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if env.params.query["pretty"]? && env.params.query["pretty"] == "1"
|
|
|
|
|
|
|
|
JSON.parse(videos).to_pretty_json
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
videos
|
|
|
|
videos
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get "/api/v1/popular" do |env|
|
|
|
|
get "/api/v1/popular" do |env|
|
|
|
|
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
|
|
|
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
|
|
@ -3114,12 +3105,8 @@ get "/api/v1/popular" do |env|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if env.params.query["pretty"]? && env.params.query["pretty"] == "1"
|
|
|
|
|
|
|
|
JSON.parse(videos).to_pretty_json
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
videos
|
|
|
|
videos
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get "/api/v1/top" do |env|
|
|
|
|
get "/api/v1/top" do |env|
|
|
|
|
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
|
|
|
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
|
|
@ -3128,7 +3115,8 @@ get "/api/v1/top" do |env|
|
|
|
|
|
|
|
|
|
|
|
|
if !config.top_enabled
|
|
|
|
if !config.top_enabled
|
|
|
|
error_message = {"error" => "Administrator has disabled this endpoint."}.to_json
|
|
|
|
error_message = {"error" => "Administrator has disabled this endpoint."}.to_json
|
|
|
|
halt env, status_code: 400, response: error_message
|
|
|
|
env.response.status_code = 400
|
|
|
|
|
|
|
|
next error_message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
videos = JSON.build do |json|
|
|
|
|
videos = JSON.build do |json|
|
|
|
@ -3160,12 +3148,8 @@ get "/api/v1/top" do |env|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if env.params.query["pretty"]? && env.params.query["pretty"] == "1"
|
|
|
|
|
|
|
|
JSON.parse(videos).to_pretty_json
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
videos
|
|
|
|
videos
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get "/api/v1/channels/:ucid" do |env|
|
|
|
|
get "/api/v1/channels/:ucid" do |env|
|
|
|
|
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
|
|
|
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
|
|
@ -3180,7 +3164,8 @@ get "/api/v1/channels/:ucid" do |env|
|
|
|
|
author, ucid, auto_generated = get_about_info(ucid, locale)
|
|
|
|
author, ucid, auto_generated = get_about_info(ucid, locale)
|
|
|
|
rescue ex
|
|
|
|
rescue ex
|
|
|
|
error_message = {"error" => ex.message}.to_json
|
|
|
|
error_message = {"error" => ex.message}.to_json
|
|
|
|
halt env, status_code: 500, response: error_message
|
|
|
|
env.response.status_code = 500
|
|
|
|
|
|
|
|
next error_message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
page = 1
|
|
|
|
page = 1
|
|
|
@ -3192,7 +3177,8 @@ get "/api/v1/channels/:ucid" do |env|
|
|
|
|
videos, count = get_60_videos(ucid, page, auto_generated, sort_by)
|
|
|
|
videos, count = get_60_videos(ucid, page, auto_generated, sort_by)
|
|
|
|
rescue ex
|
|
|
|
rescue ex
|
|
|
|
error_message = {"error" => ex.message}.to_json
|
|
|
|
error_message = {"error" => ex.message}.to_json
|
|
|
|
halt env, status_code: 500, response: error_message
|
|
|
|
env.response.status_code = 500
|
|
|
|
|
|
|
|
next error_message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -3367,12 +3353,8 @@ get "/api/v1/channels/:ucid" do |env|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if env.params.query["pretty"]? && env.params.query["pretty"] == "1"
|
|
|
|
|
|
|
|
JSON.parse(channel_info).to_pretty_json
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
channel_info
|
|
|
|
channel_info
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
["/api/v1/channels/:ucid/videos", "/api/v1/channels/videos/:ucid"].each do |route|
|
|
|
|
["/api/v1/channels/:ucid/videos", "/api/v1/channels/videos/:ucid"].each do |route|
|
|
|
|
get route do |env|
|
|
|
|
get route do |env|
|
|
|
@ -3391,14 +3373,16 @@ end
|
|
|
|
author, ucid, auto_generated = get_about_info(ucid, locale)
|
|
|
|
author, ucid, auto_generated = get_about_info(ucid, locale)
|
|
|
|
rescue ex
|
|
|
|
rescue ex
|
|
|
|
error_message = {"error" => ex.message}.to_json
|
|
|
|
error_message = {"error" => ex.message}.to_json
|
|
|
|
halt env, status_code: 500, response: error_message
|
|
|
|
env.response.status_code = 500
|
|
|
|
|
|
|
|
next error_message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
videos, count = get_60_videos(ucid, page, auto_generated, sort_by)
|
|
|
|
videos, count = get_60_videos(ucid, page, auto_generated, sort_by)
|
|
|
|
rescue ex
|
|
|
|
rescue ex
|
|
|
|
error_message = {"error" => ex.message}.to_json
|
|
|
|
error_message = {"error" => ex.message}.to_json
|
|
|
|
halt env, status_code: 500, response: error_message
|
|
|
|
env.response.status_code = 500
|
|
|
|
|
|
|
|
next error_message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
result = JSON.build do |json|
|
|
|
|
result = JSON.build do |json|
|
|
|
@ -3437,13 +3421,9 @@ end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if env.params.query["pretty"]? && env.params.query["pretty"] == "1"
|
|
|
|
|
|
|
|
JSON.parse(result).to_pretty_json
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
result
|
|
|
|
result
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
["/api/v1/channels/:ucid/latest", "/api/v1/channels/latest/:ucid"].each do |route|
|
|
|
|
["/api/v1/channels/:ucid/latest", "/api/v1/channels/latest/:ucid"].each do |route|
|
|
|
|
get route do |env|
|
|
|
|
get route do |env|
|
|
|
@ -3457,7 +3437,8 @@ end
|
|
|
|
videos = get_latest_videos(ucid)
|
|
|
|
videos = get_latest_videos(ucid)
|
|
|
|
rescue ex
|
|
|
|
rescue ex
|
|
|
|
error_message = {"error" => ex.message}.to_json
|
|
|
|
error_message = {"error" => ex.message}.to_json
|
|
|
|
halt env, status_code: 500, response: error_message
|
|
|
|
env.response.status_code = 500
|
|
|
|
|
|
|
|
next error_message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
response = JSON.build do |json|
|
|
|
|
response = JSON.build do |json|
|
|
|
@ -3489,13 +3470,9 @@ end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if env.params.query["pretty"]? && env.params.query["pretty"] == "1"
|
|
|
|
|
|
|
|
JSON.parse(response).to_pretty_json
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
response
|
|
|
|
response
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
["/api/v1/channels/:ucid/playlists", "/api/v1/channels/playlists/:ucid"].each do |route|
|
|
|
|
["/api/v1/channels/:ucid/playlists", "/api/v1/channels/playlists/:ucid"].each do |route|
|
|
|
|
get route do |env|
|
|
|
|
get route do |env|
|
|
|
@ -3512,8 +3489,9 @@ end
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
author, ucid, auto_generated = get_about_info(ucid, locale)
|
|
|
|
author, ucid, auto_generated = get_about_info(ucid, locale)
|
|
|
|
rescue ex
|
|
|
|
rescue ex
|
|
|
|
error_message = ex.message
|
|
|
|
error_message = {"error" => ex.message}.to_json
|
|
|
|
halt env, status_code: 500, response: error_message
|
|
|
|
env.response.status_code = 500
|
|
|
|
|
|
|
|
next error_message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
items, continuation = fetch_channel_playlists(ucid, author, auto_generated, continuation, sort_by)
|
|
|
|
items, continuation = fetch_channel_playlists(ucid, author, auto_generated, continuation, sort_by)
|
|
|
@ -3558,13 +3536,9 @@ end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if env.params.query["pretty"]? && env.params.query["pretty"] == "1"
|
|
|
|
|
|
|
|
JSON.parse(response).to_pretty_json
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
response
|
|
|
|
response
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get "/api/v1/channels/search/:ucid" do |env|
|
|
|
|
get "/api/v1/channels/search/:ucid" do |env|
|
|
|
|
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
|
|
|
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
|
|
@ -3663,12 +3637,8 @@ get "/api/v1/channels/search/:ucid" do |env|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if env.params.query["pretty"]? && env.params.query["pretty"] == "1"
|
|
|
|
|
|
|
|
JSON.parse(response).to_pretty_json
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
response
|
|
|
|
response
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get "/api/v1/search" do |env|
|
|
|
|
get "/api/v1/search" do |env|
|
|
|
|
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
|
|
|
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
|
|
@ -3792,12 +3762,8 @@ get "/api/v1/search" do |env|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if env.params.query["pretty"]? && env.params.query["pretty"] == "1"
|
|
|
|
|
|
|
|
JSON.parse(response).to_pretty_json
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
response
|
|
|
|
response
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get "/api/v1/playlists/:plid" do |env|
|
|
|
|
get "/api/v1/playlists/:plid" do |env|
|
|
|
|
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
|
|
|
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
|
|
@ -3821,7 +3787,8 @@ get "/api/v1/playlists/:plid" do |env|
|
|
|
|
playlist = fetch_playlist(plid, locale)
|
|
|
|
playlist = fetch_playlist(plid, locale)
|
|
|
|
rescue ex
|
|
|
|
rescue ex
|
|
|
|
error_message = {"error" => "Playlist is empty"}.to_json
|
|
|
|
error_message = {"error" => "Playlist is empty"}.to_json
|
|
|
|
halt env, status_code: 500, response: error_message
|
|
|
|
env.response.status_code = 500
|
|
|
|
|
|
|
|
next error_message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
begin
|
|
|
@ -3895,12 +3862,8 @@ get "/api/v1/playlists/:plid" do |env|
|
|
|
|
}.to_json
|
|
|
|
}.to_json
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if env.params.query["pretty"]? && env.params.query["pretty"] == "1"
|
|
|
|
|
|
|
|
JSON.parse(response).to_pretty_json
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
response
|
|
|
|
response
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get "/api/v1/mixes/:rdid" do |env|
|
|
|
|
get "/api/v1/mixes/:rdid" do |env|
|
|
|
|
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
|
|
|
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
|
|
@ -3927,7 +3890,8 @@ get "/api/v1/mixes/:rdid" do |env|
|
|
|
|
mix.videos = mix.videos[index..-1]
|
|
|
|
mix.videos = mix.videos[index..-1]
|
|
|
|
rescue ex
|
|
|
|
rescue ex
|
|
|
|
error_message = {"error" => ex.message}.to_json
|
|
|
|
error_message = {"error" => ex.message}.to_json
|
|
|
|
halt env, status_code: 500, response: error_message
|
|
|
|
env.response.status_code = 500
|
|
|
|
|
|
|
|
next error_message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
response = JSON.build do |json|
|
|
|
|
response = JSON.build do |json|
|
|
|
@ -3973,11 +3937,7 @@ get "/api/v1/mixes/:rdid" do |env|
|
|
|
|
}.to_json
|
|
|
|
}.to_json
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if env.params.query["pretty"]? && env.params.query["pretty"] == "1"
|
|
|
|
response
|
|
|
|
JSON.parse(response).to_pretty_json
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
response
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
get "/api/manifest/dash/id/videoplayback" do |env|
|
|
|
|
get "/api/manifest/dash/id/videoplayback" do |env|
|
|
|
@ -4009,7 +3969,8 @@ get "/api/manifest/dash/id/:id" do |env|
|
|
|
|
|
|
|
|
|
|
|
|
next env.redirect url
|
|
|
|
next env.redirect url
|
|
|
|
rescue ex
|
|
|
|
rescue ex
|
|
|
|
halt env, status_code: 403
|
|
|
|
env.response.status_code = 403
|
|
|
|
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if dashmpd = video.player_response["streamingData"]?.try &.["dashManifestUrl"]?.try &.as_s
|
|
|
|
if dashmpd = video.player_response["streamingData"]?.try &.["dashManifestUrl"]?.try &.as_s
|
|
|
@ -4096,7 +4057,8 @@ get "/api/manifest/hls_variant/*" do |env|
|
|
|
|
manifest = client.get(env.request.path)
|
|
|
|
manifest = client.get(env.request.path)
|
|
|
|
|
|
|
|
|
|
|
|
if manifest.status_code != 200
|
|
|
|
if manifest.status_code != 200
|
|
|
|
halt env, status_code: manifest.status_code
|
|
|
|
env.response.status_code = manifest.status_code
|
|
|
|
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
env.response.content_type = "application/x-mpegURL"
|
|
|
|
env.response.content_type = "application/x-mpegURL"
|
|
|
@ -4113,7 +4075,8 @@ get "/api/manifest/hls_playlist/*" do |env|
|
|
|
|
manifest = client.get(env.request.path)
|
|
|
|
manifest = client.get(env.request.path)
|
|
|
|
|
|
|
|
|
|
|
|
if manifest.status_code != 200
|
|
|
|
if manifest.status_code != 200
|
|
|
|
halt env, status_code: manifest.status_code
|
|
|
|
env.response.status_code = manifest.status_code
|
|
|
|
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
host_url = make_host_url(config, Kemal.config)
|
|
|
|
host_url = make_host_url(config, Kemal.config)
|
|
|
@ -4149,7 +4112,8 @@ get "/latest_version" do |env|
|
|
|
|
local = local == "true"
|
|
|
|
local = local == "true"
|
|
|
|
|
|
|
|
|
|
|
|
if !id || !itag
|
|
|
|
if !id || !itag
|
|
|
|
halt env, status_code: 400
|
|
|
|
env.response.status_code = 400
|
|
|
|
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
video = get_video(id, PG_DB, proxies, region: region)
|
|
|
|
video = get_video(id, PG_DB, proxies, region: region)
|
|
|
@ -4159,9 +4123,11 @@ get "/latest_version" do |env|
|
|
|
|
|
|
|
|
|
|
|
|
urls = (fmt_stream + adaptive_fmts).select { |fmt| fmt["itag"] == itag }
|
|
|
|
urls = (fmt_stream + adaptive_fmts).select { |fmt| fmt["itag"] == itag }
|
|
|
|
if urls.empty?
|
|
|
|
if urls.empty?
|
|
|
|
halt env, status_code: 404
|
|
|
|
env.response.status_code = 404
|
|
|
|
|
|
|
|
next
|
|
|
|
elsif urls.size > 1
|
|
|
|
elsif urls.size > 1
|
|
|
|
halt env, status_code: 409
|
|
|
|
env.response.status_code = 409
|
|
|
|
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
url = urls[0]["url"]
|
|
|
|
url = urls[0]["url"]
|
|
|
@ -4285,7 +4251,8 @@ get "/videoplayback" do |env|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if response.status_code >= 400
|
|
|
|
if response.status_code >= 400
|
|
|
|
halt env, status_code: response.status_code
|
|
|
|
env.response.status_code = response.status_code
|
|
|
|
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
client = make_client(URI.parse(host), proxies, region)
|
|
|
|
client = make_client(URI.parse(host), proxies, region)
|
|
|
@ -4509,8 +4476,8 @@ public_folder "assets"
|
|
|
|
|
|
|
|
|
|
|
|
Kemal.config.powered_by_header = false
|
|
|
|
Kemal.config.powered_by_header = false
|
|
|
|
add_handler FilteredCompressHandler.new
|
|
|
|
add_handler FilteredCompressHandler.new
|
|
|
|
add_handler DenyFrame.new
|
|
|
|
|
|
|
|
add_handler APIHandler.new
|
|
|
|
add_handler APIHandler.new
|
|
|
|
|
|
|
|
add_handler DenyFrame.new
|
|
|
|
add_context_storage_type(User)
|
|
|
|
add_context_storage_type(User)
|
|
|
|
add_context_storage_type(Preferences)
|
|
|
|
add_context_storage_type(Preferences)
|
|
|
|
|
|
|
|
|
|
|
|