From 60e870b27783bdcdb07d26489b50d18a85c49eeb Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Sat, 12 Feb 2022 17:32:20 +0100 Subject: [PATCH] Fix OPML import --- src/invidious/user/imports.cr | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/invidious/user/imports.cr b/src/invidious/user/imports.cr index 7404cd97..61d10719 100644 --- a/src/invidious/user/imports.cr +++ b/src/invidious/user/imports.cr @@ -105,12 +105,25 @@ struct Invidious::User # Youtube # ------------------- + private def is_opml?(mimetype : String, extension : String) + opml_mimetypes = [ + "application/xml", + "text/xml", + "text/x-opml", + "text/x-opml+xml", + ] + + opml_extensions = ["xml", "opml"] + + return opml_mimetypes.any?(&.== mimetype) || opml_extensions.any?(&.== extension) + end + # Import subscribed channels from Youtube # Returns success status def from_youtube(user : User, body : String, filename : String, type : String) : Bool extension = filename.split(".").last - if extension == "xml" || type == "application/xml" || type == "text/xml" + if is_opml?(type, extension) 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]