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

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=${4}/03" >> ${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_MusicPresentation.mp3
tagfile 01_MusicPresentation.mp3 01 "Music Presentation" 01
encode  01_MusicPresentation.mp3

# 02_SongNo110andPrayer.mp3
tagfile 02_SongNo110andPrayer.mp3 02 "Song No 110 and Prayer" 01
encode  02_SongNo110andPrayer.mp3

# 03_JehovahTheSourceOfTrueCourage.mp3
tagfile 03_JehovahTheSourceOfTrueCourage.mp3 03 "Jehovah The Source Of True Courage" 01
encode  03_JehovahTheSourceOfTrueCourage.mp3

# 04_WhyTrueChristiansNeedCourage_ToPreach.mp3
tagfile 04_WhyTrueChristiansNeedCourage_ToPreach.mp3 04 "Why True Christians Need Courage: To Preach" 01
encode  04_WhyTrueChristiansNeedCourage_ToPreach.mp3

# 05_WhyTrueChristiansNeedCourage_ToRemainHoly.mp3
tagfile 05_WhyTrueChristiansNeedCourage_ToRemainHoly.mp3 05 "Why True Christians Need Courage: To Remain Holy" 01
encode  05_WhyTrueChristiansNeedCourage_ToRemainHoly.mp3

# 06_WhyTrueChristiansNeedCourage_ToMaintainNeutrality.mp3
tagfile 06_WhyTrueChristiansNeedCourage_ToMaintainNeutrality.mp3 06 "Why True Christians Need Courage: To Maintain Neutrality" 01
encode  06_WhyTrueChristiansNeedCourage_ToMaintainNeutrality.mp3

# 07_SongNo126andAnnouncements.mp3
tagfile 07_SongNo126andAnnouncements.mp3 07 "Song No 126 and Announcements" 01
encode  07_SongNo126andAnnouncements.mp3

# 08_BeCourageousAndStrongAndGoToWork_GB_DSplane.mp3
tagfile 08_BeCourageousAndStrongAndGoToWork_GB_DSplane.mp3 08 "Be Courageous And Strong And Go To Work" 01
encode  08_BeCourageousAndStrongAndGoToWork_GB_DSplane.mp3

# 09_NoWeaponFormedAgainstYouWillHaveAnySuccess.mp3
tagfile 09_NoWeaponFormedAgainstYouWillHaveAnySuccess.mp3 09 "No Weapon Formed Against You Will Have Any Success" 01
encode  09_NoWeaponFormedAgainstYouWillHaveAnySuccess.mp3

# 10_SongNo61andIntermission.mp3
tagfile 10_SongNo61andIntermission.mp3 10 "Song No 61 and Intermission" 01
encode  10_SongNo61andIntermission.mp3

# 11_MusicPresentation.mp3
tagfile 11_MusicPresentation.mp3 11 "Music Presentation" 01
encode  11_MusicPresentation.mp3

# 12_SongNo69.mp3
tagfile 12_SongNo69.mp3 12 "Song No 69" 01
encode  12_SongNo69.mp3

# 13_DespairVersusHope.mp3
tagfile 13_DespairVersusHope.mp3 13 "Courage Weakeners Versus Courage Strengtheners: Despair Versus Hope" 01
encode  13_DespairVersusHope.mp3

# 14_ComplaintVersusThanksgiving.mp3
tagfile 14_ComplaintVersusThanksgiving.mp3 14 "Courage Weakeners Versus Courage Strengtheners: Complaint Versus Thanksgiving" 01
encode  14_ComplaintVersusThanksgiving.mp3

# 15_UnwholesomeRecreationVersusFieldMinistry.mp3
tagfile 15_UnwholesomeRecreationVersusFieldMinistry.mp3 15 "15_UnwholesomeRecreationVersusFieldMinistry.mp3" 01
encode  15_UnwholesomeRecreationVersusFieldMinistry.mp3

