Compare commits

...

11 commits

Author SHA1 Message Date
Dragoon Dorise 73f38af040 snes 2024-05-10 00:02:59 +02:00
Dragoon Dorise b3af3ae4d4 genesis 2024-05-10 00:02:18 +02:00
Dragoon Dorise b027aaafe3 all systems but ps3 2024-05-10 00:00:31 +02:00
Dragoon Dorise cc58433b05 snes test 2024-05-09 23:57:47 +02:00
Dragoon Dorise d9d3a826e4 no ps3 2024-05-09 23:56:23 +02:00
Dragoon Dorise e78606b819 no ps3 2024-05-09 23:53:34 +02:00
Dragoon Dorise 3085288717 all games 2024-05-09 23:50:36 +02:00
Dragoon Dorise e79b1aff03 fixes [] 2024-05-09 23:48:16 +02:00
Dragoon Dorise 7c61546295 snes test 2024-05-09 23:36:13 +02:00
Dragoon Dorise 7810440101 using jq 2024-05-09 23:00:25 +02:00
Dragoon Dorise 007275f6c7 file count gamelist 2024-05-09 22:54:52 +02:00

View file

@ -1,61 +1,62 @@
#!/bin/bash
generateGameLists(){
generateGameLists() {
ROMS_DIR="$romsPath/snes"
ROMS_DIR="$romsPath"
# Initialize an empty array in JSON format
printf "["
JSON_OUTPUT="$HOME/emudeck/roms_games.json"
echo "[" > "$JSON_OUTPUT"
first_system=true
for system_dir in "$ROMS_DIR"/*; do
for system_dir in "$ROMS_DIR"*; do
if [[ -d "$system_dir" && -f "$system_dir/metadata.txt" ]]; then
# Ignore directories named "ps3"
if [[ "$system_dir" == *"/ps3" ]]; then
continue
fi
file_count=$(find "$system_dir" -type f | wc -l)
if [[ "$file_count" -le 2 ]]; then
continue # Skip this system_dir if there are 2 or fewer files
fi
collection=$(grep 'collection:' "$system_dir/metadata.txt" | cut -d ':' -f 2- | awk '{$1=$1};1')
shortname=$(grep 'shortname:' "$system_dir/metadata.txt" | cut -d ':' -f 2- | awk '{$1=$1};1')
extensions=$(grep 'extensions:' "$system_dir/metadata.txt" | cut -d ':' -f 2- | tr ',' '\n' | awk '{$1=$1};1' | tr '\n' '|')
launcher=$(grep 'launch:' "$system_dir/metadata.txt" | cut -d ':' -f 2- | awk '{$1=$1};1')
extensions="${extensions%|}" # Eliminar el último '|'
extensions=$(grep 'extensions:' "$system_dir/metadata.txt" | cut -d ':' -f 2- | tr ',' ' ' | awk '{$1=$1};1')
if $first_system; then
first_system=false
else
printf ","
fi
tmp_file="$(mktemp)"
# Start system object
printf '{ "title": "%s", "id": "%s", "launcher": "%s", "games": [' "$collection" "$shortname" "$launcher"
find "$system_dir" -type f | while read file_path; do
# Use jq to create the JSON objects for each game and print them directly
first_game=true
find "$system_dir" -type f | while read -r file_path; do
filename=$(basename "$file_path")
extension="${filename##*.}"
if [[ $extensions =~ (^|[|])${extension,,}([|]|$) ]]; then
name="${filename%.*}"
echo "{\"name\": \"$name\", \"filename\": \"$file_path\"}," >> "$tmp_file"
name="${filename%.*}"
if [[ "$extensions" =~ "$extension" ]]; then
if $first_game; then
first_game=false
else
printf ","
fi
jq -n --arg name "$name" --arg filename "$file_path" '{"name": $name, "filename": $filename}'
fi
done
# End games array and system object
printf "] }"
sort "$tmp_file" | sed '$ s/,$//' > "${tmp_file}_sorted"
mv "${tmp_file}_sorted" "$tmp_file"
if [[ -s "$tmp_file" ]]; then
echo " {" >> "$JSON_OUTPUT"
echo " \"title\": \"$collection\"," >> "$JSON_OUTPUT"
echo " \"id\": \"$shortname\"," >> "$JSON_OUTPUT"
echo " \"launcher\": \"$launcher\"," >> "$JSON_OUTPUT"
echo " \"games\": [" >> "$JSON_OUTPUT"
cat "$tmp_file" >> "$JSON_OUTPUT"
echo " ]" >> "$JSON_OUTPUT"
echo " }," >> "$JSON_OUTPUT"
fi
rm "$tmp_file"
fi
done
echo "]" >> "$JSON_OUTPUT"
sed -i '$ s/,$//' "$JSON_OUTPUT"
cat $JSON_OUTPUT
# End of JSON array
printf "]"
}