From 61b3e4e7d2ed489b821b64d292d144784d81e466 Mon Sep 17 00:00:00 2001 From: bin456789 Date: Thu, 6 Mar 2025 20:45:29 +0800 Subject: [PATCH] =?UTF-8?q?core:=20=E6=94=AF=E6=8C=81=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8D=E4=BD=BF=E7=94=A8=20metalink=20?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E7=9A=84=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- trans.sh | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/trans.sh b/trans.sh index d587d12..c742bb1 100644 --- a/trans.sh +++ b/trans.sh @@ -161,24 +161,9 @@ download() { # 有ipv4地址无ipv4网关的情况下,aria2可能会用ipv4下载,而不是ipv6 # axel 在 lightsail 上会占用大量cpu - # aria2 下载 fedora 官方镜像链接会将meta4文件下载下来,而且占用了指定文件名,造成重命名失效。而且无法指定目录 # https://download.opensuse.org/distribution/leap/15.5/appliances/openSUSE-Leap-15.5-Minimal-VM.x86_64-kvm-and-xen.qcow2 # https://aria2.github.io/manual/en/html/aria2c.html#cmdoption-o - # 构造 aria2 参数 - save= - # 文件夹 - if [[ "$path" = '/*' ]]; then - save="$save -d /" - fi - # 文件名 - if [ -n "$path" ]; then - case "$(get_url_type "$url")" in - http) save="$save -o $path" ;; - bt) save="$save -O 1=$path" ;; - esac - fi - # 阿里云源限速,而且检测 user-agent 禁止 axel/aria2 下载 # aria2 默认 --max-tries 5 @@ -205,7 +190,20 @@ download() { url=$torrent fi - aria2c $save "$url" + # -o 设置 http 下载文件名 + # -O 设置 bt 首个文件的文件名 + aria2c "$url" \ + -d "$(dirname "$path")" \ + -o "$(basename "$path")" \ + -O "1=$(basename "$path")" + + # opensuse 官方镜像支持 metalink + # aira2 无法重命名用 metalink 下载的文件 + # 需用以下方法重命名 + if head -c 1024 "$path" | grep -Fq 'urn:ietf:params:xml:ns:metalink'; then + real_file=$(tr -d '\n' <"$path" | sed -E 's|.*