diff --git a/locales/en-US.json b/locales/en-US.json index 8032cf98..7bcf2d85 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -51,8 +51,8 @@ "Import NewPipe subscriptions (.json)": "Import NewPipe subscriptions (.json)", "Import NewPipe data (.zip)": "Import NewPipe data (.zip)", "Export": "Export", - "Export subscriptions as OPML": "Export subscriptions as OPML", - "Export subscriptions as OPML (for NewPipe & FreeTube)": "Export subscriptions as OPML (for NewPipe & FreeTube)", + "Export subscriptions as OPML (for FreeTube)": "Export subscriptions as OPML (for FreeTube)", + "Export subscriptions as JSON (for NewPipe)": "Export subscriptions as JSON (for NewPipe)", "Export data as JSON": "Export Invidious data as JSON", "Delete account?": "Delete account?", "History": "History", diff --git a/src/invidious/routes/subscriptions.cr b/src/invidious/routes/subscriptions.cr index 1de655d2..46c48f65 100644 --- a/src/invidious/routes/subscriptions.cr +++ b/src/invidious/routes/subscriptions.cr @@ -80,30 +80,23 @@ module Invidious::Routes::Subscriptions subscriptions.sort_by!(&.author.downcase) if action_takeout - if format == "json" - env.response.content_type = "application/json" - env.response.headers["content-disposition"] = "attachment" + env.response.content_type = "application/json" + env.response.headers["content-disposition"] = "attachment" + if format == "json" return Invidious::User::Export.to_invidious(user) + elsif format == "newpipe_json" + return Invidious::User::Export.to_newpipe(subscriptions) else env.response.content_type = "application/xml" - env.response.headers["content-disposition"] = "attachment" export = XML.build do |xml| xml.element("opml", version: "1.1") do xml.element("body") do - if format == "newpipe" - title = "YouTube Subscriptions" - else - title = "Invidious Subscriptions" - end + title = "Invidious Subscriptions" xml.element("outline", text: title, title: title) do subscriptions.each do |channel| - if format == "newpipe" - xml_url = "https://www.youtube.com/feeds/videos.xml?channel_id=#{channel.id}" - else - xml_url = "#{HOST_URL}/feed/channel/#{channel.id}" - end + xml_url = "#{HOST_URL}/feed/channel/#{channel.id}" xml.element("outline", text: channel.author, title: channel.author, "type": "rss", xmlUrl: xml_url) diff --git a/src/invidious/user/exports.cr b/src/invidious/user/exports.cr index 3fa468ba..cae07f70 100644 --- a/src/invidious/user/exports.cr +++ b/src/invidious/user/exports.cr @@ -2,6 +2,30 @@ struct Invidious::User module Export extend self + NEWPIPE_APP_VERSION = "0.29.0" + NEWPIPE_APP_VERSION_INT = 1014 + NEWPIPE_YT_SERVICE_ID = 0 + + def to_newpipe(subscriptions : Array(InvidiousChannel)) + return JSON.build do |json| + json.object do + json.field "subscriptions" do + json.array do + subscriptions.each do |channel| + json.object do + json.field "service_id", NEWPIPE_YT_SERVICE_ID + json.field "url", "https://www.youtube.com/channel/" + channel.id + json.field "name", channel.author + end + end + end + end + json.field "app_version", NEWPIPE_APP_VERSION + json.field "app_version_int", NEWPIPE_APP_VERSION_INT + end + end + end + def to_invidious(user : User) playlists = Invidious::Database::Playlists.select_like_iv(user.email) diff --git a/src/invidious/views/user/data_control.ecr b/src/invidious/views/user/data_control.ecr index 1ada9712..a7271703 100644 --- a/src/invidious/views/user/data_control.ecr +++ b/src/invidious/views/user/data_control.ecr @@ -53,11 +53,11 @@