Last active
September 6, 2024 15:53
-
-
Save smarteist/bdc2b3a9f3c74ad1b848355f6257c9d5 to your computer and use it in GitHub Desktop.
Revisions
-
smarteist revised this gist
Sep 6, 2024 . 1 changed file with 21 additions and 34 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,45 +6,32 @@ urls=( "https://example.com/file2.mp3" ) # Resumable downloader function download_file() { url="$1" fileName=$(basename "$url") # Fixed the missing closing parenthesis # Get the file size directly using curl's -I (HEAD request) and grep totalSize=$(curl -sI "$url" | grep -i Content-Length | awk '{print $2}' | tr -d '\r') [ -z "$totalSize" ] && totalSize="unknown" echo "File: $fileName | Total Size: $totalSize bytes" if [ -f "$fileName" ]; then from=$(stat -c%s "$fileName") echo "Resuming from byte $from..." curl -L --progress-bar -C $from -o "$fileName" "$url" else curl -L --progress-bar -o "$fileName" "$url" fi echo "Finished: $fileName" } # Download each file for url in "${urls[@]}"; do download_file "$url" echo done echo "All downloads complete." -
smarteist revised this gist
Sep 6, 2024 . 1 changed file with 34 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,27 +2,49 @@ # Define the list of URLs urls=( "https://example.com/file1.mkv" "https://example.com/file2.mp3" ) # Number of retries on failure RETRY_LIMIT=3 # Define the resumable downloader function download_file() { url="$1" fileName=$(basename "$url") retries=0 echo "Starting download: $fileName from $url" while [ $retries -lt $RETRY_LIMIT ]; do if [ -f "$fileName" ]; then from=$(stat -c%s "$fileName") echo "Resuming download from byte $from..." curl -L --progress-bar -C $from -o "$fileName" "$url" else curl -L --progress-bar -o "$fileName" "$url" fi if [ $? -eq 0 ]; then echo "Download finished: $fileName" return 0 else retries=$((retries + 1)) echo "Failed to download $fileName. Retrying ($retries/$RETRY_LIMIT)..." sleep 2 # Optional sleep before retrying fi done echo "Download failed after $RETRY_LIMIT attempts: $fileName" return 1 } # Iterate over the URLs and download the files (in parallel if needed) for url in "${urls[@]}"; do download_file "$url" & done # Wait for all background jobs to finish wait echo "All downloads complete." -
smarteist revised this gist
Feb 2, 2024 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,6 +3,7 @@ # Define the list of URLs urls=( "https://.mkv" "https://.mkv" ) # Define the resumable downloader function -
smarteist created this gist
Feb 2, 2024 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ #!/bin/bash # Define the list of URLs urls=( "https://.mkv" ) # Define the resumable downloader function download_file() { url="$1" fileName=$(basename "$url") if [ -f "$fileName" ]; then from=$(stat -c%s "$fileName") curl -L -C $from -o "$fileName" "$url" else curl -L -o "$fileName" "$url" fi echo "Download finished: $fileName" } # Iterate over the URLs and download the files for url in "${urls[@]}"; do download_file "$url" echo done