summaryrefslogtreecommitdiffstats
path: root/src/invidious.cr
diff options
context:
space:
mode:
authorTheFrenchGhosty <47571719+TheFrenchGhosty@users.noreply.github.com>2021-03-05 01:01:32 +0100
committerGitHub <noreply@github.com>2021-03-05 01:01:32 +0100
commit3cc9114f8101c73a645f3fd61b9fe6def38ef7c7 (patch)
treeb2fd4f722af187d4ad4c4b463a85181e308d9f19 /src/invidious.cr
parent790167e9147f6dfaef6de68cd6be9af72e8e82db (diff)
parent84487b2e520f74871afb7dfa97117cfe0282f0c9 (diff)
downloadinvidious-3cc9114f8101c73a645f3fd61b9fe6def38ef7c7.tar.gz
invidious-3cc9114f8101c73a645f3fd61b9fe6def38ef7c7.tar.bz2
invidious-3cc9114f8101c73a645f3fd61b9fe6def38ef7c7.zip
Merge pull request #1829 from SimonPhoenix96/xml-json-yt-sub-import
integrate legacy yt xml subscription import with new json sub import
Diffstat (limited to 'src/invidious.cr')
-rw-r--r--src/invidious.cr22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index cb2bb5fe..6d0238a1 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -751,10 +751,16 @@ post "/data_control" do |env|
end
end
when "import_youtube"
- subscriptions = JSON.parse(body)
-
- user.subscriptions += subscriptions.as_a.compact_map do |entry|
- entry["snippet"]["resourceId"]["channelId"].as_s
+ if body[0..4] == "<opml"
+ 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]
+ end
+ else
+ subscriptions = JSON.parse(body)
+ user.subscriptions += subscriptions.as_a.compact_map do |entry|
+ entry["snippet"]["resourceId"]["channelId"].as_s
+ end
end
user.subscriptions.uniq!
@@ -1548,12 +1554,12 @@ post "/feed/webhook/:token" do |env|
views: video.views,
})
- was_insert = PG_DB.query_one("INSERT INTO channel_videos VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) \
- ON CONFLICT (id) DO UPDATE SET title = $2, published = $3, \
- updated = $4, ucid = $5, author = $6, length_seconds = $7, \
+ was_insert = PG_DB.query_one("INSERT INTO channel_videos VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
+ ON CONFLICT (id) DO UPDATE SET title = $2, published = $3,
+ updated = $4, ucid = $5, author = $6, length_seconds = $7,
live_now = $8, premiere_timestamp = $9, views = $10 returning (xmax=0) as was_insert", *video.to_tuple, as: Bool)
- PG_DB.exec("UPDATE users SET notifications = array_append(notifications, $1), \
+ PG_DB.exec("UPDATE users SET notifications = array_append(notifications, $1),
feed_needs_update = true WHERE $2 = ANY(subscriptions)", video.id, video.ucid) if was_insert
end
end