Skip to content

Instantly share code, notes, and snippets.

@bbielsa
Created November 18, 2021 02:15
Show Gist options
  • Save bbielsa/7d131aa2188945f591a8379ec0defc9b to your computer and use it in GitHub Desktop.
Save bbielsa/7d131aa2188945f591a8379ec0defc9b to your computer and use it in GitHub Desktop.
when "import_youtube"
filename = part.filename || ""
extension = filename.split(".").last
if extension == "xml" && (type == "application/xml" || type == "text/xml")
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
elsif extension == "json" && type == "application/json"
subscriptions = JSON.parse(body)
user.subscriptions += subscriptions.as_a.compact_map do |entry|
entry["snippet"]["resourceId"]["channelId"].as_s
end
elsif extension == "csv" && type == "text/csv"
subscriptions = parse_subscription_export_csv(body)
user.subscriptions += subscriptions
else
next error_template(400, "Invalid subscription file uploaded")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment