Advertisement
emilwojcik93

ogg/mp3-2-flac_converter

Nov 15th, 2022 (edited)
1,325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.13 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. export_dir="./export-2"
  4. check-tag_ogg () {
  5.     vorbiscomment -lRe ${1} | grep ${2} | sed "s/${2}=//g"
  6. }
  7.  
  8. check-tag_mp3 () {
  9.     mid3v2 -l ${1} | grep ${2} | sed "s/${2}=//g"
  10. }
  11.  
  12. #metadata-update_ogg () {
  13. #    if [[ ! $(check-tag_ogg ${1} ${2} ${3}) ]]; then
  14. #        vorbiscomment -a ${1} -t "${2}=${3}"
  15. #    fi
  16. #}
  17. #metadata-update_mp3 () {
  18. #    if [[ ! $(check-tag_mp3 ${1} ${2} ${3}) ]]; then
  19. #        mid3v2 --${2} "${3}" ${1}
  20. #    fi
  21. #}
  22.  
  23. if [[ ! -d "${export_dir}" ]]; then
  24.     mkdir -p ${export_dir}
  25. fi
  26.  
  27.  
  28. for file in ./*
  29. do
  30.     if [[ "${file##*.}" = "ogg" ]]; then
  31.         if [[ $(check-tag_ogg ${file} ARTIST) ]] && [[ $(check-tag_ogg ${file} TITLE) ]]; then
  32.             artist_value="$(check-tag_ogg ${file} ARTIST)"
  33.             title_value="$(check-tag_ogg ${file} TITLE)"
  34.             name="${artist_value} - ${title_value}"
  35.             if [[ ! -f "${export_dir}/${name}.flac" ]]; then
  36.                 echo -e "Building: ${file} -- ${name}" | tee -a "${export_dir}/debug.list"
  37.                 ffmpeg -i ${file} -f flac "${export_dir}/${name}.flac" >/dev/null 2>&1
  38.                 metaflac --remove-all-tags --set-tag="ARTIST=${artist_value}" --set-tag="TITLE=${title_value}" --set-tag="ALBUM=Star Citizen" --set-tag="GENRE=soundtrack" --set-tag="ORGANIZATION=Cloud Imperium Games" --import-picture-from="3|image/jpeg|||star-citizen-cover-500x500.jpg" "${export_dir}/${name}.flac"
  39.                 echo -e "${name}" | tee -a "${export_dir}/playlist.txt" >/dev/null 2>&1
  40.                 echo -e "Complete: ${file} -- ${name}" | tee -a "${export_dir}/debug.list"
  41.             else
  42.                 echo -e "File: ${name} exist in dir: ${export_dir}. Skipping..." | tee -a "${export_dir}/debug.list" >/dev/null 2>&1
  43.             fi
  44.         else
  45.             echo -e "File: ${file} do not have required metadata"
  46.         fi
  47.     elif [[ "${file##*.}" = "mp3" ]]; then
  48.         if [[ $(check-tag_mp3 ${file} TPE1) ]] && [[ $(check-tag_mp3 ${file} TIT2) ]]; then
  49.             artist_value="$(check-tag_mp3 ${file} TPE1)"
  50.             title_value="$(check-tag_mp3 ${file} TIT2)"
  51.             name="${artist_value} - ${title_value}"
  52.             if [[ ! -f "${export_dir}/${name}.flac" ]]; then
  53.                 echo -e "Building: ${file} -- ${name}" | tee -a "${export_dir}/debug.list"
  54.                 ffmpeg -i ${file} -f flac "${export_dir}/${name}.flac" >/dev/null 2>&1
  55.                 metaflac --remove-all-tags --set-tag="ARTIST=${artist_value}" --set-tag="TITLE=${title_value}" --set-tag="ALBUM=Star Citizen" --set-tag="GENRE=soundtrack" --set-tag="ORGANIZATION=Cloud Imperium Games" --import-picture-from="3|image/jpeg|||star-citizen-cover-500x500.jpg" "${export_dir}/${name}.flac"
  56.                 echo -e "${name}" | tee -a "${export_dir}/playlist.txt" >/dev/null 2>&1
  57.                 echo -e "Complete: ${file} -- ${name}" | tee -a "${export_dir}/debug.list"
  58.             else
  59.                 echo -e "File: ${name} exist in dir: ${export_dir}. Skipping..." | tee -a "${export_dir}/debug.list" >/dev/null 2>&1
  60.             fi
  61.         else
  62.             echo -e "File: ${file} do not have required metadata"
  63.         fi
  64.     fi
  65. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement