tasks now uses steam api to get game name

This commit is contained in:
Danilo Reyes 2025-01-25 16:54:10 -06:00
parent 091303fc88
commit 5bf5161d93

View File

@ -1,5 +1,5 @@
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p bash trashy fd ripgrep file
#! nix-shell -i bash -p bash trashy fd ripgrep file jq
directories=("$HOME/Pictures/To Organize/" "$HOME/Downloads/" "$HOME/Downloads/cache")
@ -66,30 +66,42 @@ fi
# Where steam screenshots are stored, may need to replace with ur ID
dir_steam=$XDG_DATA_HOME/Steam/userdata/107446271/760/remote
declare -A games
# Insert here new games, put between [] the ID of the game
# You can find it by visiting the $dir_steam directory
# the ID is simply the name of the folder in there.
games+=(
[386360]=Smite
[960090]="Bloons Tower Defense 6"
[648800]=Raft
[262060]="Darkest Dungeon"
[234140]="Mad Max"
[433340]="Slime Rancher"
[1190460]="Death Stranding"
[1850570]="Death Stranding"
[440900]="Conan Exiles"
[679110]="Werewolf Apocalypse"
[2221490]="The Division 2"
)
cache_file="$dir_steam/game_cache"
if ! [[ -f $cache_file ]]; then
echo "creating games database"
touch "$cache_file"
fi
for key in "${!games[@]}"; do
fetch_game_name() {
local game_id
game_id=$1
local cache_entry
cache_entry=$(grep "^$game_id," "$cache_file")
if [ -n "$cache_entry" ]; then
echo "$cache_entry" | cut -d ',' -f2-
else
local response
response=$(curl -s "https://store.steampowered.com/api/appdetails?appids=${game_id}")
local game_name
game_name=$(echo "$response" | jq -r ".\"${game_id}\".data.name")
if [ -n "$game_name" ]; then
echo "$game_id,$game_name" >>"$cache_file"
echo "$game_name"
else
echo "error finding game $game_id"
fi
fi
}
while IFS= read -r game_dir; do
game_id=$(basename "$game_dir")
game_name=$(fetch_game_name "$game_id")
# Modify this to store your screenshots somewhere else
dir_dest=$(realpath "$HOME/Pictures/Screenshots/Games")/${games[$key]}
dir_game=$(realpath "$dir_steam")/$key/screenshots
dir_dest=$(realpath "$HOME/Pictures/Screenshots/Games")/"$game_name"
dir_game=$(realpath "$dir_steam")/"$game_id"/screenshots
# If there are not screenshots currently stored, why bother lol
if ! [[ -d $dir_game ]]; then #
if ! [[ -d $dir_game ]]; then
continue
fi
# If screenshots exist however...
@ -98,14 +110,8 @@ for key in "${!games[@]}"; do
fi
# Create destination directory
mkdir -vp "$dir_dest"
echo "Moving ${games[$key]} screenshots..."
fd . "$dir_game" -d 1 -tf -x mv -n {} "$dir_dest"/
# Delete thumnnails
echo "Deleting ${games[$key]} thumbnails..."
rm -rf "$dir_game"/thumbnails
done
# Clearing up empty directories
fd . "$dir_steam" -td -te -x trash {}
fd . "$dir_game" -d 1 -tf -x cp -n {} "$dir_dest"/
done < <(fd . "$dir_steam" -td --max-depth 1 --absolute-path)
cyberpunk_dir=$HOME/Games/gog/cyberpunk-2077/drive_c/users/jawz/Pictures/"Cyberpunk 2077"
if [[ -d $cyberpunk_dir ]]; then
@ -117,13 +123,17 @@ fi
proton_dir=$HOME/.steam/steam/compatibilitytools.d
if [[ -d "$proton_dir" ]]; then
while IFS= read -r protonver; do
lutrisdir=$XDG_DATA_HOME/lutris/runners/wine/$(basename "$protonver")
while IFS= read -r proton_version; do
proton_name=$(basename "$proton_version")
if [ "$proton_name" == "LegacyRuntime" ]; then
continue
fi
lutrisdir=$XDG_DATA_HOME/lutris/runners/wine/"$proton_name"
if [ -d "$lutrisdir" ] && [ -L "$lutrisdir" ]; then
continue
fi
echo "Symlink $lutrisdir doesn't exist, creating link..."
ln -s "$(realpath "$protonver")"/files "$lutrisdir"
ln -s "$(realpath "$proton_version")"/files "$lutrisdir"
done < <(fd . "$proton_dir" -d 1 -td)
fi
fd . "$XDG_DATA_HOME/lutris/runners/wine" -d1 -tl -Lx trash {}