|
1 | 1 | require "csv" |
2 | 2 |
|
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 |
6 | 6 |
|
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 |
10 | 11 |
|
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 |
15 | 15 |
|
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 |
20 | 20 |
|
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 |
22 | 25 |
|
23 | | - subscriptions << channel_id |
24 | | - end |
| 26 | + next if channel_id.empty? |
| 27 | + subscriptions << channel_id |
| 28 | + end |
25 | 29 |
|
26 | | - return subscriptions |
| 30 | + return subscriptions |
| 31 | + end |
| 32 | + end |
27 | 33 | end |
0 commit comments