-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcurl2aria2c
executable file
·50 lines (48 loc) · 1.24 KB
/
curl2aria2c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env bash
#
# NAME
#
# curl2aria2c - convert a cURL command into an aria2c command
#
# SYNOPSIS
#
# curl2aria2c <cURL args>...
#
# DESCRIPTION
#
# curl2aria2ac converts a cURL command into an equivalent aria2c
# command and executes it. The options supported currently are:
#
# -H <header>
# --cookie <cookie>
# --output <file>
#
# These are the main options that Firefox's "Copy as cURL" feature
# produces.
#
# DEPENDENCIES
#
# aria2c(1)
#
args=( "--continue" "--http-accept-gzip" )
while [[ "$1" ]]
do
case "$1" in
# Ignore "range" header. aria2c will want to
# request custom ranges anyway.
-H) shift
[[ $1 =~ ^[rR]ange: ]] || args+=( "--header" "$1" ) ;;
--output) args+=( "--out" ) ;;
# These options don't have aria2c equivalents. They were
# procured from curl.js available at:
# https://hg.mozilla.org/mozilla-central/file/tip/devtools/client/shared/curl.js
--globoff|--data-*|-I|-X)
[[ "$1" =~ --data ]] && shift
echo >&2 "${0##*/}: option $1 ignored" ;;
--cookie)
shift; args+=( --header="Cookie:$1" ) ;;
*) args+=( "$1" ) ;;
esac
shift
done
exec aria2c "${args[@]}"