From 9373c998053fccff70e3cb26dff35c1253c89099 Mon Sep 17 00:00:00 2001 From: poni Date: Fri, 24 Nov 2023 15:40:21 +0100 Subject: [PATCH] first commit eheh --- radical_LS.sh | 196 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 radical_LS.sh diff --git a/radical_LS.sh b/radical_LS.sh new file mode 100644 index 0000000..084e9d5 --- /dev/null +++ b/radical_LS.sh @@ -0,0 +1,196 @@ +#!/bin/bash + +domain="http://localhost:5500" # Replace with your actual domain +main_folder="test_directory_not_elaborated" + +# Function to compress and generate HTML links +compress_and_generate_links() { + local folder="$1" + local compressed_folder="$folder/compressed" + mkdir -p "$compressed_folder" + + declare -a text_files + declare -a picture_files + declare -a video_files + declare -a audio_files + declare -a other_files + + for file in "$folder"/*; do + if [ -f "$file" ]; then + case "$file" in + *.txt|*.md|*.sh|*.html) + text_files+=("$file") + ;; + *.jpeg | *.jpg|*.png|*.gif|*.heic) + picture_files+=("$file") + ;; + *.mp4|*.mov|*.mkv|*.avi) + video_files+=("$file") + ;; + *.mp3|*.wav|*.flac|*.aiff) + audio_files+=("$file") + ;; + *index.html) # Exclude index.html files TODO spiegalo poi + continue + ;; + *) + other_files+=("$file") + ;; + esac + fi + done + + # Create index.html file + index_file="$folder/index.html" + echo " + + RADICAL LS! -> $folder + + + " > "$index_file" + + # Add link to parent folder at the top + parent_folder="$(dirname "$folder")" + echo "

" >> "$index_file" + + # Add links to subfolders with their names displayed + subfolders=() + for subfolder in "$folder"/*; do + if [ -d "$subfolder" ] && [ ! "$(basename "$subfolder")" == "compressed" ]; then + subfolder_name=$(basename "$subfolder") + subfolders+=("

$subfolder_name

") + fi + done + + if [ ${#subfolders[@]} -gt 0 ]; then + echo "" >> "$index_file" + for subfolder_link in "${subfolders[@]}"; do + echo "$subfolder_link" >> "$index_file" + done + fi + + echo "

$folder

" >> "$index_file" + + # Display text files in the subfolder + if [ ${#text_files[@]} -gt 0 ]; then + echo "
" >> "$index_file" + for text_file in "${text_files[@]}"; do + echo "
$text_file

" >> "$index_file" + done + echo "
" >> "$index_file" + fi + + # Compress and display picture files in the subfolder + if [ ${#picture_files[@]} -gt 0 ]; then + echo "
" >> "$index_file" + for picture_file in "${picture_files[@]}"; do + compressed_file="$compressed_folder/$(basename "$picture_file")_compressed.jpg" + if [ ! -f "$compressed_file" ]; then + convert "$picture_file" -resize 30% -dither Riemersma -colors 3 "$compressed_file" #TODO + fi + echo "
+ \"Compressed + Original ⇝ $picture_file +
" >> "$index_file" #TODO: fix here the not-compressed path + done + echo "
" >> "$index_file" + fi + + # Compress and display video files in the subfolder + if [ ${#video_files[@]} -gt 0 ]; then + echo "
" >> "$index_file" + for video_file in "${video_files[@]}"; do + compressed_file="$compressed_folder/$(basename "$video_file")_compressed.mp4" + if [ ! -f "$compressed_file" ]; then + ffmpeg -i "$video_file" -vf "scale=640:480" -c:v libx264 -crf 23 -c:a aac -strict experimental "$compressed_file" -y + fi + echo "
+ + Original ⇝ $video_file +
" >> "$index_file" + done + echo "
" >> "$index_file" + fi + + # Compress and display audio files in the subfolder + if [ ${#audio_files[@]} -gt 0 ]; then + echo "
" >> "$index_file" + for audio_file in "${audio_files[@]}"; do + compressed_file="$compressed_folder/$(basename "$audio_file")_compressed.mp3" + if [ ! -f "$compressed_file" ]; then + ffmpeg -i "$audio_file" -b:a 96k "$compressed_file" -y + fi + echo "
+ + Original ⇝ $audio_file +
" >> "$index_file" + done + echo "
" >> "$index_file" + fi + + # Display other files in the subfolder + if [ ${#other_files[@]} -gt 0 ]; then + echo "

Other Files:

" >> "$index_file" + fi + + # Close HTML tags + echo "
" >> "$index_file" +} + +# Function to iterate through all subfolders excluding "compressed" +function iterate_subfolders() { + local folder="$1" + + # Loop through each item in the folder + for item in "$folder"/*; do + # Check if the item is a directory + if [ -d "$item" ] && [ ! "$(basename "$item")" == "compressed" ] && [ ! "$(basename "$item")" == "*" ]; then + compress_and_generate_links "$item" + iterate_subfolders "$item" + echo "$item" + fi + done +} + + + +# Start iterating from the main folder +iterate_subfolders $main_folder + +echo "HTML files created for each subfolder." + + + + +# stuff: + +# imagemagick got different implementations called "delegates": +# "Delegates (built-in): bzlib fontconfig freetype gslib heic jng jp2 jpeg jxl lcms lqr ltdl lzma openexr png ps raw tiff webp xml zlib" +# you can configure it through a file called delegates.xml \ No newline at end of file