mirror of
https://github.com/iv-org/invidious.git
synced 2024-11-09 15:02:14 +05:30
Merge 77de46f316
into 4782a67038
This commit is contained in:
commit
d9fcfe6a23
@ -290,42 +290,39 @@ 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" }
|
||||||
|
return false if entry.nil?
|
||||||
|
entry.open do |file_io|
|
||||||
|
# Ensure max size of 4MB
|
||||||
|
io_sized = IO::Sized.new(file_io, 0x400000)
|
||||||
|
|
||||||
Compress::Zip::File.open(io) do |file|
|
begin
|
||||||
file.entries.each do |entry|
|
temp = File.tempfile(".db") do |tempfile|
|
||||||
entry.open do |file_io|
|
begin
|
||||||
# Ensure max size of 4MB
|
File.write(tempfile.path, io_sized.gets_to_end)
|
||||||
io_sized = IO::Sized.new(file_io, 0x400000)
|
rescue
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
next if entry.filename != "newpipe.db"
|
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="))
|
||||||
|
|
||||||
tempfile = File.tempfile(".db")
|
user.watched.uniq!
|
||||||
|
Invidious::Database::Users.update_watch_history(user)
|
||||||
|
|
||||||
begin
|
user.subscriptions += db.query_all("SELECT url FROM subscriptions", as: String)
|
||||||
File.write(tempfile.path, io_sized.gets_to_end)
|
.map(&.lchop("https://www.youtube.com/channel/"))
|
||||||
rescue
|
|
||||||
return false
|
user.subscriptions.uniq!
|
||||||
|
user.subscriptions = get_batch_channels(user.subscriptions)
|
||||||
|
|
||||||
|
Invidious::Database::Users.update_subscriptions(user)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
ensure
|
||||||
db = DB.open("sqlite3://" + tempfile.path)
|
temp.delete if !temp.nil?
|
||||||
|
|
||||||
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
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user