summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbbielsa <bgb7@njit.edu>2021-10-26 21:19:20 -0400
committerSamantaz Fox <coding@samantaz.fr>2022-01-08 18:07:06 +0100
commit7cbd79fee5f87c5c611685100ef8167d90b831f5 (patch)
treec489a17ae29061375ee9de80d70a8d5303cfb08c
parent3fba342ed223922d15fc0214c0445c6f4f964f86 (diff)
downloadinvidious-7cbd79fee5f87c5c611685100ef8167d90b831f5.tar.gz
invidious-7cbd79fee5f87c5c611685100ef8167d90b831f5.tar.bz2
invidious-7cbd79fee5f87c5c611685100ef8167d90b831f5.zip
Add helper function parse_subscription_export_csv() which parses the csv format returned by the subscription exporter
-rw-r--r--src/invidious/helpers/utils.cr22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.cr
index 8453d605..6d12fe8d 100644
--- a/src/invidious/helpers/utils.cr
+++ b/src/invidious/helpers/utils.cr
@@ -1,3 +1,5 @@
+require "csv"
+
# See http://www.evanmiller.org/how-not-to-sort-by-average-rating.html
def ci_lower_bound(pos, n)
if n == 0
@@ -367,3 +369,23 @@ def fetch_random_instance
return filtered_instance_list.sample(1)[0]
end
+
+def parse_subscription_export_csv(csv_content : String)
+ rows = CSV.new(csv_content, headers: true)
+ subscriptions = Array(String).new
+
+ rows.each do |row|
+ # Channel ID is the first column in the csv export we can't use the header
+ # name, because I believe the header name is localized depending on the
+ # language the user has set on their account
+ channel_id = row[0].strip
+
+ if channel_id.empty?
+ next
+ end
+
+ subscriptions << channel_id
+ end
+
+ subscriptions
+end