From 7cbd79fee5f87c5c611685100ef8167d90b831f5 Mon Sep 17 00:00:00 2001 From: bbielsa Date: Tue, 26 Oct 2021 21:19:20 -0400 Subject: [PATCH] Add helper function parse_subscription_export_csv() which parses the csv format returned by the subscription exporter --- src/invidious/helpers/utils.cr | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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