mirror of
https://github.com/iv-org/invidious.git
synced 2024-10-01 01:25:56 -04:00
Compare commits
4 Commits
91ef0ec56a
...
d9fcfe6a23
Author | SHA1 | Date | |
---|---|---|---|
|
d9fcfe6a23 | ||
|
77de46f316 | ||
|
123c4dfba5 | ||
|
a0bb4b32c6 |
@ -290,26 +290,22 @@ struct Invidious::User
|
|||||||
end
|
end
|
||||||
|
|
||||||
def from_newpipe(user : User, body : String) : Bool
|
def from_newpipe(user : User, body : String) : Bool
|
||||||
io = IO::Memory.new(body)
|
Compress::Zip::File.open(IO::Memory.new(body), true) do |file|
|
||||||
|
entry = file.entries.find { |file_entry| file_entry.filename == "newpipe.db" }
|
||||||
Compress::Zip::File.open(io) do |file|
|
return false if entry.nil?
|
||||||
file.entries.each do |entry|
|
|
||||||
entry.open do |file_io|
|
entry.open do |file_io|
|
||||||
# Ensure max size of 4MB
|
# Ensure max size of 4MB
|
||||||
io_sized = IO::Sized.new(file_io, 0x400000)
|
io_sized = IO::Sized.new(file_io, 0x400000)
|
||||||
|
|
||||||
next if entry.filename != "newpipe.db"
|
begin
|
||||||
|
temp = File.tempfile(".db") do |tempfile|
|
||||||
tempfile = File.tempfile(".db")
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
File.write(tempfile.path, io_sized.gets_to_end)
|
File.write(tempfile.path, io_sized.gets_to_end)
|
||||||
rescue
|
rescue
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
db = DB.open("sqlite3://" + tempfile.path)
|
DB.open("sqlite3://" + tempfile.path) do |db|
|
||||||
|
|
||||||
user.watched += db.query_all("SELECT url FROM streams", as: String)
|
user.watched += db.query_all("SELECT url FROM streams", as: String)
|
||||||
.map(&.lchop("https://www.youtube.com/watch?v="))
|
.map(&.lchop("https://www.youtube.com/watch?v="))
|
||||||
|
|
||||||
@ -323,9 +319,10 @@ struct Invidious::User
|
|||||||
user.subscriptions = get_batch_channels(user.subscriptions)
|
user.subscriptions = get_batch_channels(user.subscriptions)
|
||||||
|
|
||||||
Invidious::Database::Users.update_subscriptions(user)
|
Invidious::Database::Users.update_subscriptions(user)
|
||||||
|
end
|
||||||
db.close
|
end
|
||||||
tempfile.delete
|
ensure
|
||||||
|
temp.delete if !temp.nil?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user