This commit is contained in:
ChunkyProgrammer 2024-04-30 23:45:35 +00:00 committed by GitHub
commit 08ab47b7b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 28 additions and 29 deletions

View File

@ -290,42 +290,41 @@ struct Invidious::User
end
def from_newpipe(user : User, body : String) : Bool
io = IO::Memory.new(body)
Compress::Zip::File.open(io) do |file|
Compress::Zip::File.open(IO::Memory.new(body), true) do |file|
file.entries.each do |entry|
entry.open do |file_io|
next if entry.filename != "newpipe.db"
# Ensure max size of 4MB
io_sized = IO::Sized.new(file_io, 0x400000)
next if entry.filename != "newpipe.db"
tempfile = File.tempfile(".db")
begin
File.write(tempfile.path, io_sized.gets_to_end)
rescue
return false
temp = File.tempfile(".db") do |tempfile|
begin
File.write(tempfile.path, io_sized.gets_to_end)
rescue
return false
end
DB.open("sqlite3://" + tempfile.path) do |db|
user.watched += db.query_all("SELECT url FROM streams", as: String)
.map(&.lchop("https://www.youtube.com/watch?v="))
user.watched.uniq!
Invidious::Database::Users.update_watch_history(user)
user.subscriptions += db.query_all("SELECT url FROM subscriptions", as: String)
.map(&.lchop("https://www.youtube.com/channel/"))
user.subscriptions.uniq!
user.subscriptions = get_batch_channels(user.subscriptions)
Invidious::Database::Users.update_subscriptions(user)
end
end
ensure
temp.delete if !temp.nil?
end
db = DB.open("sqlite3://" + tempfile.path)
user.watched += db.query_all("SELECT url FROM streams", as: String)
.map(&.lchop("https://www.youtube.com/watch?v="))
user.watched.uniq!
Invidious::Database::Users.update_watch_history(user)
user.subscriptions += db.query_all("SELECT url FROM subscriptions", as: String)
.map(&.lchop("https://www.youtube.com/channel/"))
user.subscriptions.uniq!
user.subscriptions = get_batch_channels(user.subscriptions)
Invidious::Database::Users.update_subscriptions(user)
db.close
tempfile.delete
end
end
end