Feature #396 » genid3db.sh
| 1 |
#!/bin/bash
|
|---|---|
| 2 |
# Generate a database of JSON data from ID3 tags extracted from MP3 files.
|
| 3 |
# This includes extracting the cover art and associating it with the JSON data.
|
| 4 |
# --------------------------------------------------------------------------------
|
| 5 |
|
| 6 |
lib=".musiclib" |
| 7 |
coverart="${lib}/coverart" |
| 8 |
mkdir -p "${coverart}" |
| 9 |
|
| 10 |
find . -iname "*.mp3" | while read file; do |
| 11 |
|
| 12 |
echo "Processing ${file}" |
| 13 |
|
| 14 |
# Get a UUID to uniquely identify the song.
|
| 15 |
uuid=$(uuidgen) |
| 16 |
|
| 17 |
# Extract Cover Art, if any.
|
| 18 |
ffmpeg -i "${file}" "${coverart}/${uuid}.png" 2>/dev/null |
| 19 |
|
| 20 |
# Extract ID3 data
|
| 21 |
ffprobe -show_format -show_streams -print_format json "${file}" 2>/dev/null | jq .format.tags > ${lib}/${uuid}.json |
| 22 |
|
| 23 |
# Add the filename and covert art file to the extracted ID3 data.
|
| 24 |
cat ${lib}/${uuid}.json | jq --arg file "${file}" '. + {file: $file}' > ${lib}/${uuid}.2 |
| 25 |
mv ${lib}/${uuid}.2 ${lib}/${uuid}.json |
| 26 |
cat ${lib}/${uuid}.json | jq --arg coverart "${uuid}.png" '. + {coverart: $coverart}' > ${lib}/${uuid}.2 |
| 27 |
mv ${lib}/${uuid}.2 ${lib}/${uuid}.json |
| 28 |
|
| 29 |
done
|
| 30 |
|
| 31 |
# ls -l ${coverart}
|
| 32 |
# sleep 5
|
| 33 |
# cat ${lib}/*.json
|
- « Previous
- 1
- 2
- Next »