summaryrefslogtreecommitdiffstats
path: root/src/invidious.cr
diff options
context:
space:
mode:
Diffstat (limited to 'src/invidious.cr')
-rw-r--r--src/invidious.cr57
1 files changed, 26 insertions, 31 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index e0967753..bbf9b4c9 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -90,9 +90,9 @@ REDDIT_URL = URI.parse("https://www.reddit.com")
LOGIN_URL = URI.parse("https://accounts.google.com")
PUBSUB_URL = URI.parse("https://pubsubhubbub.appspot.com")
TEXTCAPTCHA_URL = URI.parse("http://textcaptcha.com/omarroth@hotmail.com.json")
+CURRENT_BRANCH = `git branch | sed -n '/\* /s///p'`.strip
CURRENT_COMMIT = `git rev-list HEAD --max-count=1 --abbrev-commit`.strip
-CURRENT_VERSION = `git describe --tags $(git rev-list --tags --max-count=1)`.strip
-CURRENT_BRANCH = `git status | head -1`.strip
+CURRENT_VERSION = `git describe --tags --abbrev=0`.strip
LOCALES = {
"ar" => load_locale("ar"),
@@ -264,7 +264,7 @@ get "/" do |env|
if user
user = user.as(User)
if user.preferences.redirect_feed
- env.redirect "/feed/subscriptions"
+ next env.redirect "/feed/subscriptions"
end
end
@@ -417,7 +417,7 @@ get "/watch" do |env|
video.description = replace_links(video.description)
description = video.short_description
- host_url = make_host_url(Kemal.config.ssl || config.https_only, config.domain)
+ host_url = make_host_url(config, Kemal.config)
host_params = env.request.query_params
host_params.delete_all("v")
@@ -517,7 +517,7 @@ get "/embed/:id" do |env|
video.description = replace_links(video.description)
description = video.short_description
- host_url = make_host_url(Kemal.config.ssl || config.https_only, config.domain)
+ host_url = make_host_url(config, Kemal.config)
host_params = env.request.query_params
host_params.delete_all("v")
@@ -603,7 +603,7 @@ get "/opensearch.xml" do |env|
locale = LOCALES[env.get("locale").as(String)]?
env.response.content_type = "application/opensearchdescription+xml"
- host = make_host_url(Kemal.config.ssl || config.https_only, config.domain)
+ host = make_host_url(config, Kemal.config)
XML.build(indent: " ", encoding: "UTF-8") do |xml|
xml.element("OpenSearchDescription", xmlns: "http://a9.com/-/spec/opensearch/1.1/") do
@@ -1500,7 +1500,7 @@ get "/subscription_manager" do |env|
subscriptions.sort_by! { |channel| channel.author.downcase }
if action_takeout
- host_url = make_host_url(Kemal.config.ssl || config.https_only, config.domain)
+ host_url = make_host_url(config, Kemal.config)
if format == "json"
env.response.content_type = "application/json"
@@ -1583,14 +1583,7 @@ post "/data_control" do |env|
user.subscriptions += body["subscriptions"].as_a.map { |a| a.as_s }
user.subscriptions.uniq!
- user.subscriptions.select! do |ucid|
- begin
- get_channel(ucid, PG_DB, false, false)
- true
- rescue ex
- false
- end
- end
+ user.subscriptions = get_batch_channels(user.subscriptions, PG_DB, false, false)
PG_DB.exec("UPDATE users SET subscriptions = $1 WHERE email = $2", user.subscriptions, user.email)
end
@@ -1964,7 +1957,7 @@ get "/feed/subscriptions" do |env|
# Show latest video from each channel
videos = PG_DB.query_all("SELECT DISTINCT ON (ucid) * FROM #{view_name} \
- ORDER BY ucid, published", as: ChannelVideo)
+ ORDER BY ucid, published DESC", as: ChannelVideo)
end
videos.sort_by! { |video| video.published }.reverse!
@@ -2057,7 +2050,8 @@ end
get "/feed/channel/:ucid" do |env|
locale = LOCALES[env.get("locale").as(String)]?
- env.response.content_type = "text/xml"
+ env.response.content_type = "application/atom+xml"
+
ucid = env.params.url["ucid"]
begin
@@ -2101,7 +2095,7 @@ get "/feed/channel/:ucid" do |env|
)
end
- host_url = make_host_url(Kemal.config.ssl || config.https_only, config.domain)
+ host_url = make_host_url(config, Kemal.config)
path = env.request.path
feed = XML.build(indent: " ", encoding: "UTF-8") do |xml|
@@ -2168,6 +2162,8 @@ end
get "/feed/private" do |env|
locale = LOCALES[env.get("locale").as(String)]?
+ env.response.content_type = "application/atom+xml"
+
token = env.params.query["token"]?
if !token
@@ -2210,7 +2206,7 @@ get "/feed/private" do |env|
if latest_only
videos = PG_DB.query_all("SELECT DISTINCT ON (ucid) * FROM #{view_name} \
- ORDER BY ucid, published", as: ChannelVideo)
+ ORDER BY ucid, published DESC", as: ChannelVideo)
videos.sort_by! { |video| video.published }.reverse!
else
@@ -2235,7 +2231,7 @@ get "/feed/private" do |env|
videos = videos[0..max_results]
end
- host_url = make_host_url(Kemal.config.ssl || config.https_only, config.domain)
+ host_url = make_host_url(config, Kemal.config)
path = env.request.path
query = env.request.query.not_nil!
@@ -2281,16 +2277,17 @@ get "/feed/private" do |env|
end
end
- env.response.content_type = "application/atom+xml"
feed
end
get "/feed/playlist/:plid" do |env|
locale = LOCALES[env.get("locale").as(String)]?
+ env.response.content_type = "application/atom+xml"
+
plid = env.params.url["plid"]
- host_url = make_host_url(Kemal.config.ssl || config.https_only, config.domain)
+ host_url = make_host_url(config, Kemal.config)
path = env.request.path
client = make_client(YT_URL)
@@ -2315,7 +2312,6 @@ get "/feed/playlist/:plid" do |env|
document = document.gsub(match[0], "<uri>#{content}</uri>")
end
- env.response.content_type = "text/xml"
document
end
@@ -2327,7 +2323,6 @@ get "/feed/webhook/:token" do |env|
mode = env.params.query["hub.mode"]
topic = env.params.query["hub.topic"]
challenge = env.params.query["hub.challenge"]
- lease_seconds = env.params.query["hub.lease_seconds"]
if verify_token.starts_with? "v1"
_, time, nonce, signature = verify_token.split(":")
@@ -2536,15 +2531,15 @@ end
get "/api/v1/stats" do |env|
env.response.content_type = "application/json"
- if statistics["error"]?
- halt env, status_code: 500, response: statistics.to_json
- end
-
if !config.statistics_enabled
error_message = {"error" => "Statistics are not enabled."}.to_json
halt env, status_code: 400, response: error_message
end
+ if statistics["error"]?
+ halt env, status_code: 500, response: statistics.to_json
+ end
+
if env.params.query["pretty"]? && env.params.query["pretty"] == "1"
statistics.to_pretty_json
else
@@ -2897,7 +2892,7 @@ get "/api/v1/videos/:id" do |env|
end
if video.player_response["streamingData"]?.try &.["hlsManifestUrl"]?
- host_url = make_host_url(Kemal.config.ssl || config.https_only, config.domain)
+ host_url = make_host_url(config, Kemal.config)
host_params = env.request.query_params
host_params.delete_all("v")
@@ -4091,7 +4086,7 @@ get "/api/manifest/hls_variant/*" do |env|
env.response.content_type = "application/x-mpegURL"
env.response.headers.add("Access-Control-Allow-Origin", "*")
- host_url = make_host_url(Kemal.config.ssl || config.https_only, config.domain)
+ host_url = make_host_url(config, Kemal.config)
manifest = manifest.body
manifest.gsub("https://www.youtube.com", host_url)
@@ -4105,7 +4100,7 @@ get "/api/manifest/hls_playlist/*" do |env|
halt env, status_code: manifest.status_code
end
- host_url = make_host_url(Kemal.config.ssl || config.https_only, config.domain)
+ host_url = make_host_url(config, Kemal.config)
manifest = manifest.body.gsub("https://www.youtube.com", host_url)
manifest = manifest.gsub(/https:\/\/r\d---.{11}\.c\.youtube\.com/, host_url)