diff --git a/README.md b/README.md index 73e64f7..e6fa493 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,8 @@ So it's a tiny script to correct this. I get the date and the "real" title from "Le moment Meurice" : http://www.franceinter.fr/emission-le-moment-meurice +The script manage both a directory and a file as first argument. + ## tag_photo.sh The main goal is to have a solution to know the "subject" of a picture without to open it and no really good name. It can happen if you delete your pictures and get it back with `photorec` or `foremost`. For this i use the Exif metadata. diff --git a/rename_meurice_podcast b/rename_meurice_podcast index 6f9731e..cc71e19 100755 --- a/rename_meurice_podcast +++ b/rename_meurice_podcast @@ -4,36 +4,64 @@ # Also change the title tag (2016.09.30 Title) # http://radiofrance-podcast.net/podcast09/rss_14257.xml -MEURICE_DIR="${1}" -TMP_LIST_FILE="/tmp/list_meurice_file" +# If the first arg is a directory +if [ -d "${1}" ]; then -# List audio files -find "${MEURICE_DIR}" -mindepth 1 -type f -iregex '.*\.mp3' > "${TMP_LIST_FILE}" + MEURICE_DIR="${1}" + TMP_LIST_FILE="/tmp/list_meurice_file" -while IFS= read -r FILE -do + # List audio files + find "${MEURICE_DIR}" -mindepth 1 -type f -iregex '.*\.mp3' > "${TMP_LIST_FILE}" - FILE_ABSOLUT_PATH="${MEURICE_DIR}/${FILE}" + 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}") # Get file information - FILE_EXT=$(echo "${FILE_ABSOLUT_PATH}" | awk -F'[.]' '{print $NF}') + FILE_EXT=$(echo "${MEURICE_FILE}" | 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/') + 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/') printf '%s\n' "date : ${DATE}" printf '%s\n' "title : ${TITLE}" # Correct title tag - command eyeD3 --title="${DATE} ${TITLE}" "${FILE_ABSOLUT_PATH}" + command eyeD3 --title="${DATE} ${TITLE}" "${MEURICE_FILE}" # Rename the file - #cp "${FILE}" "${MEURICE_DIR}"/"${DATE}"_"${TITLE}"."${FILE_EXT}" - #cp "${MEURICE_DIR}"/"${FILE}" "${MEURICE_DIR}"/"${DATE}"_"${TITLE}"."${FILE_EXT}" - mv "${FILE_ABSOLUT_PATH}" "${MEURICE_DIR}"/"${DATE}"_"${TITLE}"."${FILE_EXT}" + mv "${MEURICE_FILE}" "${MEURICE_DIR}"/"${DATE}"_"${TITLE}"."${FILE_EXT}" -done < "${TMP_LIST_FILE}" +# Otherwise print an error +else + printf '%s\n' "Error with the first arg : ${1}" + exit 1 +fi exit 0