summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/invidious.cr85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index c91b75f8..dfa0aadf 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -587,6 +587,91 @@ get "/feed/subscriptions" do |env|
end
end
+# Two functions that are useful if you have multiple subscriptions that don't have
+# the "bell dinged". enable_notifications dings the bell for all subscriptions,
+# disable_notifications does the opposite. These don't fit conveniently anywhere,
+# so instead are here more as an undocumented utility.
+get "/enable_notifications" do |env|
+ authorized = env.get? "authorized"
+
+ if authorized
+ headers = HTTP::Headers.new
+ headers["Cookie"] = env.request.headers["Cookie"]
+
+ client = get_client(youtube_pool)
+ subs = client.get("/subscription_manager?disable_polymer=1", headers)
+ headers["Cookie"] += "; " + subs.cookies.add_request_headers(headers)["Cookie"]
+ match = subs.body.match(/'XSRF_TOKEN': "(?<session_token>[A-Za-z0-9\_\-\=]+)"/)
+ if match
+ session_token = match["session_token"]
+ else
+ next env.redirect "/"
+ end
+
+ headers["content-type"] = "application/x-www-form-urlencoded"
+ subs = XML.parse_html(subs.body)
+ subs.xpath_nodes(%q(//a[@class="subscription-title yt-uix-sessionlink"]/@href)).each do |channel|
+ channel_id = channel.content.lstrip("/channel/")
+
+ channel_req = {
+ "channel_id" => channel_id.not_nil!,
+ "receive_all_updates" => "true",
+ "receive_post_updates" => "true",
+ "session_token" => session_token.not_nil!,
+ }
+
+ channel_req = HTTP::Params.encode(channel_req)
+
+ client.post("/subscription_ajax?action_update_subscription_preferences=1", headers, channel_req)
+ end
+
+ youtube_pool << client
+ end
+
+ env.redirect "/"
+end
+
+get "/disable_notifications" do |env|
+ authorized = env.get? "authorized"
+
+ if authorized
+ headers = HTTP::Headers.new
+ headers["Cookie"] = env.request.headers["Cookie"]
+
+ client = get_client(youtube_pool)
+ subs = client.get("/subscription_manager?disable_polymer=1", headers)
+ headers["Cookie"] += "; " + subs.cookies.add_request_headers(headers)["Cookie"]
+ match = subs.body.match(/'XSRF_TOKEN': "(?<session_token>[A-Za-z0-9\_\-\=]+)"/)
+ if match
+ session_token = match["session_token"]
+ else
+ next env.redirect "/"
+ end
+
+ headers["content-type"] = "application/x-www-form-urlencoded"
+ subs = XML.parse_html(subs.body)
+ subs.xpath_nodes(%q(//a[@class="subscription-title yt-uix-sessionlink"]/@href)).each do |channel|
+ channel_id = channel.content.lstrip("/channel/")
+
+ channel_req = {
+ "channel_id" => channel_id.not_nil!,
+ "receive_all_updates" => "false",
+ "receive_no_updates" => "false",
+ "receive_post_updates" => "true",
+ "session_token" => session_token.not_nil!,
+ }
+
+ channel_req = HTTP::Params.encode(channel_req)
+
+ client.post("/subscription_ajax?action_update_subscription_preferences=1", headers, channel_req)
+ end
+
+ youtube_pool << client
+ end
+
+ env.redirect "/"
+end
+
error 404 do |env|
error_message = "404 Page not found"
templated "error"
ru/messages.json?id=fe9547cf1a08b6d75e4b178a25de53ec9e0c5257&follow=1'>Update Russian translationTotalCaesar659 2020-11-09Update README.mdYumi Izumi 2020-11-09Update options.jsYumi Izumi 2020-11-09Update options.htmlYumi Izumi 2020-11-08Update popup.jsYumi Izumi 2020-11-08Update popup.htmlYumi Izumi 2020-11-08Update background.jsYumi Izumi 2020-11-08Closes #111 - Adds ability to customise random instance poolsv1.1.43SimonBrazell 2020-11-08Fixes #119 - Change zh-CN to zh_CN.SimonBrazell 2020-11-07Update README.mdKunio 2020-11-05Update Russian translationTotalCaesar659 2020-11-04Update store listing templatesSimonBrazell 2020-11-04Update Bibliogram linksbopol 2020-11-04Remove duplicate entry in instagramReservedPaths arraySimonBrazell 2020-11-04Remove "https://yewtu.be" from random instance listSimonBrazell 2020-11-04Ignore embedded videos for FreeTube redirectsSimonBrazell 2020-11-04Fixes #99 - Bibliogram, handle /igtv/, /tv/ and /reel/v1.1.42SimonBrazell 2020-11-04Fixes #104 - /remove-twitter-sw.js stopping Twitter redirectsSimonBrazell 2020-11-04Closes #113 - Added support for FreeTubeSimonBrazell 2020-11-04Clean up invidious random instance listSimonBrazell 2020-10-23Rename _locales/store.md to _locales/pl/store.mdAustin Huang