Last active
June 9, 2025 00:40
-
-
Save bumbummen99/906336b0e4bba4e9be733c7d638e7eea to your computer and use it in GitHub Desktop.
Simple bash script to download screenshots from your Steam account.
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 characters
#!/bin/bash | |
print_progress() { | |
local current=$1 | |
local total=$2 | |
local width=40 | |
local percent=$(( 100 * current / total )) | |
local filled=$(( width * current / total )) | |
local empty=$(( width - filled )) | |
# Balken in Variablen bauen | |
local bar_filled=$(printf "%0.s█" $(seq 1 $filled)) | |
local bar_empty=$(printf "%0.s-" $(seq 1 $empty)) | |
# Kompletten Fortschrittsbalken in EINEM printf ausgeben | |
printf "\r[%s%s] %3d%% (%d/%d) " "$bar_filled" "$bar_empty" "$percent" "$current" "$total" | |
} | |
# Check if required arguments have been provided | |
if [[ $# -ne 2 ]]; then | |
# Show usage | |
echo "Usage: $0 <SteamID64> <API_KEY>" | |
exit 1 | |
fi | |
# Read the provided arguments | |
STEAMID="$1" | |
API_KEY="$2" | |
# Configuration | |
API_URL="https://api.steampowered.com/IPublishedFileService/GetUserFiles/v1/" | |
PER_PAGE=100 | |
# Working directory | |
BASE_DIR="./screenshots" | |
mkdir -p "$BASE_DIR" | |
page=1 | |
total="" | |
downloaded=0 | |
declare -A second_count | |
while [[ -z "$total" || $downloaded -lt $total ]]; do | |
echo "Retrieving page $page..." | |
# Query the Steam API | |
response=$(curl -s -G "$API_URL" \ | |
--data-urlencode "key=$API_KEY" \ | |
--data-urlencode "steamid=$STEAMID" \ | |
--data-urlencode "filetype=4" \ | |
--data-urlencode "numperpage=$PER_PAGE" \ | |
--data-urlencode "page=$page") | |
# Determine if the API query was successful | |
if [[ -z "$response" ]]; then | |
echo "Error querying the API" | |
exit 1 | |
fi | |
# Read the total amount and list of files from the API response | |
total=$(echo "$response" | jq '.response.total') | |
files=$(echo "$response" | jq -c '.response.publishedfiledetails[]') | |
# End loop in case no files are returned | |
if [[ "$files" == "" ]]; then | |
echo "No further screenshots found." | |
break | |
fi | |
# Get the amount of files in the current page | |
total_page=$(echo "$files" | jq -s 'length') | |
processed_page=0 | |
# Initialize the progress bar | |
print_progress "$processed_page" "$total_page" | |
# Process all retrieved files individually | |
while IFS= read -r file; do | |
url=$(echo "$file" | jq -r '.file_url') | |
appid=$(echo "$file" | jq -r '.consumer_appid') | |
created=$(echo "$file" | jq -r '.time_created') | |
timestamp=$(date -u -d @"$created" +"%Y%m%d%H%M%S") | |
second_key="${appid}_${timestamp}" | |
# Counter for multiple screenshots made at the same second | |
count=${second_count["$second_key"]} | |
count=$((count + 1)) | |
second_count["$second_key"]=$count | |
# Temporary file | |
tmpfile=$(mktemp) | |
wget -q -O "$tmpfile" "$url" | |
if [[ ! -s "$tmpfile" ]]; then | |
echo "Error downloading $url" | |
rm -f "$tmpfile" | |
continue | |
fi | |
mime=$(file --mime-type -b "$tmpfile") | |
case "$mime" in | |
image/jpeg) ext="jpg" ;; | |
image/png) ext="png" ;; | |
*) echo "Unknown MIME type: $mime"; rm -f "$tmpfile"; continue ;; | |
esac | |
outfile="$BASE_DIR/$STEAMID/$appid/${timestamp}_${count}.${ext}" | |
mkdir -p "$(dirname "$outfile")" | |
mv "$tmpfile" "$outfile" | |
# Set the modified timestamp | |
touch -d @"$created" "$outfile" | |
# Increase the downloaded count | |
downloaded=$((downloaded + 1)) | |
# Increase the page's file count | |
processed_page=$((processed_page + 1)) | |
# Draw the progress bar | |
print_progress "$processed_page" "$total_page" | |
done < <(echo "$files") | |
# Finish the progress bar | |
echo "" | |
# Set the page for the next iteration | |
page=$((page + 1)) | |
done | |
echo "Done: downloaded $downloaded screenshots." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment