Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions src/invidious/routes/subscriptions.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment on lines +95 to 102
Expand Down
20 changes: 20 additions & 0 deletions src/invidious/user/exports.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@ struct Invidious::User
module Export
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
Comment on lines +5 to +23

def to_invidious(user : User)
playlists = Invidious::Database::Playlists.select_like_iv(user.email)

Expand Down
6 changes: 5 additions & 1 deletion src/invidious/views/user/data_control.ecr
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@
</div>

<div class="pure-control-group">
<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=opml_freetube"><%= I18n.translate(locale, "Export subscriptions as OPML (for FreeTube)") %></a>
</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>
Comment on lines +60 to +64
</div>

<div class="pure-control-group">
Expand Down
Loading