]> code.delx.au - youtube-cgi/blobdiff - youtube.cgi
handle videos with no signature
[youtube-cgi] / youtube.cgi
index 7e7645614e9dcaa159aa9c843185cb485e427adf..67153e260d9ab1b44628414c6a0fd0f83767ca43 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python2
 
 from __future__ import division
 
@@ -79,6 +79,9 @@ urlopener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
 referrer = ""
 
 def urlopen(url, offset=None):
+       if url.startswith("//"):
+               url = "http:" + url
+
        global referrer
        req = urllib2.Request(url)
        if referrer:
@@ -146,11 +149,11 @@ def get_player_config(doc):
                                        return player_config
 
 def extract_function(output, script, func_name):
-       p1 = script.find("function " + func_name)
+       p1 = script.find("function " + func_name + "(")
        p2 = script.find("}", p1)
        code = script[p1:p2+1]
        output.append(code)
-       deps = re.findall(R"[^\.]\b([a-zA-Z]+)\(", code)
+       deps = re.findall(R"[^\.][= ]([\$0-9a-zA-Z]+)\(", code)
        deps = set(deps)
        deps.remove(func_name)
        for dep in deps:
@@ -207,9 +210,13 @@ def get_best_video(player_config):
                video_url = url_data["url"][0]
                if "sig" in url_data:
                        signature = url_data["sig"][0]
-               else:
+               elif "s" in url_data:
                        signature = decode_signature(js_url, url_data["s"][0])
-               video_url = append_to_qs(video_url, {"signature": signature})
+               else:
+                       signature = None
+
+               if signature:
+                       video_url = append_to_qs(video_url, {"signature": signature})
 
                best_url = video_url
                best_quality = quality