# 16_BadAssociationsVersusGoodAssociations.mp3
tagfile 16_BadAssociationsVersusGoodAssociations.mp3 16 "16_BadAssociationsVersusGoodAssociations.mp3" 01
encode  16_BadAssociationsVersusGoodAssociations.mp3

# 17_WorldlyWisdomVersusPersonalStudy.mp3
tagfile 17_WorldlyWisdomVersusPersonalStudy.mp3 17 "17_WorldlyWisdomVersusPersonalStudy.mp3" 01
encode  17_WorldlyWisdomVersusPersonalStudy.mp3

# 18_DoubtVersusFaith.mp3
tagfile 18_DoubtVersusFaith.mp3 18 "18_DoubtVersusFaith.mp3" 01
encode  18_DoubtVersusFaith.mp3

# 19_SongNo55andAnnouncements.mp3
tagfile 19_SongNo55andAnnouncements.mp3 19 "19_SongNo55andAnnouncements.mp3" 01
encode  19_SongNo55andAnnouncements.mp3

# 20_WhatTheyRisked_HananiahMishaelAzariah3.mp3
tagfile 20_WhatTheyRisked_HananiahMishaelAzariah3.mp3 20 "20_WhatTheyRisked_HananiahMishaelAzariah3.mp3" 01
encode  20_WhatTheyRisked_HananiahMishaelAzariah3.mp3

# 21_WhatTheyRisked_AquilaAndPriscilla.mp3
tagfile 21_WhatTheyRisked_AquilaAndPriscilla.mp3 21 "21_WhatTheyRisked_AquilaAndPriscilla.mp3" 01
encode  21_WhatTheyRisked_AquilaAndPriscilla.mp3

# 22_WhatTheyRisked_Stephen.mp3
tagfile 22_WhatTheyRisked_Stephen.mp3 22 "22_WhatTheyRisked_Stephen.mp3" 01
encode  22_WhatTheyRisked_Stephen.mp3

# 23_TakeCourageIHaveConqueredTheWorld.mp3
tagfile 23_TakeCourageIHaveConqueredTheWorld.mp3 23 "23_TakeCourageIHaveConqueredTheWorld.mp3" 01
encode  23_TakeCourageIHaveConqueredTheWorld.mp3

# 24_CourageousSoldiersOfChrist.mp3
tagfile 24_CourageousSoldiersOfChrist.mp3 24 "24_CourageousSoldiersOfChrist.mp3" 01
encode  24_CourageousSoldiersOfChrist.mp3

# 25_SongNo22andClosingPrayer.mp3
tagfile 25_SongNo22andClosingPrayer.mp3 25 "25_SongNo22andClosingPrayer.mp3" 01
encode  25_SongNo22andClosingPrayer.mp3

# 26_MusicPresentation.mp3
tagfile 26_MusicPresentation.mp3 01 "26_MusicPresentation.mp3" 02
encode  26_MusicPresentation.mp3

# 27_SongNo76andPrayer.mp3
tagfile 27_SongNo76andPrayer.mp3 02 "27_SongNo76andPrayer.mp3" 02
encode  27_SongNo76andPrayer.mp3

# 28_BeACourageous_BibleStudent.mp3
tagfile 28_BeACourageous_BibleStudent.mp3 03 "28_BeACourageous_BibleStudent.mp3" 02
encode  28_BeACourageous_BibleStudent.mp3

# 29_BeACourageous_Youth.mp3
tagfile 29_BeACourageous_Youth.mp3 04 "29_BeACourageous_Youth.mp3" 02
encode  29_BeACourageous_Youth.mp3

# 30_BeACourageous_Publisher.mp3
tagfile 30_BeACourageous_Publisher.mp3 05 "30_BeACourageous_Publisher.mp3" 02
encode  30_BeACourageous_Publisher.mp3

# 31_BeACourageous_MarriageMate.mp3
tagfile 31_BeACourageous_MarriageMate.mp3 06 "31_BeACourageous_MarriageMate.mp3" 02
encode  31_BeACourageous_MarriageMate.mp3

