generated from nhcarrigan/template
37 lines
1.4 KiB
Bash
Executable File
37 lines
1.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Initialize an empty string to hold the list of books in JSON-like format
|
|
books=""
|
|
filecount=$(find "/mnt/c/Users/accou/Documents/iDrive/Cloud-Drive_accounts@nhcarrigan.com/Books" -type f | wc -l)
|
|
echo "Found $filecount files."
|
|
current=0
|
|
|
|
# Loop over each file found by find
|
|
while IFS= read -r -d $'\0' file; do
|
|
current=$((current + 1))
|
|
echo -ne "Processing $current/$filecount\r"
|
|
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:]]*//')
|
|
|
|
if [ -z "$title" ]; then
|
|
# remove extension from the filename
|
|
title=$(basename "$file" | sed -e 's/\.[^.]*$//')
|
|
fi
|
|
if [ -z "$author" ]; then
|
|
author=$(exiftool "$file" | grep "^Author\s*:" | cut -d ":" -f 2 | sed -e 's/^[[:space:]]*//')
|
|
fi
|
|
if [ -z "$author" ]; then
|
|
author="Unknown Author"
|
|
fi
|
|
|
|
# use jq to add the book to the list
|
|
books="$books$(jq -n --arg title "$title" --arg author "$author" '{title: $title, author: $author}'),"
|
|
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
|
|
books="[${books%,}]"
|
|
|
|
# Write to ./books/books.json
|
|
echo "$books" > ./books/books.json
|
|
echo -ne "Done!\r"
|