Created
April 6, 2024 20:18
-
-
Save lpenaud/7883d23887eb40367b1a592853032ce8 to your computer and use it in GitHub Desktop.
Export folder picture from flac
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| if [ $# -eq 0 ]; then | |
| printf "Usage: %s INDIR [...INDIRS]\n" "${0}" >&2 | |
| exit 1 | |
| fi | |
| # track | |
| function get_mimetype () { | |
| local line | |
| while read -e line; do | |
| if [[ "${line}" =~ ^[[:space:]]*MIME[[:space:]]type:[[:space:]](.*)$ ]]; then | |
| echo "${BASH_REMATCH[1]}" | |
| return 0 | |
| fi | |
| done < <(metaflac --list --block-type=PICTURE "${1}" | head) | |
| printf "The track '%s' haven't picture\n" "${1}" >&2 | |
| return 1 | |
| } | |
| # track | |
| function get_ext () { | |
| local mimetype="$(get_mimetype "${1}")" | |
| case "${mimetype}" in | |
| "image/jpeg") | |
| echo "jpg" | |
| ;; | |
| "image/png") | |
| echo "png" | |
| ;; | |
| *) | |
| printf "Unkown mimetype '%s' of '%s'\n" \ | |
| "${mimetype}" \ | |
| "${1}" >&2 | |
| return 1 | |
| ;; | |
| esac | |
| } | |
| # track | |
| function folder_picture () { | |
| local picture="$(dirname "${1}")/folder.$(get_ext "${1}")" | |
| printf "Extract picture from '%s' to '%s'\n" \ | |
| "${1}" \ | |
| "${picture}" | |
| metaflac --export-picture-to="${picture}" "${1}" | |
| } | |
| declare track | |
| while read -e track; do | |
| folder_picture "${track}" & | |
| done < <(find "${@}" -type f -name '01*.flac') | |
| wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment