diff --git a/src/invidious.cr b/src/invidious.cr
index dfa0aadf..f4d7f791 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -209,14 +209,24 @@ get "/watch" do |env|
env.params.query.delete_all("listen")
end
- yt_client = get_client(youtube_pool)
+ client = get_client(youtube_pool)
+
+ authorized = env.get? "authorized"
+ if authorized
+ sid = env.request.cookies["SID"].value
+
+ subscriptions = PG_DB.query_one("SELECT subscriptions FROM users WHERE id = $1", sid, as: Array(String))
+ else
+ subscriptions = [] of String
+ end
+
begin
- video = get_video(id, yt_client, PG_DB)
+ video = get_video(id, client, PG_DB)
rescue ex
error_message = ex.message
next templated "error"
ensure
- youtube_pool << yt_client
+ youtube_pool << client
end
fmt_stream = [] of HTTP::Params
@@ -611,13 +621,13 @@ get "/enable_notifications" do |env|
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_id = channel.content.lstrip("/channel/").not_nil!
channel_req = {
- "channel_id" => channel_id.not_nil!,
+ "channel_id" => channel_id,
"receive_all_updates" => "true",
"receive_post_updates" => "true",
- "session_token" => session_token.not_nil!,
+ "session_token" => session_token,
}
channel_req = HTTP::Params.encode(channel_req)
@@ -651,14 +661,14 @@ get "/disable_notifications" do |env|
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_id = channel.content.lstrip("/channel/").not_nil!
channel_req = {
- "channel_id" => channel_id.not_nil!,
+ "channel_id" => channel_id,
"receive_all_updates" => "false",
"receive_no_updates" => "false",
"receive_post_updates" => "true",
- "session_token" => session_token.not_nil!,
+ "session_token" => session_token,
}
channel_req = HTTP::Params.encode(channel_req)
@@ -672,6 +682,63 @@ get "/disable_notifications" do |env|
env.redirect "/"
end
+get "/subscription_ajax" do |env|
+ authorized = env.get? "authorized"
+ referer = env.request.headers["referer"]?
+ referer ||= "/"
+
+ if authorized
+ if env.params.query["action_create_subscription_to_channel"]?
+ action = "action_create_subscription_to_channel"
+ elsif env.params.query["action_remove_subscriptions"]?
+ action = "action_remove_subscriptions"
+ else
+ action = ""
+ env.redirect referer
+ end
+
+ channel_id = env.params.query["c"]?
+ channel_id ||= ""
+
+ 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': "(?<%= video.info["author"] %>
+ "> + Unsubscribe from <%= video.info["author"] %> + +
+ <% else %> ++ "> + Subscribe to <%= video.info["author"] %> + +
+ <% end %> + <% end %>Shared <%= video.published.to_s("%B %-d, %Y") %>