Skip to content

Instantly share code, notes, and snippets.

@scturtle
Created July 5, 2019 14:47
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scturtle/56882175dd9122358be64e71712138c9 to your computer and use it in GitHub Desktop.
Save scturtle/56882175dd9122358be64e71712138c9 to your computer and use it in GitHub Desktop.
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