Skip to content

Commit

Permalink
Adds detection of .aif files
Browse files Browse the repository at this point in the history
Source files include `.aif` which should be transcoded as well.
  • Loading branch information
topfunky committed May 4, 2024
1 parent 5276206 commit 75893b4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions find_and_transcode_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func findFiles(sourceDir, destinationDir string) error {
for _, file := range filesThatNeedToBeRendered {
sourcePath := filepath.Join(sourceDir, file.sourcePath)

if strings.HasSuffix(sourcePath, ".m4a") {
if strings.HasSuffix(sourcePath, ".m4a") || strings.HasSuffix(sourcePath, ".aif") {
// TODO: Extract to transcodeFileAtPath with sourcePath and destinationDir
destinationPath := filepath.Join(destinationDir, strings.TrimSuffix(file.sourcePath, filepath.Ext(file.sourcePath))+".mp3")
err := transcodeFileAtPath(sourcePath, destinationPath)
Expand Down Expand Up @@ -164,7 +164,7 @@ func getExclusiveFiles(filesA, filesB []string) []FileToRender {
if strings.HasSuffix(file, ".mp3") {
// Copy .mp3 files over verbatim
destinationFilename = file
} else if strings.HasSuffix(file, ".m4a") {
} else if strings.HasSuffix(file, ".m4a") || strings.HasSuffix(file, ".aif") {
// Other files need to be transcoded to .mp3
destinationFilename = strings.TrimSuffix(file, filepath.Ext(file)) + ".mp3"
} else {
Expand Down
6 changes: 6 additions & 0 deletions find_and_transcode_files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ func TestGetExclusiveFiles(t *testing.T) {
DestinationList: []string{"file4.m4a", "file5.mp3", "file6.mp3"},
ExpectedOutput: []string{"file1.m4a", "file2.m4a", "file3.m4a"},
},
{
Name: "Destination contains aif files which should be transcoded",
SourceList: []string{"file1.m4a", "file2.aif"},
DestinationList: []string{},
ExpectedOutput: []string{"file1.m4a", "file2.aif"},
},
{
Name: "Ignore non-music files",
SourceList: []string{".DS_Store"},
Expand Down
3 changes: 3 additions & 0 deletions sync_and_transcode_music_files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func setupFixtureFilesInDirectory(tempDir string, numberOfFiles int) error {
"source/a-band/file5.m4a",
"source/Whitespace Band/file6.m4a",
"source/the-band/file7.mp3",
"source/file8.aif",
"source/.DS_Store",
}
for _, file := range testFiles[0:numberOfFiles] {
Expand Down Expand Up @@ -91,6 +92,8 @@ func TestFindFiles(t *testing.T) {
"destination/a-band/file5.mp3",
"destination/Whitespace Band/file6.mp3",
"destination/the-band/file7.mp3",
"destination/file8.mp3",
// TODO: Maybe needs to include blank spot for missing .DS_Store
}

tempDir, err := setup(t, len(transcodedFiles))
Expand Down

0 comments on commit 75893b4

Please sign in to comment.