From 7f75a7ca0be1c778aa721d8902874eb12a529a6b Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Fri, 22 Feb 2019 20:36:16 -0600 Subject: [PATCH] Add support for changing signature param --- src/invidious/signatures.cr | 10 ++++++++-- src/invidious/videos.cr | 12 ++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/invidious/signatures.cr b/src/invidious/signatures.cr index b2ed89d26..8b7603981 100644 --- a/src/invidious/signatures.cr +++ b/src/invidious/signatures.cr @@ -39,7 +39,12 @@ def fetch_decrypt_function(id = "CvFH_6DNRCY") return decrypt_function end -def decrypt_signature(a, code) +def decrypt_signature(fmt, code) + if !fmt["s"]? + return "" + end + + a = fmt["s"] a = a.split("") code.each do |item| @@ -53,7 +58,8 @@ def decrypt_signature(a, code) end end - return a.join("") + signature = a.join("") + return "&#{fmt["sp"]?}=#{signature}" end def splice(a, b) diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index 9c2d8745f..03770af7b 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -286,10 +286,8 @@ class Video end end - if streams[0]? && streams[0]["s"]? - streams.each do |fmt| - fmt["url"] += "&signature=" + decrypt_signature(fmt["s"], decrypt_function) - end + streams.each do |fmt| + fmt["url"] += decrypt_signature(fmt, decrypt_function) end return streams @@ -381,10 +379,8 @@ class Video end end - if adaptive_fmts[0]? && adaptive_fmts[0]["s"]? - adaptive_fmts.each do |fmt| - fmt["url"] += "&signature=" + decrypt_signature(fmt["s"], decrypt_function) - end + adaptive_fmts.each do |fmt| + fmt["url"] += decrypt_signature(fmt, decrypt_function) end return adaptive_fmts