Skip to content

Commit

Permalink
Fix URL filename extraction in mods_downloader.sh (#262)
Browse files Browse the repository at this point in the history
* Gets the filename from the server headers (content-disposition: filename)
* Fallback to extracting using basename by removing the query parameter(s)
  • Loading branch information
msansen authored Aug 4, 2024
1 parent 35e7994 commit 69e5b0a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions scripts/Mods/mods_downloader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ IFS=', ' read -r -a urls <<< "$MODS_URLS"

# Iterate over the URLs and download/extract/copy each file
for url in "${urls[@]}"; do
# Extract filename from URL
filename=$(basename "$url")
# Extract filename from the server
filename=$(curl -sIL "$url" | grep -i -o -E 'content-disposition:.*filename="?([^"]*)"?' | sed -E 's/.*filename="?([^"]*)"?/\1/')

# Fallback to extracting from URL if necessary
if [ -z "$filename" ]; then
filename=$(basename "${url%%\?*}")
fi

# Download the file
echo "INFO: Downloading $filename from $url..."
Expand Down

0 comments on commit 69e5b0a

Please sign in to comment.