# 32_BeACourageous_Parent.mp3
tagfile 32_BeACourageous_Parent.mp3 07 "32_BeACourageous_Parent.mp3" 02
encode  32_BeACourageous_Parent.mp3

# 33_BeACourageous_Pioneer.mp3
tagfile 33_BeACourageous_Pioneer.mp3 08 "33_BeACourageous_Pioneer.mp3" 02
encode  33_BeACourageous_Pioneer.mp3

# 34_BeACourageous_CongregationElder.mp3
tagfile 34_BeACourageous_CongregationElder.mp3 09 "34_BeACourageous_CongregationElder.mp3" 02
encode  34_BeACourageous_CongregationElder.mp3

# 35_BeACourageous_OlderPerson.mp3
tagfile 35_BeACourageous_OlderPerson.mp3 10 "35_BeACourageous_OlderPerson.mp3" 02
encode  35_BeACourageous_OlderPerson.mp3

# 36_SongNo119andAnnouncements.mp3
tagfile 36_SongNo119andAnnouncements.mp3 11 "36_SongNo119andAnnouncements.mp3" 02
encode  36_SongNo119andAnnouncements.mp3

# 37_Imitate_JoshuaAndCaleb.mp3
tagfile 37_Imitate_JoshuaAndCaleb.mp3 12 "37_Imitate_JoshuaAndCaleb.mp3" 02
encode  37_Imitate_JoshuaAndCaleb.mp3

# 38_Imitate_Jael_OS_BMcLaren.mp3
tagfile 38_Imitate_Jael_OS_BMcLaren.mp3 13 "38_Imitate_Jael_OS_BMcLaren.mp3" 02
encode  38_Imitate_Jael_OS_BMcLaren.mp3

# 39_Imitate_Micaiah.mp3
tagfile 39_Imitate_Micaiah.mp3 14 "39_Imitate_Micaiah.mp3" 02
encode  39_Imitate_Micaiah.mp3

# 40_Imitate_Jeremiah.mp3
tagfile 40_Imitate_Jeremiah.mp3 15 "40_Imitate_Jeremiah.mp3" 02
encode  40_Imitate_Jeremiah.mp3

# 41_Imitate_Paul.mp3
tagfile 41_Imitate_Paul.mp3 16 "41_Imitate_Paul.mp3" 02
encode  41_Imitate_Paul.mp3

# 42_Baptism_WeAreNotTheSortWhoShrinkBack.mp3
tagfile 42_Baptism_WeAreNotTheSortWhoShrinkBack.mp3 17 "42_Baptism_WeAreNotTheSortWhoShrinkBack.mp3" 02
encode  42_Baptism_WeAreNotTheSortWhoShrinkBack.mp3

# 43_SongNo38andIntermission.mp3
tagfile 43_SongNo38andIntermission.mp3 18 "43_SongNo38andIntermission.mp3" 02
encode  43_SongNo38andIntermission.mp3

# 44_MusicPresentation.mp3
tagfile 44_MusicPresentation.mp3 19 "44_MusicPresentation.mp3" 02
encode  44_MusicPresentation.mp3

# 45_SongNo111.mp3
tagfile 45_SongNo111.mp3 20 "45_SongNo111.mp3" 02
encode  45_SongNo111.mp3

# 46_LearnCourageFromCreation_Lions.mp3
tagfile 46_LearnCourageFromCreation_Lions.mp3 21 "46_LearnCourageFromCreation_Lions.mp3" 02
encode  46_LearnCourageFromCreation_Lions.mp3

# 47_LearnCourageFromCreation_Horses.mp3
tagfile 47_LearnCourageFromCreation_Horses.mp3 22 "47_LearnCourageFromCreation_Horses.mp3" 02
encode  47_LearnCourageFromCreation_Horses.mp3

# 48_LearnCourageFromCreation_Mongooses.mp3
tagfile 48_LearnCourageFromCreation_Mongooses.mp3 23 "48_LearnCourageFromCreation_Mongooses.mp3" 02
encode  48_LearnCourageFromCreation_Mongooses.mp3

