#!/bin/sh
CDIR=$(echo "${PWD##*/}" | sed 's/_/ /g')

#ffmpeg -i "${FILE}" -map_metadata -1 -vn -c:a flac -y "${AUD}.flac"
#metaflac --preserve-modtime --import-tags-from="${AUD}.tags" "${AUD}.flac"
#oggenc "${AUD}.flac"

#rm -f "${AUD}.flac"

tagfile(){
    FILE="${1}"
    AUD="$(echo ${FILE%.*})"

    echo "TITLE=${3}" > ${AUD}.tags
    echo "ARTIST=Watch Tower" >> ${AUD}.tags
    echo "ALBUMARTIST=Watch Tower" >> ${AUD}.tags
    echo "DISCNUMBER=01/01" >> ${AUD}.tags
    echo "ALBUM=${CDIR}" >> ${AUD}.tags
    echo "TRACKNUMBER=${2}" >> ${AUD}.tags
    echo "YEAR=2018" >> ${AUD}.tags
}

encode(){
    FILE="${1}"
    AUD="$(echo ${FILE%.*})"

    ffmpeg -i "${FILE}" -map_metadata -1 -vn -c:a flac -y "${AUD}.flac"
    metaflac --preserve-modtime --import-tags-from="${AUD}.tags" "${AUD}.flac"
    oggenc "${AUD}.flac"
    rm -f "${AUD}.flac"
}

#01-Music_Morning.mp3
tagfile 01-Music_Morning.mp3 01 "Music Morning"
encode  01-Music_Morning.mp3

#02-SongNo77andPrayer.mp3
tagfile 02-SongNo77andPrayer.mp3 02 "Song 77 and Prayer"
encode  02-SongNo77andPrayer.mp3

#03-WhyIsItDifficultToDoWhatIsFine_CO_EKrishna.mp3
tagfile 03-WhyIsItDifficultToDoWhatIsFine_CO_EKrishna.mp3 03 "Why Is It Difficult To Do What Is Fine"
encode  03-WhyIsItDifficultToDoWhatIsFine_CO_EKrishna.mp3

#04-AvoidSowingToTheFlesh_UseSocialMediaWisely.mp3
tagfile 04-AvoidSowingToTheFlesh_UseSocialMediaWisely.mp3 04 "Avoid Sowing To The Flesh Use Social Media Wisely"
encode  04-AvoidSowingToTheFlesh_UseSocialMediaWisely.mp3

#05-AvoidSowingToTheFlesh_ChooseWholesomeEntertainment.mp3
tagfile 05-AvoidSowingToTheFlesh_ChooseWholesomeEntertainment.mp3 05 "Avoid Sowing To The Flesh Choose Wholesome Entertainment"
encode  05-AvoidSowingToTheFlesh_ChooseWholesomeEntertainment.mp3

#06-AvoidSowingToTheFlesh_FightTheSpiritOfEnvy.mp3
tagfile 06-AvoidSowingToTheFlesh_FightTheSpiritOfEnvy.mp3 06 "Avoid Sowing To The Flesh Fight The Spirit Of Envy"
encode  06-AvoidSowingToTheFlesh_FightTheSpiritOfEnvy.mp3

#07-AvoidSowingToTheFlesh_InvestInASecureFuture.mp3
tagfile 07-AvoidSowingToTheFlesh_InvestInASecureFuture.mp3 07 "Avoid Sowing To The Flesh Invest In A Secure Future"
encode  07-AvoidSowingToTheFlesh_InvestInASecureFuture.mp3

#08-SongNo45andAnnouncements.mp3
tagfile 08-SongNo45andAnnouncements.mp3 08 "Song 45 and Announcements"
encode  08-SongNo45andAnnouncements.mp3

#09-KeepWorkingGoodTowardAll.mp3
tagfile 09-KeepWorkingGoodTowardAll.mp3 09 "Keep Working Good Toward All"
encode  09-KeepWorkingGoodTowardAll.mp3

#10-Baptism_DoNotGiveIntoFear.mp3
tagfile 10-Baptism_DoNotGiveIntoFear.mp3 10 "Do Not Give Into Fear"
encode  10-Baptism_DoNotGiveIntoFear.mp3

#11-SongNo63.mp3
tagfile 11-SongNo63.mp3 11 "Song 63"
encode  11-SongNo63.mp3

#12-Music_Afternoon.mp3
tagfile 12-Music_Afternoon.mp3 12 "Music Afternoon"
encode  12-Music_Afternoon.mp3

#13-SongNo127andPrayer.mp3
tagfile 13-SongNo127andPrayer.mp3 13 "Song 127 and Prayer"
encode  13-SongNo127andPrayer.mp3

#14-PublicTalk_AvoidMockingGodInWhatSense_CO_EKrishna.mp3
tagfile 14-PublicTalk_AvoidMockingGodInWhatSense_CO_EKrishna.mp3 14 "Avoid Mocking God In What Sense"
encode  14-PublicTalk_AvoidMockingGodInWhatSense_CO_EKrishna.mp3

#15-WTS_Jan18_WhyGiveToTheOneWhoHas.mp3
tagfile 15-WTS_Jan18_WhyGiveToTheOneWhoHas.mp3 15 "WTS Jan 18 Why Give To The One Who Has"
encode  15-WTS_Jan18_WhyGiveToTheOneWhoHas.mp3

#16-SongNo59andAnnouncements.mp3
tagfile 16-SongNo59andAnnouncements.mp3 16 "Song 59 and Announcements"
encode  16-SongNo59andAnnouncements.mp3

#17-KeepSowingToTheSpirit_DevelopGoodStudyHabits.mp3
tagfile 17-KeepSowingToTheSpirit_DevelopGoodStudyHabits.mp3 17 "Keep Sowing To The Spirit Develop Good Study Habits"
encode  17-KeepSowingToTheSpirit_DevelopGoodStudyHabits.mp3

#18-KeepSowingToTheSpirit_UseBiblePrinciplesToGuideYourLife.mp3
tagfile 18-KeepSowingToTheSpirit_UseBiblePrinciplesToGuideYourLife.mp3 18 "Keep Sowing To The Spirit Use Bible Principles To Guide Your Life"
encode  18-KeepSowingToTheSpirit_UseBiblePrinciplesToGuideYourLife.mp3

#19-KeepSowingToTheSpirit_DoNotLetYourHandRest.mp3
tagfile 19-KeepSowingToTheSpirit_DoNotLetYourHandRest.mp3 19 "Keep Sowing To The Spirit Do Not Let Your Hand Rest"
encode  19-KeepSowingToTheSpirit_DoNotLetYourHandRest.mp3

#20-WhatWillWeReapIfWeDoNotTireOut.mp3
tagfile 20-WhatWillWeReapIfWeDoNotTireOut.mp3 20 "What Will We Reap If We Do Not Tire Out"
encode  20-WhatWillWeReapIfWeDoNotTireOut.mp3

#21-SongNo126andPrayer.mp3
tagfile 21-SongNo126andPrayer.mp3 21 "Song 126 and Prayer"
encode  21-SongNo126andPrayer.mp3

