diff --git a/src/invidious.cr b/src/invidious.cr index 2e141c29..b78e8f72 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -1116,7 +1116,7 @@ post "/data_control" do |env| body["subscriptions"].as_a.each do |ucid| ucid = ucid.as_s if !user.subscriptions.includes? ucid - PG_DB.exec("UPDATE users SET subscriptions = array_append(subscriptions,$1) WHERE id = $2", ucid, user.id) + PG_DB.exec("UPDATE users SET subscriptions = array_append(subscriptions,$1) WHERE email = $2", ucid, user.email) begin client = make_client(YT_URL) @@ -1131,6 +1131,7 @@ post "/data_control" do |env| id = id.as_s if !user.watched.includes? id PG_DB.exec("UPDATE users SET watched = array_append(watched,$1) WHERE email = $2", id, user.email) + user.watched << id end end @@ -1141,11 +1142,12 @@ post "/data_control" do |env| ucid = channel["xmlUrl"].match(/UC[a-zA-Z0-9_-]{22}/).not_nil![0] if !user.subscriptions.includes? ucid - PG_DB.exec("UPDATE users SET subscriptions = array_append(subscriptions,$1) WHERE email = $2", ucid, user.email) - begin client = make_client(YT_URL) get_channel(ucid, client, PG_DB, false, false) + + PG_DB.exec("UPDATE users SET subscriptions = array_append(subscriptions,$1) WHERE email = $2", ucid, user.email) + user.subscriptions << ucid rescue ex next end @@ -1156,11 +1158,12 @@ post "/data_control" do |env| ucid = md["channel_id"] if !user.subscriptions.includes? ucid - PG_DB.exec("UPDATE users SET subscriptions = array_append(subscriptions,$1) WHERE email = $2", ucid, user.email) - begin client = make_client(YT_URL) get_channel(ucid, client, PG_DB, false, false) + + PG_DB.exec("UPDATE users SET subscriptions = array_append(subscriptions,$1) WHERE email = $2", ucid, user.email) + user.subscriptions << ucid rescue ex next end @@ -1192,19 +1195,22 @@ post "/data_control" do |env| db = entry.io.gets_to_end db.scan(/youtube\.com\/watch\?v\=(?[a-zA-Z0-9_-]{11})/) do |md| - if !user.watched.includes? md["id"] - PG_DB.exec("UPDATE users SET watched = array_append(watched,$1) WHERE email = $2", md["id"], user.email) + id = md["id"] + if !user.watched.includes? id + PG_DB.exec("UPDATE users SET watched = array_append(watched,$1) WHERE email = $2", id, user.email) + user.watched << id end end db.scan(/youtube\.com\/channel\/(?[a-zA-Z0-9_-]{22})/) do |md| ucid = md["ucid"] if !user.subscriptions.includes? ucid - PG_DB.exec("UPDATE users SET subscriptions = array_append(subscriptions,$1) WHERE email = $2", ucid, user.email) - begin client = make_client(YT_URL) get_channel(ucid, client, PG_DB, false, false) + + PG_DB.exec("UPDATE users SET subscriptions = array_append(subscriptions,$1) WHERE email = $2", ucid, user.email) + user.subscriptions << ucid rescue ex next end