Skip to content

Commit

Permalink
Fix scraper database
Browse files Browse the repository at this point in the history
After renaming Emu labels Scraper didn't create its database anymore.
It was due to \n presence in Emus/show.json
  • Loading branch information
cizia64 committed Jul 16, 2024
1 parent ca7c9bf commit cf79e1a
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ for dir in /mnt/SDCARD/Emus/*/; do
echo "Skipping $folder_name"
continue
fi

config_file="${dir}config.json"
if [ -f "$config_file" ]; then
# Retrieve the trimui_name_full_EU from the database
trimui_name_full_EU=$(sqlite3 "$db_path" "SELECT trimui_name_full_EU FROM systems WHERE crossmix_foldername = '$folder_name'")
trimui_name_full_EU=$(sqlite3 "$db_path" "SELECT trimui_name_full_EU FROM systems WHERE crossmix_foldername = '$folder_name' LIMIT 1")
if [ -n "$trimui_name_full_EU" ]; then
# Update the label value in the JSON file
/mnt/SDCARD/System/bin/jq --arg new_label "$trimui_name_full_EU" '.label = $new_label' "$config_file" >/tmp/tmp_config.json && mv /tmp/tmp_config.json "$config_file"
Expand All @@ -44,5 +45,5 @@ fi

/mnt/SDCARD/System/usr/trimui/scripts/mainui_state_update.sh "EMULATOR LABELS" "$script_name"

# Labels has changed so the Emulator selection must be done again:
# Labels have changed so the Emulator selection must be done again:
/mnt/SDCARD/Apps/EmuCleaner/launch.sh -s
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ for dir in /mnt/SDCARD/Emus/*/; do
config_file="${dir}config.json"
if [ -f "$config_file" ]; then
# Retrieve the trimui_name_full_US from the database
trimui_name_full_US=$(sqlite3 "$db_path" "SELECT trimui_name_full_US FROM systems WHERE crossmix_foldername = '$folder_name'")
trimui_name_full_US=$(sqlite3 "$db_path" "SELECT trimui_name_full_US FROM systems WHERE crossmix_foldername = '$folder_name' LIMIT 1")
if [ -n "$trimui_name_full_US" ]; then
# Update the label value in the JSON file
/mnt/SDCARD/System/bin/jq --arg new_label "$trimui_name_full_US" '.label = $new_label' "$config_file" > /tmp/tmp_config.json && mv /tmp/tmp_config.json "$config_file"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ for dir in /mnt/SDCARD/Emus/*/; do
config_file="${dir}config.json"
if [ -f "$config_file" ]; then
# Retrieve the trimui_name_short_EU from the database
trimui_name_short_EU=$(sqlite3 "$db_path" "SELECT trimui_name_short_EU FROM systems WHERE crossmix_foldername = '$folder_name'")
trimui_name_short_EU=$(sqlite3 "$db_path" "SELECT trimui_name_short_EU FROM systems WHERE crossmix_foldername = '$folder_name' LIMIT 1")
if [ -n "$trimui_name_short_EU" ]; then
# Update the label value in the JSON file
/mnt/SDCARD/System/bin/jq --arg new_label "$trimui_name_short_EU" '.label = $new_label' "$config_file" > /tmp/tmp_config.json && mv /tmp/tmp_config.json "$config_file"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ for dir in /mnt/SDCARD/Emus/*/; do
config_file="${dir}config.json"
if [ -f "$config_file" ]; then
# Retrieve the trimui_name_short_US from the database
trimui_name_short_US=$(sqlite3 "$db_path" "SELECT trimui_name_short_US FROM systems WHERE crossmix_foldername = '$folder_name'")
trimui_name_short_US=$(sqlite3 "$db_path" "SELECT trimui_name_short_US FROM systems WHERE crossmix_foldername = '$folder_name' LIMIT 1")
if [ -n "$trimui_name_short_US" ]; then
# Update the label value in the JSON file
/mnt/SDCARD/System/bin/jq --arg new_label "$trimui_name_short_US" '.label = $new_label' "$config_file" > /tmp/tmp_config.json && mv /tmp/tmp_config.json "$config_file"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,28 @@ script_name=$(basename "$0" .sh)
# Path to the SQLite database
db_path="/mnt/SDCARD/System/usr/trimui/scripts/emulators_list.db"

# Iterate over all config.json files in /mnt/SDCARD/Emus/ and set the label from the database
find /mnt/SDCARD/Emus/ -type d -exec sh -c '
for dir do
# Iterate over all directories in /mnt/SDCARD/Emus/
for dir in /mnt/SDCARD/Emus/*/; do
folder_name=$(basename "$dir")
# Skip directories starting with an underscore
if [[ "$folder_name" == _* ]]; then
echo "Skipping $folder_name"
continue
fi

config_file="$dir/config.json"
if [ -f "$config_file" ]; then
folder_name=$(basename "$dir")
# Retrieve the crossmix_name from the database
crossmix_name=$(sqlite3 '"$db_path"' "SELECT crossmix_name FROM systems WHERE crossmix_foldername = \"$folder_name\"")
if [ -n "$crossmix_name" ]; then
# Update the label value in the JSON file
/mnt/SDCARD/System/bin/jq --arg new_label "$crossmix_name" ".label = \$new_label" "$config_file" > /tmp/tmp_config.json && mv /tmp/tmp_config.json "$config_file"
echo "Updated label in $folder_name to $crossmix_name"
else
echo "No crossmix_name found for folder $folder_name"
fi
config_file="${dir}config.json"
if [ -f "$config_file" ]; then
# Retrieve the crossmix_name from the database
crossmix_name=$(sqlite3 "$db_path" "SELECT crossmix_name FROM systems WHERE crossmix_foldername = '$folder_name' LIMIT 1")
if [ -n "$crossmix_name" ]; then
# Update the label value in the JSON file
/mnt/SDCARD/System/bin/jq --arg new_label "$crossmix_name" '.label = $new_label' "$config_file" >/tmp/tmp_config.json && mv /tmp/tmp_config.json "$config_file"
echo "Updated label in $folder_name to \"$crossmix_name\""
else
echo "No crossmix_name found for folder $folder_name"
fi
done
' sh {} +
fi
done

# Check for the existence of crossmix.json and update it
json_file="/mnt/SDCARD/System/etc/crossmix.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ for dir in /mnt/SDCARD/Emus/*/; do

config_file="${dir}config.json"
if [ -f "$config_file" ]; then
# Retrieve the manufacturer and trimui_name_short_US from the database
manufacturer=$(sqlite3 "$db_path" "SELECT manufacturer FROM systems WHERE crossmix_foldername = '$folder_name'")
trimui_name_short_US=$(sqlite3 "$db_path" "SELECT trimui_name_short_EU FROM systems WHERE crossmix_foldername = '$folder_name'")
if [ -n "$manufacturer" ] && [ -n "$trimui_name_short_US" ]; then
# Retrieve the manufacturer and trimui_name_short_EU from the database
manufacturer=$(sqlite3 "$db_path" "SELECT manufacturer FROM systems WHERE crossmix_foldername = '$folder_name' LIMIT 1")
trimui_name_short_EU=$(sqlite3 "$db_path" "SELECT trimui_name_short_EU FROM systems WHERE crossmix_foldername = '$folder_name' LIMIT 1")
if [ -n "$manufacturer" ] && [ -n "$trimui_name_short_EU" ]; then
# Construct the crossmix_name
first_three_letters=$(echo "$manufacturer" | cut -c1-3)
crossmix_name="$first_three_letters. $trimui_name_short_US"
crossmix_name="$first_three_letters. $trimui_name_short_EU"
# Update the label value in the JSON file
/mnt/SDCARD/System/bin/jq --arg new_label "$crossmix_name" '.label = $new_label' "$config_file" > /tmp/tmp_config.json && mv /tmp/tmp_config.json "$config_file"
echo "Updated label in $folder_name to \"$crossmix_name\""
else
echo "No manufacturer or trimui_name_short_US found for folder $folder_name"
echo "No manufacturer or trimui_name_short_EU found for folder $folder_name"
fi
fi
done
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ for dir in /mnt/SDCARD/Emus/*/; do
config_file="${dir}config.json"
if [ -f "$config_file" ]; then
# Retrieve the manufacturer and trimui_name_short_US from the database
manufacturer=$(sqlite3 "$db_path" "SELECT manufacturer FROM systems WHERE crossmix_foldername = '$folder_name'")
trimui_name_short_US=$(sqlite3 "$db_path" "SELECT trimui_name_short_US FROM systems WHERE crossmix_foldername = '$folder_name'")
manufacturer=$(sqlite3 "$db_path" "SELECT manufacturer FROM systems WHERE crossmix_foldername = '$folder_name' LIMIT 1")
trimui_name_short_US=$(sqlite3 "$db_path" "SELECT trimui_name_short_US FROM systems WHERE crossmix_foldername = '$folder_name' LIMIT 1")
if [ -n "$manufacturer" ] && [ -n "$trimui_name_short_US" ]; then
# Construct the crossmix_name
first_three_letters=$(echo "$manufacturer" | cut -c1-3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ for dir in /mnt/SDCARD/Emus/*/; do
config_file="${dir}config.json"
if [ -f "$config_file" ]; then
# Check if the folder is in the database
crossmix_name=$(sqlite3 "$db_path" "SELECT crossmix_name FROM systems WHERE crossmix_foldername = '$folder_name'")
crossmix_name=$(sqlite3 "$db_path" "SELECT crossmix_name FROM systems WHERE crossmix_foldername = '$folder_name' LIMIT 1")
if [ -n "$crossmix_name" ]; then
# Generate a string with the current number of spaces
spaces=$(printf "%*s" $counter "")
Expand Down
Binary file modified System/usr/trimui/scripts/emulators_list.db
Binary file not shown.

0 comments on commit cf79e1a

Please sign in to comment.