From a2f79a163f899022ff4106b0c045c951d84d4244 Mon Sep 17 00:00:00 2001
From: simonphoenix96 <diazjustin1995@yahoo.de>
Date: Sat, 27 Feb 2021 18:58:55 +0100
Subject: [PATCH 1/3] integrate legacy yt xml subscription import with new json
 sub import

---
 src/invidious.cr | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/invidious.cr b/src/invidious.cr
index 563a3768..fb1d168e 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -760,10 +760,16 @@ post "/data_control" do |env|
           end
         end
       when "import_youtube"
-        subscriptions = JSON.parse(body)
-
-        user.subscriptions += subscriptions.as_a.compact_map do |entry|
-          entry["snippet"]["resourceId"]["channelId"].as_s
+        if body[0..4] == "<opml" 
+          subscriptions = XML.parse(body)
+          user.subscriptions += subscriptions.xpath_nodes(%q(//outline[@type="rss"])).map do |channel|
+            channel["xmlUrl"].match(/UC[a-zA-Z0-9_-]{22}/).not_nil![0]
+          end
+        else
+          subscriptions = JSON.parse(body)
+          user.subscriptions += subscriptions.as_a.compact_map do |entry|
+            entry["snippet"]["resourceId"]["channelId"].as_s
+        end
         end
         user.subscriptions.uniq!
 

From 9689376de69ae0fa1c6e8569647ced5d5851e2e1 Mon Sep 17 00:00:00 2001
From: Simon Phoenix <diazjustin1995@yahoo.de>
Date: Sat, 27 Feb 2021 19:12:01 +0100
Subject: [PATCH 2/3] fixed line indent typo

---
 src/invidious.cr | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/invidious.cr b/src/invidious.cr
index fb1d168e..a776b2c0 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -769,7 +769,7 @@ post "/data_control" do |env|
           subscriptions = JSON.parse(body)
           user.subscriptions += subscriptions.as_a.compact_map do |entry|
             entry["snippet"]["resourceId"]["channelId"].as_s
-        end
+          end
         end
         user.subscriptions.uniq!
 

From 84487b2e520f74871afb7dfa97117cfe0282f0c9 Mon Sep 17 00:00:00 2001
From: simonphoenix96 <diazjustin1995@yahoo.de>
Date: Sat, 27 Feb 2021 21:59:09 +0100
Subject: [PATCH 3/3] format invidious.cr using crystal cli

---
 src/invidious.cr | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/invidious.cr b/src/invidious.cr
index a776b2c0..80f551e9 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -760,7 +760,7 @@ post "/data_control" do |env|
           end
         end
       when "import_youtube"
-        if body[0..4] == "<opml" 
+        if body[0..4] == "<opml"
           subscriptions = XML.parse(body)
           user.subscriptions += subscriptions.xpath_nodes(%q(//outline[@type="rss"])).map do |channel|
             channel["xmlUrl"].match(/UC[a-zA-Z0-9_-]{22}/).not_nil![0]
@@ -1563,12 +1563,12 @@ post "/feed/webhook/:token" do |env|
         views:              video.views,
       })
 
-      was_insert = PG_DB.query_one("INSERT INTO channel_videos VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) \
-        ON CONFLICT (id) DO UPDATE SET title = $2, published = $3, \
-        updated = $4, ucid = $5, author = $6, length_seconds = $7, \
+      was_insert = PG_DB.query_one("INSERT INTO channel_videos VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
+        ON CONFLICT (id) DO UPDATE SET title = $2, published = $3,
+        updated = $4, ucid = $5, author = $6, length_seconds = $7,
         live_now = $8, premiere_timestamp = $9, views = $10 returning (xmax=0) as was_insert", *video.to_tuple, as: Bool)
 
-      PG_DB.exec("UPDATE users SET notifications = array_append(notifications, $1), \
+      PG_DB.exec("UPDATE users SET notifications = array_append(notifications, $1),
         feed_needs_update = true WHERE $2 = ANY(subscriptions)", video.id, video.ucid) if was_insert
     end
   end