Skip to content

Instantly share code, notes, and snippets.

@glajchs
Created April 29, 2018 05:24
Show Gist options
  • Select an option

  • Save glajchs/c5f99abb08ad2a852347013fe6714b0a to your computer and use it in GitHub Desktop.

Select an option

Save glajchs/c5f99abb08ad2a852347013fe6714b0a to your computer and use it in GitHub Desktop.
Download any CS:GO replays that were "corrupt" on first attempt to download
#!/bin/bash
cd "${HOME}/.local/share/Steam/steamapps/common/Counter-Strike Global Offensive/csgo/replays"
declare -a REPLAY_INFO_FILES=(`find . -name "*.info" -type f`)
declare -a FILES_WITH_TIMES=()
SEPARATOR="-SEPARATOR-"
DOWNLOADS=0
# Find all files that need downloading, and prepend them with a sortable timestamp
for INFO_FILE in "${REPLAY_INFO_FILES[@]}"; do
if [ ! -e "${INFO_FILE%.info}" ]; then
FILES_WITH_TIMES+=("`stat -c %y ${INFO_FILE}` -SEPARATOR- ${INFO_FILE}")
fi
done
# Sort all the entries
IFS=$'\n' SORTED_FILES_WITH_TIMES=($(sort -r <<<"${FILES_WITH_TIMES[*]}"))
unset IFS
# Do the actual download work
for FILE_WITH_TIMESTAMP in "${SORTED_FILES_WITH_TIMES[@]}"; do
TIMESTAMP=`echo "${FILE_WITH_TIMESTAMP}" | sed -e 's/\(.*\) '${SEPARATOR}'.*/\1/g'`
INFO_FILE=`echo "${FILE_WITH_TIMESTAMP}" | sed -e 's/.*'${SEPARATOR}' \(.*\)/\1/g'`
DOWNLOAD_URL=`echo "${INFO_FILE}" | sed -e 's/\.\/match\([0-9]\+\)_\([0-9]\+_[0-9]\+\)_\([0-9]\+\).*/http:\/\/replay\3.valve.net\/\1\/\2.dem.bz2/g'`
DOWNLOADED_FILENAME=`echo "${DOWNLOAD_URL}" | sed -e 's/http:\/\/.*\/.*\/\(.*\)/\1/g'`
echo "Downloading match ${INFO_FILE%.info} played at `stat -c %y ${INFO_FILE}`"
# Download
wget --quiet "${DOWNLOAD_URL}"
# Unzip
bunzip2 "${DOWNLOADED_FILENAME}"
# Rename (so the CS:GO client knows about them)
mv "${DOWNLOADED_FILENAME%.bz2}" "${INFO_FILE%.info}"
DOWNLOADS=$((DOWNLOADS+1))
done
echo "Downloaded a total of ${DOWNLOADS} replays"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment