From d307c3b80bedec00d74a91ff38dc81cdebbfa4d4 Mon Sep 17 00:00:00 2001 From: daxid <david.rouquet@tetras-libre.fr> Date: Sun, 12 Jan 2025 11:32:43 +0100 Subject: [PATCH] new media extraction --- ...PRECATED_extract_all_media_from_folder.sh} | 0 .../script/postEditJpexsFlashExtraction.sh | 67 +++++++++++++++++++ 2 files changed, 67 insertions(+) rename tetras_extraction/script/{extract_all_media_from_folder.sh => DEPRECATED_extract_all_media_from_folder.sh} (100%) create mode 100644 tetras_extraction/script/postEditJpexsFlashExtraction.sh diff --git a/tetras_extraction/script/extract_all_media_from_folder.sh b/tetras_extraction/script/DEPRECATED_extract_all_media_from_folder.sh similarity index 100% rename from tetras_extraction/script/extract_all_media_from_folder.sh rename to tetras_extraction/script/DEPRECATED_extract_all_media_from_folder.sh diff --git a/tetras_extraction/script/postEditJpexsFlashExtraction.sh b/tetras_extraction/script/postEditJpexsFlashExtraction.sh new file mode 100644 index 0000000..babf071 --- /dev/null +++ b/tetras_extraction/script/postEditJpexsFlashExtraction.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +# Check if the correct number of arguments is provided +if [ "$#" -ne 2 ]; then + echo "Usage: $0 <source_folder> <destination_folder>" + exit 1 +fi + +SOURCE_FOLDER=$1 +DESTINATION_FOLDER=$2 + +# Check if source folder exists +if [ ! -d "$SOURCE_FOLDER" ]; then + echo "Error: Source folder does not exist." + exit 1 +fi + +# Create destination folder if it doesn't exist +mkdir -p "$DESTINATION_FOLDER" + +# Copy contents of source folder to destination folder +cp -r "$SOURCE_FOLDER"/* "$DESTINATION_FOLDER"/ + +# Iterate over level 1 files and folders in the destination folder +for item in "$DESTINATION_FOLDER"/*; do + # Check if the item has the .swf suffix + if [[ "$item" == *.swf ]]; then + # Remove the .swf suffix + new_item="${item%.swf}" + mv "$item" "$new_item" + item="$new_item" + fi + + # If the item is a directory, check for a "sounds" subfolder + if [ -d "$item" ]; then + SOUNDS_FOLDER="$item/sounds" + if [ -d "$SOUNDS_FOLDER" ]; then + # Move all files from "sounds" to the parent directory + mv "$SOUNDS_FOLDER"/* "$item"/ + # Remove the "sounds" folder + rmdir "$SOUNDS_FOLDER" + fi + + # Check the number of files in the folder + file_count=$(find "$item" -maxdepth 1 -type f | wc -l) + if [ "$file_count" -eq 1 ]; then + # Get the file name and extension + file_path=$(find "$item" -maxdepth 1 -type f) + file_extension="${file_path##*.}" + folder_name=$(basename "$item") + new_file_name="$item/${folder_name}_01.$file_extension" + mv "$file_path" "$new_file_name" + elif [ "$file_count" -gt 1 ]; then + # Remove the prefix before _ and replace "son " with parent folder name + _0 + folder_name=$(basename "$item") + for file in "$item"/*; do + if [[ $(basename "$file") == *_* ]]; then + base_name=$(basename "$file") + new_base_name=$(echo "$base_name" | sed "s/^.*_//; s/^son/${folder_name}_0/") + mv "$file" "$item/$new_base_name" + fi + done + fi + fi +done + +echo "Copy, rename, and reorganization operation completed successfully." -- GitLab