2016-10-07 18:16:45 +02:00
|
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
|
|
# Rename Guillaume Meurice podcast files
|
|
|
|
|
# Also change the title tag (2016.09.30 Title)
|
|
|
|
|
# http://radiofrance-podcast.net/podcast09/rss_14257.xml
|
|
|
|
|
|
2016-11-02 10:22:07 +01:00
|
|
|
|
# If the first arg is a directory
|
|
|
|
|
if [ -d "${1}" ]; then
|
2016-10-07 18:16:45 +02:00
|
|
|
|
|
2016-11-02 10:22:07 +01:00
|
|
|
|
MEURICE_DIR="${1}"
|
|
|
|
|
TMP_LIST_FILE="/tmp/list_meurice_file"
|
2016-10-07 18:16:45 +02:00
|
|
|
|
|
2016-11-02 10:22:07 +01:00
|
|
|
|
# List audio files
|
|
|
|
|
find "${MEURICE_DIR}" -mindepth 1 -type f -iregex '.*\.mp3' > "${TMP_LIST_FILE}"
|
2016-10-07 18:16:45 +02:00
|
|
|
|
|
2016-11-02 10:22:07 +01:00
|
|
|
|
while IFS= read -r FILE
|
|
|
|
|
do
|
|
|
|
|
|
|
|
|
|
FILE_ABSOLUT_PATH="${MEURICE_DIR}/${FILE}"
|
|
|
|
|
|
|
|
|
|
# Get file information
|
|
|
|
|
FILE_EXT=$(echo "${FILE_ABSOLUT_PATH}" | awk -F'[.]' '{print $NF}')
|
|
|
|
|
|
|
|
|
|
# Get tag information
|
|
|
|
|
DATE=$(eyeD3 "${FILE_ABSOLUT_PATH}" | grep 'title' 2> /dev/null | sed 's/.*\(..\).\(..\).\(201.\).*/\3-\2-\1/')
|
|
|
|
|
TITLE=$(eyeD3 "${FILE_ABSOLUT_PATH}" | grep 'title' 2> /dev/null | sed 's/.*: \(.*\) \(..\).\(..\).\(201.\).*/\1/')
|
|
|
|
|
|
|
|
|
|
printf '%s\n' "date : ${DATE}"
|
|
|
|
|
printf '%s\n' "title : ${TITLE}"
|
|
|
|
|
|
|
|
|
|
# Correct title tag
|
|
|
|
|
command eyeD3 --title="${DATE} ${TITLE}" "${FILE_ABSOLUT_PATH}"
|
|
|
|
|
|
|
|
|
|
# Rename the file
|
|
|
|
|
mv "${FILE_ABSOLUT_PATH}" "${MEURICE_DIR}"/"${DATE}"_"${TITLE}"."${FILE_EXT}"
|
|
|
|
|
|
|
|
|
|
done < "${TMP_LIST_FILE}"
|
|
|
|
|
|
|
|
|
|
# If the first arg is a file
|
|
|
|
|
elif [ -f "${1}" ]; then
|
|
|
|
|
MEURICE_FILE="${1}"
|
|
|
|
|
MEURICE_DIR=$(dirname "${MEURICE_FILE}")
|
2016-10-07 18:16:45 +02:00
|
|
|
|
|
|
|
|
|
# Get file information
|
2016-11-02 10:22:07 +01:00
|
|
|
|
FILE_EXT=$(echo "${MEURICE_FILE}" | awk -F'[.]' '{print $NF}')
|
2016-10-07 18:16:45 +02:00
|
|
|
|
|
|
|
|
|
# Get tag information
|
2016-11-02 10:22:07 +01:00
|
|
|
|
DATE=$(eyeD3 "${MEURICE_FILE}" | grep 'title' 2> /dev/null | sed 's/.*\(..\).\(..\).\(201.\).*/\3-\2-\1/')
|
|
|
|
|
TITLE=$(eyeD3 "${MEURICE_FILE}" | grep 'title' 2> /dev/null | sed 's/.*: \(.*\) \(..\).\(..\).\(201.\).*/\1/')
|
2016-10-07 18:16:45 +02:00
|
|
|
|
|
|
|
|
|
printf '%s\n' "date : ${DATE}"
|
|
|
|
|
printf '%s\n' "title : ${TITLE}"
|
|
|
|
|
|
|
|
|
|
# Correct title tag
|
2016-11-02 10:22:07 +01:00
|
|
|
|
command eyeD3 --title="${DATE} ${TITLE}" "${MEURICE_FILE}"
|
2016-10-07 18:16:45 +02:00
|
|
|
|
|
|
|
|
|
# Rename the file
|
2016-11-02 10:22:07 +01:00
|
|
|
|
mv "${MEURICE_FILE}" "${MEURICE_DIR}"/"${DATE}"_"${TITLE}"."${FILE_EXT}"
|
2016-10-07 18:16:45 +02:00
|
|
|
|
|
2016-11-02 10:22:07 +01:00
|
|
|
|
# Otherwise print an error
|
|
|
|
|
else
|
|
|
|
|
printf '%s\n' "Error with the first arg : ${1}"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2016-10-07 18:16:45 +02:00
|
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
|
|