Compare commits
2 commits
Author | SHA1 | Date | |
---|---|---|---|
31e9773b0c | |||
1f94a0e1ec |
11 changed files with 84 additions and 44 deletions
|
@ -49,14 +49,14 @@ module Invidious::Database::Users
|
|||
PG_DB.exec(request, user.watched, user.email)
|
||||
end
|
||||
|
||||
def mark_watched(user : User, vid : String)
|
||||
def mark_watched(user : User, history_details : JSON::Any)
|
||||
request = <<-SQL
|
||||
UPDATE users
|
||||
SET watched = array_append(array_remove(watched, $1), $1)
|
||||
SET watched = array_append(array_remove(watched, $1::jsonb), $1::jsonb)
|
||||
WHERE email = $2
|
||||
SQL
|
||||
|
||||
PG_DB.exec(request, vid, user.email)
|
||||
PG_DB.exec(request, history_details, user.email)
|
||||
end
|
||||
|
||||
def mark_unwatched(user : User, vid : String)
|
||||
|
@ -79,6 +79,16 @@ module Invidious::Database::Users
|
|||
PG_DB.exec(request, user.email)
|
||||
end
|
||||
|
||||
def get_watched(user : User)
|
||||
request = <<-SQL
|
||||
SELECT watched
|
||||
from users
|
||||
where email = $1
|
||||
SQL
|
||||
|
||||
PG_DB.query_one?(request, user.email, &.read(Array(JSON::Any)))
|
||||
end
|
||||
|
||||
# -------------------
|
||||
# Update (channels)
|
||||
# -------------------
|
||||
|
|
|
@ -86,7 +86,7 @@ module Invidious::Routes::API::V1::Authenticated
|
|||
return error_json(400, "Invalid video id.")
|
||||
end
|
||||
|
||||
Invidious::Database::Users.mark_watched(user, id)
|
||||
# Invidious::Database::Users.mark_watched(user, id)
|
||||
env.response.status_code = 204
|
||||
end
|
||||
|
||||
|
|
|
@ -124,7 +124,7 @@ module Invidious::Routes::Embed
|
|||
user = env.get?("user").try &.as(User)
|
||||
if user
|
||||
subscriptions = user.subscriptions
|
||||
watched = user.watched
|
||||
# watched = user.watched
|
||||
notifications = user.notifications
|
||||
end
|
||||
subscriptions ||= [] of String
|
||||
|
|
|
@ -123,15 +123,17 @@ module Invidious::Routes::Feeds
|
|||
end
|
||||
|
||||
user = user.as(User)
|
||||
watched = Invidious::Database::Users.get_watched(user)
|
||||
|
||||
max_results = env.params.query["max_results"]?.try &.to_i?.try &.clamp(0, MAX_ITEMS_PER_PAGE)
|
||||
max_results ||= user.preferences.max_results
|
||||
max_results ||= CONFIG.default_user_preferences.max_results
|
||||
|
||||
if user.watched[(page - 1) * max_results]?
|
||||
watched = user.watched.reverse[(page - 1) * max_results, max_results]
|
||||
end
|
||||
watched ||= [] of String
|
||||
# TODO: History!!
|
||||
# if user.watched[(page - 1) * max_results]?
|
||||
# watched = user.watched.reverse[(page - 1) * max_results, max_results]
|
||||
# end
|
||||
# watched ||= [] of String
|
||||
|
||||
# Used for pagination links
|
||||
base_url = "/feed/history"
|
||||
|
|
|
@ -43,7 +43,7 @@ module Invidious::Routes::Watch
|
|||
user = env.get?("user").try &.as(User)
|
||||
if user
|
||||
subscriptions = user.subscriptions
|
||||
watched = user.watched
|
||||
# watched = user.watched
|
||||
notifications = user.notifications
|
||||
end
|
||||
subscriptions ||= [] of String
|
||||
|
@ -68,8 +68,14 @@ module Invidious::Routes::Watch
|
|||
end
|
||||
env.params.query.delete_all("iv_load_policy")
|
||||
|
||||
if watched && preferences.watch_history
|
||||
Invidious::Database::Users.mark_watched(user.as(User), id)
|
||||
history_details = JSON::Any.new({
|
||||
"id" => JSON::Any.new(id),
|
||||
"title" => JSON::Any.new(video.title),
|
||||
"author" => JSON::Any.new(video.author)
|
||||
})
|
||||
|
||||
if preferences.watch_history
|
||||
Invidious::Database::Users.mark_watched(user.as(User), history_details)
|
||||
end
|
||||
|
||||
if CONFIG.enable_user_notifications && notifications && notifications.includes? id
|
||||
|
@ -278,9 +284,9 @@ module Invidious::Routes::Watch
|
|||
|
||||
case action
|
||||
when "action_mark_watched"
|
||||
Invidious::Database::Users.mark_watched(user, id)
|
||||
# Invidious::Database::Users.mark_watched(user, history_details)
|
||||
when "action_mark_unwatched"
|
||||
Invidious::Database::Users.mark_unwatched(user, id)
|
||||
# Invidious::Database::Users.mark_unwatched(user, id)
|
||||
else
|
||||
return error_json(400, "Unsupported action #{action}")
|
||||
end
|
||||
|
|
22
src/invidious/routes/xd.xml
Normal file
22
src/invidious/routes/xd.xml
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<feed xmlns:yt= \x22http:// www.youtube.com/ xml/ schemas/ 2015\x22 xmlns= \x22http:// www.w3.org/ 2005/ Atom\x22>
|
||||
<link rel= \x22hub\x22 href= \x22https:// pubsubhubbub.appspot.com\x22 />
|
||||
<link rel= \x22self\x22 href= \x22https:// www.youtube.com/ xml/ feeds/ videos.xml?channel_id=UCn8n_wDeUDrdDMQfoElZlfw\x22/>
|
||||
<title>YouTube video feed</title>
|
||||
<updated>2024-12-18T23:19:42.357314923+00:00</updated>
|
||||
<entry>
|
||||
<id>yt:video:YYBivfsnwIU</id>
|
||||
<yt:videoId>YYBivfsnwIU</yt:videoId>
|
||||
<yt:channelId>
|
||||
UCn8n_wDeUDrdDMQfoElZlfw</yt:channelId>
|
||||
<title>How To Make Silicone Tray Liners For the HARVESTRIGHT FREEZE DRYER #siliconetrayliners</title>
|
||||
<link rel= \x22alternate\x22 href= \x22https:// www.youtube.com/ watch?v=YYBivfsnwIU\x22/>\x0A
|
||||
<author>\x0A
|
||||
<name>TheFreeze Drying Community</name>
|
||||
<uri>https://www.youtube.com/channel/UCn8n_wDeUDrdDMQfoElZlfw</uri>
|
||||
</author>
|
||||
<published>
|
||||
2021-02-07T14:00:17+00:00</published>\x0A <updated>2024-12-18T23:19:42.357314923+00:00</updated>
|
||||
\x0A
|
||||
</entry>
|
||||
</feed>
|
|
@ -8,7 +8,7 @@ struct Invidious::User
|
|||
return JSON.build do |json|
|
||||
json.object do
|
||||
json.field "subscriptions", user.subscriptions
|
||||
json.field "watch_history", user.watched
|
||||
# json.field "watch_history", user.watched
|
||||
json.field "preferences", user.preferences
|
||||
json.field "playlists" do
|
||||
json.array do
|
||||
|
|
|
@ -100,11 +100,11 @@ struct Invidious::User
|
|||
Invidious::Database::Users.update_subscriptions(user)
|
||||
end
|
||||
|
||||
if data["watch_history"]?
|
||||
user.watched += data["watch_history"].as_a.map(&.as_s)
|
||||
user.watched.reverse!.uniq!.reverse!
|
||||
Invidious::Database::Users.update_watch_history(user)
|
||||
end
|
||||
# if data["watch_history"]?
|
||||
# user.watched += data["watch_history"].as_a.map(&.as_s)
|
||||
# user.watched.reverse!.uniq!.reverse!
|
||||
# Invidious::Database::Users.update_watch_history(user)
|
||||
# end
|
||||
|
||||
if data["preferences"]?
|
||||
user.preferences = Preferences.from_json(data["preferences"].to_json)
|
||||
|
@ -219,23 +219,23 @@ struct Invidious::User
|
|||
end
|
||||
|
||||
def from_youtube_wh(user : User, body : String, filename : String, type : String) : Bool
|
||||
extension = filename.split(".").last
|
||||
# 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
|
||||
# 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
|
||||
end
|
||||
|
||||
# -------------------
|
||||
|
@ -310,11 +310,11 @@ struct Invidious::User
|
|||
|
||||
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 += 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.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/"))
|
||||
|
|
|
@ -12,7 +12,7 @@ struct Invidious::User
|
|||
property preferences : Preferences
|
||||
property password : String?
|
||||
property token : String
|
||||
property watched : Array(String)
|
||||
# property watched : Array(String)
|
||||
property feed_needs_update : Bool?
|
||||
|
||||
module PreferencesConverter
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<%-
|
||||
thin_mode = env.get("preferences").as(Preferences).thin_mode
|
||||
item_watched = !item.is_a?(SearchChannel | SearchHashtag | SearchPlaylist | InvidiousPlaylist | Category) && env.get?("user").try &.as(User).watched.index(item.id) != nil
|
||||
# item_watched = !item.is_a?(SearchChannel | SearchHashtag | SearchPlaylist | InvidiousPlaylist | Category) && env.get?("user").try &.as(User).watched.index(item.id) != nil
|
||||
author_verified = item.responds_to?(:author_verified) && item.author_verified
|
||||
-%>
|
||||
|
||||
|
@ -117,10 +117,10 @@
|
|||
<a tabindex="-1" href="<%= link_url %>">
|
||||
<img loading="lazy" class="thumbnail" src="/vi/<%= item.id %>/mqdefault.jpg" alt="" />
|
||||
|
||||
<% if item_watched %>
|
||||
<% #if item_watched %>
|
||||
<div class="watched-overlay"></div>
|
||||
<div class="watched-indicator" data-length="<%= item.length_seconds %>" data-id="<%= item.id %>"></div>
|
||||
<% end %>
|
||||
<% #end %>
|
||||
</a>
|
||||
<%- else -%>
|
||||
<div class="thumbnail-placeholder"></div>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
<div class="pure-g h-box">
|
||||
<div class="pure-u-1-3">
|
||||
<h3><%= translate_count(locale, "generic_videos_count", user.watched.size, NumberFormatting::HtmlSpan) %></h3>
|
||||
<h3><%= translate_count(locale, "generic_videos_count", watched.size, NumberFormatting::HtmlSpan) %></h3>
|
||||
</div>
|
||||
<div class="pure-u-1-3">
|
||||
<h3 style="text-align:center">
|
||||
|
|
Loading…
Add table
Reference in a new issue