From b55e619441e5ee63e28f933ada18b126badbf744 Mon Sep 17 00:00:00 2001 From: Viktor Stanchev Date: Wed, 15 Apr 2015 15:41:02 -0400 Subject: [PATCH] fix command execution vlun when using -C or openCommand, close #46 --- pirate-get.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pirate-get.py b/pirate-get.py index 5bf5c50..97126e0 100755 --- a/pirate-get.py +++ b/pirate-get.py @@ -113,6 +113,13 @@ class NoRedirection(request.HTTPErrorProcessor): https_response = http_response +cmd_args_regex = '''(('[^']*'|"[^"]*"|(\\\\\\s|[^\\s])+)+ *)''' +def parse_cmd(cmd, url): + ret = re.findall(cmd_args_regex, cmd) + ret2 = list(map(lambda x: x[0].strip(), ret)) + ret3 = list(map(lambda x: x.replace('%s', url), ret2)) + return ret3 + # create a subclass and override the handler methods class BayParser(HTMLParser): title = '' @@ -489,7 +496,6 @@ def main(): action='store_true', help='open magnets with transmission-remote') parser.add_argument('-C', '--custom', dest='command', - action='store_true', help='open magnets with a custom command' ' (%%s will be replaced with the url)') parser.add_argument('-M', '--save-magnets', @@ -675,7 +681,7 @@ def main(): command = config.get('Misc', 'openCommand') if args.command: command = args.command - os.system(command % url) + subprocess.call(parse_cmd(command, url), shell=False) else: webbrowser.open(url)