Replace signature function with generic catchall

This commit is contained in:
Omar Roth 2018-02-22 13:01:37 -06:00
parent 225625a0fb
commit 13ef4440d0
2 changed files with 19 additions and 70 deletions

View File

@ -175,54 +175,24 @@ def search(query, client)
end end
end end
def swap(a, b) def splice(a, b)
c = a[0] c = a[0]
a[0] = a[b % a.size] a[0] = a[b % a.size]
a[b % a.size] = c a[b % a.size] = c
return a return a
end end
def decrypt_signature(a, base) def decrypt_signature(a)
a = a.split("") a = a.split("")
case base a.delete_at(0..1)
when "vflG9lb96" a = splice(a, 2)
a = swap(a, 26) a = splice(a, 51)
a.reverse! a = splice(a, 9)
a = swap(a, 8) a.delete_at(0..1)
a = swap(a, 61) a.reverse!
when "vflxuxnEY" a = splice(a, 15)
a.delete_at(0..2) a.delete_at(0..2)
a.reverse!
c = a[0]
a[0] = a[49 % a.size]
a[49] = c
when "vflAXQwEj"
a = swap(a, 26)
a.reverse!
a = swap(a, 8)
a = swap(a, 61)
when "vflNpPGQq"
a = swap(a, 26)
a.reverse!
a = swap(a, 8)
a = swap(a, 61)
when "vflCCoUi2"
a = swap(a, 26)
a.reverse!
a = swap(a, 8)
a = swap(a, 61)
when "vflg4IfMn"
a = swap(a, 6)
a = swap(a, 64)
a = swap(a, 25)
a = swap(a, 53)
a.delete_at(0..1)
a.reverse!
a.delete_at(0..2)
else
raise "Could not decrypt signature for player #{base}"
end
return a.join("") return a.join("")
end end

View File

@ -177,34 +177,9 @@ get "/watch" do |env|
fmt_stream << HTTP::Params.parse(string) fmt_stream << HTTP::Params.parse(string)
end end
base = nil signature = false
if fmt_stream[0]? && fmt_stream[0]["s"]? if fmt_stream[0]? && fmt_stream[0]["s"]?
base = video.html.xpath_node(%q(//script[@name="player/base"])) signature = true
if !base
base = video.html.xpath_node(%q(//script[@name="player_ias/base"]))
end
if !base
error_message = "Could not find signature for #{video.id}"
next templated "error"
end
base = base["src"]
base = base.split("/")[3].split("-")[1]
begin
decrypt_signature(fmt_stream[0]["s"], base)
rescue ex
error_message = ex.message
next templated "error"
end
end
fmt_stream.each do |fmt|
if base
fmt["url"] += "&signature=" + decrypt_signature(fmt["s"], base)
end
end end
# We want lowest quality first # We want lowest quality first
@ -217,9 +192,13 @@ get "/watch" do |env|
end end
end end
adaptive_fmts.each do |fmt| if signature
if base adaptive_fmts.each do |fmt|
fmt["url"] += "&signature=" + decrypt_signature(fmt["s"], base) fmt["url"] += "&signature=" + decrypt_signature(fmt["s"])
end
fmt_stream.each do |fmt|
fmt["url"] += "&signature=" + decrypt_signature(fmt["s"])
end end
end end