summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSamantaz Fox <coding@samantaz.fr>2024-08-01 23:28:30 +0200
committerSamantaz Fox <coding@samantaz.fr>2024-08-07 23:25:32 +0200
commitec1bb5db87a40d74203a09ca401d0f70d0ad962d (patch)
tree61836082ff021c7090c277baef51f68c32dac7e2 /src
parent3b7e45b7bc5798e05d49658428b49536d20e745c (diff)
downloadinvidious-ec1bb5db87a40d74203a09ca401d0f70d0ad962d.tar.gz
invidious-ec1bb5db87a40d74203a09ca401d0f70d0ad962d.tar.bz2
invidious-ec1bb5db87a40d74203a09ca401d0f70d0ad962d.zip
SigHelper: Add support for PLAYER_UPDATE_TIMESTAMP opcode
Diffstat (limited to 'src')
-rw-r--r--src/invidious/helpers/sig_helper.cr9
-rw-r--r--src/invidious/helpers/signatures.cr17
2 files changed, 22 insertions, 4 deletions
diff --git a/src/invidious/helpers/sig_helper.cr b/src/invidious/helpers/sig_helper.cr
index 108587ce..2239858b 100644
--- a/src/invidious/helpers/sig_helper.cr
+++ b/src/invidious/helpers/sig_helper.cr
@@ -61,6 +61,7 @@ module Invidious::SigHelper
DECRYPT_SIGNATURE = 2
GET_SIGNATURE_TIMESTAMP = 3
GET_PLAYER_STATUS = 4
+ PLAYER_UPDATE_TIMESTAMP = 5
end
private record Request,
@@ -135,7 +136,15 @@ module Invidious::SigHelper
player_version = IO::ByteFormat::NetworkEndian.decode(UInt32, bytes[1..4])
has_player ? player_version : nil
end
+ end
+
+ # Return when the player was last updated
+ def get_player_timestamp : UInt64?
+ request = Request.new(Opcode::GET_SIGNATURE_TIMESTAMP, nil)
+ return self.send_request(request) do |bytes|
+ IO::ByteFormat::NetworkEndian.decode(UInt64, bytes)
+ end
end
private def send_request(request : Request, &)
diff --git a/src/invidious/helpers/signatures.cr b/src/invidious/helpers/signatures.cr
index 8fbfaac0..cf170668 100644
--- a/src/invidious/helpers/signatures.cr
+++ b/src/invidious/helpers/signatures.cr
@@ -2,18 +2,27 @@ require "http/params"
require "./sig_helper"
struct Invidious::DecryptFunction
- @last_update = Time.monotonic - 42.days
+ @last_update : Time = Time.utc - 42.days
def initialize
self.check_update
end
def check_update
- now = Time.monotonic
- if (now - @last_update) > 60.seconds
+ now = Time.utc
+
+ # If we have updated in the last 5 minutes, do nothing
+ return if (now - @last_update) > 5.minutes
+
+ # Get the time when the player was updated, in the event where
+ # multiple invidious processes are run in parallel.
+ player_ts = Invidious::SigHelper::Client.get_player_timestamp
+ player_time = Time.unix(player_ts || 0)
+
+ if (now - player_time) > 5.minutes
LOGGER.debug("Signature: Player might be outdated, updating")
Invidious::SigHelper::Client.force_update
- @last_update = Time.monotonic
+ @last_update = Time.utc
end
end