generated from nhcarrigan/template
fix: use null-safe while loop for filename handling in scripts
Security Scan and Upload / Security & DefectDojo Upload (pull_request) Successful in 49s
Security Scan and Upload / Security & DefectDojo Upload (pull_request) Successful in 49s
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
IFS=$'\n'
|
#!/bin/bash
|
||||||
|
|
||||||
# Initialize an empty string to hold the list of books in JSON-like format
|
# Initialize an empty string to hold the list of books in JSON-like format
|
||||||
books=""
|
books=""
|
||||||
@@ -7,15 +7,15 @@ echo "Found $filecount files."
|
|||||||
current=0
|
current=0
|
||||||
|
|
||||||
# Loop over each file found by find
|
# Loop over each file found by find
|
||||||
for file in $(find "/mnt/c/Users/accou/Documents/iDrive/Cloud-Drive_accounts@nhcarrigan.com/Books" -type f -print0 | tr '\0' '\n'); do
|
while IFS= read -r -d $'\0' file; do
|
||||||
current=$((current + 1))
|
current=$((current + 1))
|
||||||
echo -ne "Processing $current/$filecount\r"
|
echo -ne "Processing $current/$filecount\r"
|
||||||
title=$(exiftool "$file" | grep "^Title\s*:" | cut -d ":" -f 2 | sed -e 's/^[[:space:]]*//')
|
title=$(exiftool "$file" | grep "^Title\s*:" | cut -d ":" -f 2 | sed -e 's/^[[:space:]]*//')
|
||||||
author=$(exiftool "$file" | grep "^Creator\s*:" | cut -d ":" -f 2 | sed -e 's/^[[:space:]]*//')
|
author=$(exiftool "$file" | grep "^Creator\s*:" | cut -d ":" -f 2 | sed -e 's/^[[:space:]]*//')
|
||||||
|
|
||||||
if [ -z "$title" ]; then
|
if [ -z "$title" ]; then
|
||||||
# remove .mp3 from the title
|
# remove extension from the filename
|
||||||
title=$(basename "$file" | sed -e 's/\.*//g')
|
title=$(basename "$file" | sed -e 's/\.[^.]*$//')
|
||||||
fi
|
fi
|
||||||
if [ -z "$author" ]; then
|
if [ -z "$author" ]; then
|
||||||
author=$(exiftool "$file" | grep "^Author\s*:" | cut -d ":" -f 2 | sed -e 's/^[[:space:]]*//')
|
author=$(exiftool "$file" | grep "^Author\s*:" | cut -d ":" -f 2 | sed -e 's/^[[:space:]]*//')
|
||||||
@@ -26,11 +26,11 @@ for file in $(find "/mnt/c/Users/accou/Documents/iDrive/Cloud-Drive_accounts@nhc
|
|||||||
|
|
||||||
# use jq to add the book to the list
|
# use jq to add the book to the list
|
||||||
books="$books$(jq -n --arg title "$title" --arg author "$author" '{title: $title, author: $author}'),"
|
books="$books$(jq -n --arg title "$title" --arg author "$author" '{title: $title, author: $author}'),"
|
||||||
done
|
done < <(find "/mnt/c/Users/accou/Documents/iDrive/Cloud-Drive_accounts@nhcarrigan.com/Books" -type f -print0)
|
||||||
|
|
||||||
# Remove trailing comma and add square brackets to complete the list
|
# Remove trailing comma and add square brackets to complete the list
|
||||||
books="[${books%,}]"
|
books="[${books%,}]"
|
||||||
|
|
||||||
# Write to ./books/books.json
|
# Write to ./books/books.json
|
||||||
echo "$books" > ./books/books.json
|
echo "$books" > ./books/books.json
|
||||||
echo -ne "Done!\r"
|
echo -ne "Done!\r"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
IFS=$'\n'
|
#!/bin/bash
|
||||||
|
|
||||||
# Initialize an empty string to hold the list of songs in JSON-like format
|
# Initialize an empty string to hold the list of songs in JSON-like format
|
||||||
songs=""
|
songs=""
|
||||||
@@ -7,7 +7,7 @@ echo "Found $filecount files."
|
|||||||
current=0
|
current=0
|
||||||
|
|
||||||
# Loop over each file found by find
|
# Loop over each file found by find
|
||||||
for file in $(find "/mnt/c/Users/accou/Music" -type f -print0 | tr '\0' '\n'); do
|
while IFS= read -r -d $'\0' file; do
|
||||||
current=$((current + 1))
|
current=$((current + 1))
|
||||||
echo -ne "Processing $current/$filecount\r"
|
echo -ne "Processing $current/$filecount\r"
|
||||||
title=$(mid3v2 -l "$file" | grep "TIT2\|TT2" | cut -d "=" -f 2)
|
title=$(mid3v2 -l "$file" | grep "TIT2\|TT2" | cut -d "=" -f 2)
|
||||||
@@ -22,11 +22,11 @@ for file in $(find "/mnt/c/Users/accou/Music" -type f -print0 | tr '\0' '\n'); d
|
|||||||
|
|
||||||
# use jq to add the song to the list
|
# use jq to add the song to the list
|
||||||
songs="$songs$(jq -n --arg title "$title" --arg artist "$artist" '{title: $title, artist: $artist}'),"
|
songs="$songs$(jq -n --arg title "$title" --arg artist "$artist" '{title: $title, artist: $artist}'),"
|
||||||
done
|
done < <(find "/mnt/c/Users/accou/Music" -type f -print0)
|
||||||
|
|
||||||
# Remove trailing comma and add square brackets to complete the list
|
# Remove trailing comma and add square brackets to complete the list
|
||||||
songs="[${songs%,}]"
|
songs="[${songs%,}]"
|
||||||
|
|
||||||
# Write to ./music/songs.json
|
# Write to ./music/songs.json
|
||||||
echo "$songs" > ./music/songs.json
|
echo "$songs" > ./music/songs.json
|
||||||
echo -ne "Done!\r"
|
echo -ne "Done!\r"
|
||||||
|
|||||||
Reference in New Issue
Block a user