Skip to content

Instantly share code, notes, and snippets.

@scturtle scturtle/c2a.py
Created Jul 5, 2019

Embed
What would you like to do?
curl to aria2
#!/usr/bin/env python
import sys
cmd = "aria2c --no-conf '{}'".format(sys.argv[2])
i = 3
while i < len(sys.argv):
arg = sys.argv[i]
i += 1
if arg == '-H':
arg = sys.argv[i]
i += 1
arg = arg.strip('"\'')
if arg.startswith('User-Agent: '):
user_agent = arg[len('User-Agent: '):]
cmd += " --user-agent='{}'".format(user_agent)
elif arg.startswith('Referer: '):
referer = arg[len('Referer: '):]
cmd += " --referer='{}'".format(referer)
elif arg.startswith('Range: '):
print('SKIP Range')
else:
cmd += " --header='{}'".format(arg)
elif arg == '--data':
assert False, "aria2c do not support post"
elif arg == '-u' or arg == '--user':
userpswd = sys.argv[i].split(':', 1)
i += 1
cmd += ' --http-user=' + userpswd[0]
cmd += ' --http-pswd=' + userpswd[1]
else:
print('UNKNOWN:', arg)
cmd += ' --all-proxy=http://127.0.0.1:1087 -c -x 5'
print(cmd)
print('if needed:', '--all-proxy=http://127.0.0.1:1087', '-c', '-x N -s N', '-o XX')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.