mirror of https://github.com/iv-org/invidious.git
SigHelper: Small fixes + suggestions from code review
This commit is contained in:
parent
61d75050e4
commit
3b7e45b7bc
|
@ -9,7 +9,7 @@ require "socket/unix_socket"
|
||||||
|
|
||||||
private alias NetworkEndian = IO::ByteFormat::NetworkEndian
|
private alias NetworkEndian = IO::ByteFormat::NetworkEndian
|
||||||
|
|
||||||
class Invidious::SigHelper
|
module Invidious::SigHelper
|
||||||
enum UpdateStatus
|
enum UpdateStatus
|
||||||
Updated
|
Updated
|
||||||
UpdateNotRequired
|
UpdateNotRequired
|
||||||
|
@ -98,7 +98,7 @@ class Invidious::SigHelper
|
||||||
def decrypt_n_param(n : String) : String?
|
def decrypt_n_param(n : String) : String?
|
||||||
request = Request.new(Opcode::DECRYPT_N_SIGNATURE, StringPayload.new(n))
|
request = Request.new(Opcode::DECRYPT_N_SIGNATURE, StringPayload.new(n))
|
||||||
|
|
||||||
n_dec = send_request(request) do |bytes|
|
n_dec = self.send_request(request) do |bytes|
|
||||||
StringPayload.from_bytes(bytes).string
|
StringPayload.from_bytes(bytes).string
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ class Invidious::SigHelper
|
||||||
def decrypt_sig(sig : String) : String?
|
def decrypt_sig(sig : String) : String?
|
||||||
request = Request.new(Opcode::DECRYPT_SIGNATURE, StringPayload.new(sig))
|
request = Request.new(Opcode::DECRYPT_SIGNATURE, StringPayload.new(sig))
|
||||||
|
|
||||||
sig_dec = send_request(request) do |bytes|
|
sig_dec = self.send_request(request) do |bytes|
|
||||||
StringPayload.from_bytes(bytes).string
|
StringPayload.from_bytes(bytes).string
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -118,10 +118,10 @@ class Invidious::SigHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return the signature timestamp from the server's current player
|
# Return the signature timestamp from the server's current player
|
||||||
def get_sts : UInt64?
|
def get_signature_timestamp : UInt64?
|
||||||
request = Request.new(Opcode::GET_SIGNATURE_TIMESTAMP, nil)
|
request = Request.new(Opcode::GET_SIGNATURE_TIMESTAMP, nil)
|
||||||
|
|
||||||
return send_request(request) do |bytes|
|
return self.send_request(request) do |bytes|
|
||||||
IO::ByteFormat::NetworkEndian.decode(UInt64, bytes)
|
IO::ByteFormat::NetworkEndian.decode(UInt64, bytes)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -130,12 +130,12 @@ class Invidious::SigHelper
|
||||||
def get_player : UInt32?
|
def get_player : UInt32?
|
||||||
request = Request.new(Opcode::GET_PLAYER_STATUS, nil)
|
request = Request.new(Opcode::GET_PLAYER_STATUS, nil)
|
||||||
|
|
||||||
send_request(request) do |bytes|
|
return self.send_request(request) do |bytes|
|
||||||
has_player = (bytes[0] == 0xFF)
|
has_player = (bytes[0] == 0xFF)
|
||||||
player_version = IO::ByteFormat::NetworkEndian.decode(UInt32, bytes[1..4])
|
player_version = IO::ByteFormat::NetworkEndian.decode(UInt32, bytes[1..4])
|
||||||
|
has_player ? player_version : nil
|
||||||
end
|
end
|
||||||
|
|
||||||
return has_player ? player_version : nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private def send_request(request : Request, &)
|
private def send_request(request : Request, &)
|
||||||
|
@ -280,8 +280,7 @@ class Invidious::SigHelper
|
||||||
uri = URI.parse("tcp://#{host_or_path}")
|
uri = URI.parse("tcp://#{host_or_path}")
|
||||||
@socket = TCPSocket.new(uri.host.not_nil!, uri.port.not_nil!)
|
@socket = TCPSocket.new(uri.host.not_nil!, uri.port.not_nil!)
|
||||||
end
|
end
|
||||||
|
LOGGER.info("SigHelper: Using helper at '#{host_or_path}'")
|
||||||
LOGGER.debug("SigHelper: Listening on '#{host_or_path}'")
|
|
||||||
|
|
||||||
{% if flag?(:advanced_debug) %}
|
{% if flag?(:advanced_debug) %}
|
||||||
@io = IO::Hexdump.new(@socket, output: STDERR, read: true, write: true)
|
@io = IO::Hexdump.new(@socket, output: STDERR, read: true, write: true)
|
||||||
|
@ -296,11 +295,7 @@ class Invidious::SigHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def close : Nil
|
def close : Nil
|
||||||
if @socket.closed?
|
@socket.close if !@socket.closed?
|
||||||
raise Exception.new("SigHelper: Can't close socket, it's already closed")
|
|
||||||
else
|
|
||||||
@socket.close
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def flush(*args, **options)
|
def flush(*args, **options)
|
||||||
|
|
|
@ -37,7 +37,7 @@ struct Invidious::DecryptFunction
|
||||||
|
|
||||||
def get_sts : UInt64?
|
def get_sts : UInt64?
|
||||||
self.check_update
|
self.check_update
|
||||||
return SigHelper::Client.get_sts
|
return SigHelper::Client.get_signature_timestamp
|
||||||
rescue ex
|
rescue ex
|
||||||
LOGGER.debug(ex.message || "Signature: Unknown error")
|
LOGGER.debug(ex.message || "Signature: Unknown error")
|
||||||
LOGGER.trace(ex.inspect_with_backtrace)
|
LOGGER.trace(ex.inspect_with_backtrace)
|
||||||
|
|
|
@ -101,7 +101,7 @@ struct Video
|
||||||
# Methods for parsing streaming data
|
# Methods for parsing streaming data
|
||||||
|
|
||||||
def convert_url(fmt)
|
def convert_url(fmt)
|
||||||
if cfr = fmt["signatureCipher"]?.try { |h| HTTP::Params.parse(h.as_s) }
|
if cfr = fmt["signatureCipher"]?.try { |json| HTTP::Params.parse(json.as_s) }
|
||||||
sp = cfr["sp"]
|
sp = cfr["sp"]
|
||||||
url = URI.parse(cfr["url"])
|
url = URI.parse(cfr["url"])
|
||||||
params = url.query_params
|
params = url.query_params
|
||||||
|
|
Loading…
Reference in New Issue