mirror of
https://github.com/iv-org/invidious.git
synced 2024-11-23 06:10:11 +00:00
Use a find instead of an each loop
This commit is contained in:
parent
6b0e4e6817
commit
bba1769f4b
@ -291,40 +291,38 @@ struct Invidious::User
|
||||
|
||||
def from_newpipe(user : User, body : String) : Bool
|
||||
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"
|
||||
entry = file.entries.find { |file_entry| file_entry.filename == "newpipe.db" }
|
||||
return false if entry.nil?
|
||||
entry.open do |file_io|
|
||||
# Ensure max size of 4MB
|
||||
io_sized = IO::Sized.new(file_io, 0x400000)
|
||||
|
||||
# Ensure max size of 4MB
|
||||
io_sized = IO::Sized.new(file_io, 0x400000)
|
||||
|
||||
begin
|
||||
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
|
||||
begin
|
||||
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
|
||||
ensure
|
||||
temp.delete if !temp.nil?
|
||||
end
|
||||
ensure
|
||||
temp.delete if !temp.nil?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user