Created
August 17, 2024 19:52
-
-
Save SamadiPour/a719ad5bd481aa9fb6d1bf75b4d33421 to your computer and use it in GitHub Desktop.
A bash script for retrying the failed tasks in Aria2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ARIA_URL="http://127.0.0.1:6800/jsonrpc" | |
SECRET="secret" | |
# Step 1: Retrieve GIDs of failed downloads | |
response=$(curl -s -X POST $ARIA_URL \ | |
-H "Content-Type: application/json" \ | |
-d '{ | |
"jsonrpc": "2.0", | |
"id": 1, | |
"method": "aria2.tellStopped", | |
"params": ["token:'"$SECRET"'", 0, 1000] | |
}') | |
# Check if success | |
if [ $? -ne 0 ]; then | |
echo "Failed to retrieve GIDs of failed downloads" | |
exit 1 | |
fi | |
# Loop through each GID and retry the download | |
lenght=$(echo "$response" | jq -r '.result | length') | |
for ((i = 0; i < $lenght; i++)); do | |
GID=$(echo "$response" | jq -r '.result['"$i"'].gid') | |
URL=$(echo "$response" | jq -r '.result['"$i"'].files[0].uris[0].uri') | |
STATUS=$(echo "$response" | jq -r '.result['"$i"'].status') | |
if [ "$STATUS" != "error" ]; then | |
echo "Skipping: $GID $URL $STATUS" | |
continue | |
fi | |
echo "Retrying: $GID $URL $STATUS" | |
task_status=$(curl -s -X POST $ARIA_URL \ | |
-H 'Content-Type: application/json' \ | |
-d '{ | |
"jsonrpc": "2.0", | |
"id": 2, | |
"method": "system.multicall", | |
"params": [[{"methodName":"aria2.tellStatus","params":["token:'"$SECRET"'","'"$GID"'"]},{"methodName":"aria2.getOption","params":["token:'"$SECRET"'","'"$GID"'"]}]] | |
}') | |
params=$(echo $task_status | jq -c '.result[1][0]') | |
# Remove the failed download result | |
curl -s -X POST $ARIA_URL \ | |
-H "Content-Type: application/json" \ | |
-d '{ | |
"jsonrpc": "2.0", | |
"id": 2, | |
"method": "aria2.removeDownloadResult", | |
"params": ["token:'"$SECRET"'", "'"$GID"'"] | |
}' | |
# Re-add the download | |
curl -s -X POST $ARIA_URL \ | |
-H "Content-Type: application/json" \ | |
-d '{ | |
"jsonrpc": "2.0", | |
"id": 3, | |
"method": "aria2.addUri", | |
"params": ["token:'"$SECRET"'",["'"$URL"'"],'"$params"'] | |
}' | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cronjob for starting at 2:02 and ending at 7:58
Cronjob for retrying failed ones every 10 minutes from 2:00 to 8:00