Skip to content

Commit 60e870b

Browse files
committed
Fix OPML import
1 parent 99d770b commit 60e870b

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/invidious/user/imports.cr

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,25 @@ struct Invidious::User
105105
# Youtube
106106
# -------------------
107107

108+
private def is_opml?(mimetype : String, extension : String)
109+
opml_mimetypes = [
110+
"application/xml",
111+
"text/xml",
112+
"text/x-opml",
113+
"text/x-opml+xml",
114+
]
115+
116+
opml_extensions = ["xml", "opml"]
117+
118+
return opml_mimetypes.any?(&.== mimetype) || opml_extensions.any?(&.== extension)
119+
end
120+
108121
# Import subscribed channels from Youtube
109122
# Returns success status
110123
def from_youtube(user : User, body : String, filename : String, type : String) : Bool
111124
extension = filename.split(".").last
112125

113-
if extension == "xml" || type == "application/xml" || type == "text/xml"
126+
if is_opml?(type, extension)
114127
subscriptions = XML.parse(body)
115128
user.subscriptions += subscriptions.xpath_nodes(%q(//outline[@type="rss"])).map do |channel|
116129
channel["xmlUrl"].match(/UC[a-zA-Z0-9_-]{22}/).not_nil![0]

0 commit comments

Comments
 (0)