# 49_LearnCourageFromCreation_Hummingbirds.mp3
tagfile 49_LearnCourageFromCreation_Hummingbirds.mp3 24 "49_LearnCourageFromCreation_Hummingbirds.mp3" 02
encode  49_LearnCourageFromCreation_Hummingbirds.mp3

# 50_LearnCourageFromCreation_Elephants.mp3
tagfile 50_LearnCourageFromCreation_Elephants.mp3 25 "50_LearnCourageFromCreation_Elephants.mp3" 02
encode  50_LearnCourageFromCreation_Elephants.mp3

# 51_SongNo60andAnnouncements.mp3
tagfile 51_SongNo60andAnnouncements.mp3 26 "51_SongNo60andAnnouncements.mp3" 02
encode  51_SongNo60andAnnouncements.mp3

# 52_ShowingCourageIn_Africa.mp3
tagfile 52_ShowingCourageIn_Africa.mp3 27 "52_ShowingCourageIn_Africa.mp3" 02
encode  52_ShowingCourageIn_Africa.mp3

# 53_ShowingCourageIn_Asia.mp3
tagfile 53_ShowingCourageIn_Asia.mp3 28 "53_ShowingCourageIn_Asia.mp3" 02
encode  53_ShowingCourageIn_Asia.mp3

# 54_ShowingCourageIn_Europe.mp3
tagfile 54_ShowingCourageIn_Europe.mp3 29 "54_ShowingCourageIn_Europe.mp3" 02
encode  54_ShowingCourageIn_Europe.mp3

# 55_ShowingCourageIn_NorthAmerica.mp3
tagfile 55_ShowingCourageIn_NorthAmerica.mp3 30 "55_ShowingCourageIn_NorthAmerica.mp3" 02
encode  55_ShowingCourageIn_NorthAmerica.mp3

# 56_ShowingCourageIn_Oceania.mp3
tagfile 56_ShowingCourageIn_Oceania.mp3 31 "56_ShowingCourageIn_Oceania.mp3" 02
encode  56_ShowingCourageIn_Oceania.mp3

# 57_ShowingCourageIn_SouthAmerica.mp3
tagfile 57_ShowingCourageIn_SouthAmerica.mp3 32 "57_ShowingCourageIn_SouthAmerica.mp3" 02
encode  57_ShowingCourageIn_SouthAmerica.mp3

# 58_CourageousButNotSelfReliant.mp3
tagfile 58_CourageousButNotSelfReliant.mp3 33 "58_CourageousButNotSelfReliant.mp3" 02
encode  58_CourageousButNotSelfReliant.mp3

# 59_SongNo3andClosingPrayer.mp3
tagfile 59_SongNo3andClosingPrayer.mp3 34 "59_SongNo3andClosingPrayer.mp3" 02
encode  59_SongNo3andClosingPrayer.mp3

# 60_MusicPresentation.mp3
tagfile 60_MusicPresentation.mp3 01 "60_MusicPresentation.mp3" 03
encode  60_MusicPresentation.mp3

# 61_SongNo73and Prayer.mp3
tagfile 61_SongNo73and Prayer.mp3 02 "61_SongNo73and Prayer.mp3" 03
encode  61_SongNo73and Prayer.mp3

# 62_FutureEvents_TheCryOfPeaceAndSecurity.mp3
tagfile 62_FutureEvents_TheCryOfPeaceAndSecurity.mp3 03 "62_FutureEvents_TheCryOfPeaceAndSecurity.mp3" 03
encode  62_FutureEvents_TheCryOfPeaceAndSecurity.mp3

# 63_FutureEvents_TheDestructionOfBabylonTheGreat.mp3
tagfile 63_FutureEvents_TheDestructionOfBabylonTheGreat.mp3 04 "63_FutureEvents_TheDestructionOfBabylonTheGreat.mp3" 03
encode  63_FutureEvents_TheDestructionOfBabylonTheGreat.mp3

