Created
August 25, 2013 07:25
-
-
Save qrtt1/6332471 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ast | |
import urllib | |
import unparse | |
YDL_YOUTUBE_IE_SOURCE="https://raw.github.com/rg3/youtube-dl/master/youtube_dl/extractor/youtube.py" | |
class TargetFinder(ast.NodeVisitor): | |
def __init__(self): | |
self.target = None | |
def visit_FunctionDef(self, node): | |
if node.name == "_decrypt_signature": | |
self.target = node | |
super(TargetFinder, self).generic_visit(node) | |
def visit_arguments(self, node): | |
if node.args: | |
node.args = [ arg for arg in node.args if arg.id != 'self'] | |
super(TargetFinder, self).generic_visit(node) | |
def visit_If(self, node): | |
if node.orelse and isinstance(node.orelse[0], ast.Raise): | |
# don't raise Exception. it will return None | |
node.orelse=[] | |
super(TargetFinder, self).generic_visit(node) | |
def find(self, node): | |
self.visit(node) | |
return self.target | |
source=urllib.urlopen(YDL_YOUTUBE_IE_SOURCE).read() | |
tree=ast.parse(source) | |
function = TargetFinder().find(tree) | |
unparse.Unparser(function) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment