Only add signature if stream has decrypted signature

pull/3/head
Omar Roth 7 years ago
parent 1d301a5055
commit 4d1fa61bf0

@ -183,21 +183,26 @@ def swap(a, b)
end end
def decrypt_signature(a, base) def decrypt_signature(a, base)
if a && base
a = a.split("") a = a.split("")
if base == "vflG9lb96" case base
when "vflG9lb96"
a = swap(a, 26) a = swap(a, 26)
a.reverse! a.reverse!
a = swap(a, 8) a = swap(a, 8)
a = swap(a, 61) a = swap(a, 61)
elsif base == "vflxuxnEY" when "vflxuxnEY"
a.delete_at(0..2) a.delete_at(0..2)
a.reverse! a.reverse!
c = a[0] c = a[0]
a[0] = a[49 % a.size] a[0] = a[49 % a.size]
a[49] = c a[49] = c
elsif base == "vflAXQwEj" when "vflAXQwEj"
a = swap(a, 26)
a.reverse!
a = swap(a, 8)
a = swap(a, 61)
when "vflNpPGQq"
a = swap(a, 26) a = swap(a, 26)
a.reverse! a.reverse!
a = swap(a, 8) a = swap(a, 8)
@ -208,7 +213,6 @@ def decrypt_signature(a, base)
return a.join("") return a.join("")
end end
end
def rank_videos(db, n) def rank_videos(db, n)
top = [] of {Float64, String} top = [] of {Float64, String}

@ -176,24 +176,26 @@ get "/watch" do |env|
base = video.html.xpath_node(%q(//script[@name="player_ias/base"])) base = video.html.xpath_node(%q(//script[@name="player_ias/base"]))
end end
if base if !base
error_message = "Could not find signature for #{video.id}"
next templated "error"
end
base = base["src"] base = base["src"]
base = base.split("/")[3].split("-")[1] 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
end end
begin
fmt_stream.each do |fmt| fmt_stream.each do |fmt|
if fmt["s"]? && !base if base
File.write("info/#{id}.html", video.html) fmt["url"] += "&signature=" + decrypt_signature(fmt["s"], base)
raise "Could not find signature for #{video.id}"
end
fmt["url"] = "#{fmt["url"]}&signature=#{decrypt_signature(fmt["s"]?, base)}"
end end
rescue ex
error_message = ex
next templated "error"
end end
# We want lowest quality first # We want lowest quality first
@ -207,7 +209,9 @@ get "/watch" do |env|
end end
adaptive_fmts.each do |fmt| adaptive_fmts.each do |fmt|
fmt["url"] = "#{fmt["url"]}&signature=#{decrypt_signature(fmt["s"]?, base)}" if base
fmt["url"] += "&signature=" + decrypt_signature(fmt["s"], base)
end
end end
rvs = [] of Hash(String, String) rvs = [] of Hash(String, String)

Loading…
Cancel
Save