# 64_FutureEvents_TheProclamationOfTheHailstoneMessage.mp3
tagfile 64_FutureEvents_TheProclamationOfTheHailstoneMessage.mp3 05 "64_FutureEvents_TheProclamationOfTheHailstoneMessage.mp3" 03
encode  64_FutureEvents_TheProclamationOfTheHailstoneMessage.mp3

# 65_FutureEvents_TheAttackByGogOfMagog.mp3
tagfile 65_FutureEvents_TheAttackByGogOfMagog.mp3 06 "65_FutureEvents_TheAttackByGogOfMagog.mp3" 03
encode  65_FutureEvents_TheAttackByGogOfMagog.mp3

# 66_FutureEvents_Armageddon.mp3
tagfile 66_FutureEvents_Armageddon.mp3 07 "66_FutureEvents_Armageddon.mp3" 03
encode  66_FutureEvents_Armageddon.mp3

# 67_FutureEvents_TheGreatReconstruction.mp3
tagfile 67_FutureEvents_TheGreatReconstruction.mp3 08 "67_FutureEvents_TheGreatReconstruction.mp3" 03
encode  67_FutureEvents_TheGreatReconstruction.mp3

# 68_FutureEvents_TheFinalTest.mp3
tagfile 68_FutureEvents_TheFinalTest.mp3 09 "68_FutureEvents_TheFinalTest.mp3" 03
encode  68_FutureEvents_TheFinalTest.mp3

# 69_SongNo8andAnnouncements.mp3
tagfile 69_SongNo8andAnnouncements.mp3 10 "69_SongNo8andAnnouncements.mp3" 03
encode  69_SongNo8andAnnouncements.mp3

# 70_TheResurrectionHopeImpartsCourageHow.mp3
tagfile 70_TheResurrectionHopeImpartsCourageHow.mp3 11 "70_TheResurrectionHopeImpartsCourageHow.mp3" 03
encode  70_TheResurrectionHopeImpartsCourageHow.mp3

# 71_SummaryOfTheWatchtower.mp3
tagfile 71_SummaryOfTheWatchtower.mp3 12 "71_SummaryOfTheWatchtower.mp3" 03
encode  71_SummaryOfTheWatchtower.mp3

# 72_SongNo151andIntermission.mp3
tagfile 72_SongNo151andIntermission.mp3 13 "72_SongNo151andIntermission.mp3" 03
encode  72_SongNo151andIntermission.mp3

# 73_MusicPresentation.mp3
tagfile 73_MusicPresentation.mp3 14 "73_MusicPresentation.mp3" 03
encode  73_MusicPresentation.mp3

# 74_SongNo5.mp3
tagfile 74_SongNo5.mp3 15 "74_SongNo5.mp3" 03
encode  74_SongNo5.mp3

# 75_TheStoryOfJonah_ALessonInCourageAndMercy.mp3
tagfile 75_TheStoryOfJonah_ALessonInCourageAndMercy.mp3 16 "75_TheStoryOfJonah_ALessonInCourageAndMercy.mp3" 03
encode  75_TheStoryOfJonah_ALessonInCourageAndMercy.mp3

# 76_SongNo71andAnnouncements.mp3
tagfile 76_SongNo71andAnnouncements.mp3 17 "76_SongNo71andAnnouncements.mp3" 03
encode  76_SongNo71andAnnouncements.mp3

# 77_ThereAreMoreWithUsThanAgainstUs.mp3
tagfile 77_ThereAreMoreWithUsThanAgainstUs.mp3 18 "77_ThereAreMoreWithUsThanAgainstUs.mp3" 03
encode  77_ThereAreMoreWithUsThanAgainstUs.mp3

# 78_ClosingSong_GiveMeCourage_AndPrayer.mp3
tagfile 78_ClosingSong_GiveMeCourage_AndPrayer.mp3 19 "78_ClosingSong_GiveMeCourage_AndPrayer.mp3" 03
encode  78_ClosingSong_GiveMeCourage_AndPrayer.mp3
