diff options
| author | Omar Roth <omarroth@hotmail.com> | 2018-02-12 19:54:11 -0600 |
|---|---|---|
| committer | Omar Roth <omarroth@hotmail.com> | 2018-02-12 19:54:11 -0600 |
| commit | 4d1fa61bf007c6ef668e4883802aab33203d4f17 (patch) | |
| tree | ffcf20133dcda4ffefed24e7870f4f4e6f069242 /src | |
| parent | 1d301a5055328881f348b61ac10b74d175a54a3c (diff) | |
| download | invidious-4d1fa61bf007c6ef668e4883802aab33203d4f17.tar.gz invidious-4d1fa61bf007c6ef668e4883802aab33203d4f17.tar.bz2 invidious-4d1fa61bf007c6ef668e4883802aab33203d4f17.zip | |
Only add signature if stream has decrypted signature
Diffstat (limited to 'src')
| -rw-r--r-- | src/helpers.cr | 14 | ||||
| -rw-r--r-- | src/invidious.cr | 28 |
2 files changed, 25 insertions, 17 deletions
diff --git a/src/helpers.cr b/src/helpers.cr index 4ac08f9e..e6bb2ab3 100644 --- a/src/helpers.cr +++ b/src/helpers.cr @@ -183,21 +183,26 @@ def swap(a, b) end def decrypt_signature(a, base) - if a && base a = a.split("") - if base == "vflG9lb96" + case base + when "vflG9lb96" a = swap(a, 26) a.reverse! a = swap(a, 8) a = swap(a, 61) - elsif base == "vflxuxnEY" + when "vflxuxnEY" a.delete_at(0..2) a.reverse! c = a[0] a[0] = a[49 % a.size] 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.reverse! a = swap(a, 8) @@ -208,7 +213,6 @@ def decrypt_signature(a, base) return a.join("") end -end def rank_videos(db, n) top = [] of {Float64, String} diff --git a/src/invidious.cr b/src/invidious.cr index 2a5ff4e0..f7fccb22 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -176,24 +176,26 @@ get "/watch" do |env| base = video.html.xpath_node(%q(//script[@name="player_ias/base"])) end - if base + 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 - begin fmt_stream.each do |fmt| - if fmt["s"]? && !base - File.write("info/#{id}.html", video.html) - raise "Could not find signature for #{video.id}" - end - - fmt["url"] = "#{fmt["url"]}&signature=#{decrypt_signature(fmt["s"]?, base)}" + if base + fmt["url"] += "&signature=" + decrypt_signature(fmt["s"], base) end - rescue ex - error_message = ex - next templated "error" end # We want lowest quality first @@ -207,7 +209,9 @@ get "/watch" do |env| end 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 rvs = [] of Hash(String, String) |
