mirror of
https://git.nadeko.net/Fijxu/invidious.git
synced 2025-12-21 10:28:50 +00:00
User: Add support for importing Youtube watch history (#4171)
This commit is contained in:
@@ -218,6 +218,26 @@ struct Invidious::User
|
||||
end
|
||||
end
|
||||
|
||||
def from_youtube_wh(user : User, body : String, filename : String, type : String) : Bool
|
||||
extension = filename.split(".").last
|
||||
|
||||
if extension == "json" || type == "application/json"
|
||||
data = JSON.parse(body)
|
||||
watched = data.as_a.compact_map do |item|
|
||||
next unless url = item["titleUrl"]?
|
||||
next unless match = url.as_s.match(/\?v=(?<video_id>[a-zA-Z0-9_-]+)$/)
|
||||
match["video_id"]
|
||||
end
|
||||
watched.reverse! # YouTube have newest first
|
||||
user.watched += watched
|
||||
user.watched.uniq!
|
||||
Invidious::Database::Users.update_watch_history(user)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
# -------------------
|
||||
# Freetube
|
||||
# -------------------
|
||||
|
||||
Reference in New Issue
Block a user