diff options
| author | Omar Roth <omarroth@hotmail.com> | 2018-02-22 13:01:37 -0600 |
|---|---|---|
| committer | Omar Roth <omarroth@hotmail.com> | 2018-02-22 13:01:37 -0600 |
| commit | 13ef4440d01b606e07c5e96f0f0117ead2ba9f1c (patch) | |
| tree | 1efc204bc23690aa3bc0beffd478721ccdcd4f28 /src | |
| parent | 225625a0fbbcf4af4551b8a1a29db916923a2649 (diff) | |
| download | invidious-13ef4440d01b606e07c5e96f0f0117ead2ba9f1c.tar.gz invidious-13ef4440d01b606e07c5e96f0f0117ead2ba9f1c.tar.bz2 invidious-13ef4440d01b606e07c5e96f0f0117ead2ba9f1c.zip | |
Replace signature function with generic catchall
Diffstat (limited to 'src')
| -rw-r--r-- | src/helpers.cr | 50 | ||||
| -rw-r--r-- | src/invidious.cr | 39 |
2 files changed, 19 insertions, 70 deletions
diff --git a/src/helpers.cr b/src/helpers.cr index 9ce527a7..d3c89e03 100644 --- a/src/helpers.cr +++ b/src/helpers.cr @@ -175,54 +175,24 @@ def search(query, client) end end -def swap(a, b) +def splice(a, b) c = a[0] a[0] = a[b % a.size] a[b % a.size] = c return a end -def decrypt_signature(a, base) +def decrypt_signature(a) a = a.split("") - case base - when "vflG9lb96" - a = swap(a, 26) - a.reverse! - a = swap(a, 8) - a = swap(a, 61) - when "vflxuxnEY" - 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 + a.delete_at(0..1) + a = splice(a, 2) + a = splice(a, 51) + a = splice(a, 9) + a.delete_at(0..1) + a.reverse! + a = splice(a, 15) + a.delete_at(0..2) return a.join("") end diff --git a/src/invidious.cr b/src/invidious.cr index cb95647c..ae9e0978 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -177,34 +177,9 @@ get "/watch" do |env| fmt_stream << HTTP::Params.parse(string) end - base = nil + signature = false if fmt_stream[0]? && fmt_stream[0]["s"]? - base = video.html.xpath_node(%q(//script[@name="player/base"])) - - 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 + signature = true end # We want lowest quality first @@ -217,9 +192,13 @@ get "/watch" do |env| end end - adaptive_fmts.each do |fmt| - if base - fmt["url"] += "&signature=" + decrypt_signature(fmt["s"], base) + if signature + adaptive_fmts.each do |fmt| + fmt["url"] += "&signature=" + decrypt_signature(fmt["s"]) + end + + fmt_stream.each do |fmt| + fmt["url"] += "&signature=" + decrypt_signature(fmt["s"]) end end |
