Skip to content

Commit ef8dc72

Browse files
committed
Put CSV import function under its own module
1 parent ad4a06f commit ef8dc72

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

src/invidious/user/imports.cr

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
11
require "csv"
22

3-
def parse_subscription_export_csv(csv_content : String)
4-
rows = CSV.new(csv_content, headers: true)
5-
subscriptions = Array(String).new
3+
struct Invidious::User
4+
module Import
5+
extend self
66

7-
# Counter to limit the amount of imports.
8-
# This is intended to prevent DoS.
9-
row_counter = 0
7+
# Parse a youtube CSV subscription file
8+
def parse_subscription_export_csv(csv_content : String)
9+
rows = CSV.new(csv_content, headers: true)
10+
subscriptions = Array(String).new
1011

11-
rows.each do |row|
12-
# Limit to 1200
13-
row_counter += 1
14-
break if row_counter > 1_200
12+
# Counter to limit the amount of imports.
13+
# This is intended to prevent DoS.
14+
row_counter = 0
1515

16-
# Channel ID is the first column in the csv export we can't use the header
17-
# name, because the header name is localized depending on the
18-
# language the user has set on their account
19-
channel_id = row[0].strip
16+
rows.each do |row|
17+
# Limit to 1200
18+
row_counter += 1
19+
break if row_counter > 1_200
2020

21-
next if channel_id.empty?
21+
# Channel ID is the first column in the csv export we can't use the header
22+
# name, because the header name is localized depending on the
23+
# language the user has set on their account
24+
channel_id = row[0].strip
2225

23-
subscriptions << channel_id
24-
end
26+
next if channel_id.empty?
27+
subscriptions << channel_id
28+
end
2529

26-
return subscriptions
30+
return subscriptions
31+
end
32+
end
2733
end

0 commit comments

Comments
 (0)