add subscription json export for NewPipe

This commit is contained in:
unrealtournament 2026-07-24 22:02:19 +02:00
parent 59bb97cdc3
commit ac4c597aa7
3 changed files with 29 additions and 4 deletions

View File

@ -80,14 +80,15 @@ module Invidious::Routes::Subscriptions
subscriptions.sort_by!(&.author.downcase) subscriptions.sort_by!(&.author.downcase)
if action_takeout if action_takeout
if format == "json"
env.response.content_type = "application/json" env.response.content_type = "application/json"
env.response.headers["content-disposition"] = "attachment" env.response.headers["content-disposition"] = "attachment"
if format == "json"
return Invidious::User::Export.to_invidious(user) return Invidious::User::Export.to_invidious(user)
elsif format == "newpipe_json"
return Invidious::User::Export.to_newpipe(subscriptions)
else else
env.response.content_type = "application/xml" env.response.content_type = "application/xml"
env.response.headers["content-disposition"] = "attachment"
export = XML.build do |xml| export = XML.build do |xml|
xml.element("opml", version: "1.1") do xml.element("opml", version: "1.1") do
xml.element("body") do xml.element("body") do

View File

@ -2,6 +2,26 @@ struct Invidious::User
module Export module Export
extend self extend self
def to_newpipe(subscriptions)
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", 0
json.field "url", "https://www.youtube.com/channel/" + channel.id
json.field "name", channel.author
end
end
end
end
json.field "app_version", "0.29.0"
json.field "app_version_int", 1014
end
end
end
def to_invidious(user : User) def to_invidious(user : User)
playlists = Invidious::Database::Playlists.select_like_iv(user.email) playlists = Invidious::Database::Playlists.select_like_iv(user.email)

View File

@ -60,6 +60,10 @@
<a href="/subscription_manager?action_takeout=1&format=newpipe"><%= I18n.translate(locale, "Export subscriptions as OPML (for NewPipe & FreeTube)") %></a> <a href="/subscription_manager?action_takeout=1&format=newpipe"><%= I18n.translate(locale, "Export subscriptions as OPML (for NewPipe & FreeTube)") %></a>
</div> </div>
<div class="pure-control-group">
<a href="/subscription_manager?action_takeout=1&format=newpipe_json"><%= I18n.translate(locale, "Export subscriptions as JSON (for NewPipe)") %></a>
</div>
<div class="pure-control-group"> <div class="pure-control-group">
<a href="/subscription_manager?action_takeout=1&format=json"><%= I18n.translate(locale, "Export data as JSON") %></a> <a href="/subscription_manager?action_takeout=1&format=json"><%= I18n.translate(locale, "Export data as JSON") %></a>
</div> </div>