Skip to content

Commit

Permalink
Ignores files that are not music files
Browse files Browse the repository at this point in the history
Ignores `.DS_Store` and other files that should not be transcoded.
  • Loading branch information
topfunky committed May 4, 2024
1 parent 22ab69e commit 73aebab
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
6 changes: 4 additions & 2 deletions find_and_transcode_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,11 @@ func getExclusiveFiles(filesA, filesB []string) []FileToRender {
destinationFilename := ""
if strings.HasSuffix(file, ".mp3") {
destinationFilename = file
} else {
} else if strings.HasSuffix(file, ".m4a") {
// TODO: Use func to get file ext instead of hard coding .m4a
destinationFilename = strings.TrimSuffix(file, ".m4a") + ".mp3"
} else {
file = ""
}
fileToRender := FileToRender{
sourcePath: file,
Expand All @@ -170,7 +172,7 @@ func getExclusiveFiles(filesA, filesB []string) []FileToRender {
}

for _, file := range sourceFileOutputNameList {
if !fileMap[file.destinationPath] {
if !fileMap[file.destinationPath] && file.destinationPath != "" {
exclusiveFiles = append(exclusiveFiles, file)
}
}
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: "Ignore non-music files",
SourceList: []string{".DS_Store"},
DestinationList: []string{},
ExpectedOutput: []string(nil),
},
}

for _, c := range cases {
Expand Down
7 changes: 7 additions & 0 deletions sync_and_transcode_music_files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func setupFixtureFilesInDirectory(tempDir string, numberOfFiles int) error {
"source/a-band/file5.m4a",
"source/Whitespace Band/file6.m4a",
"source/the-band/file7.mp3",
"source/.DS_Store",
}
for _, file := range testFiles[0:numberOfFiles] {
filePath := filepath.Join(tempDir, file)
Expand Down Expand Up @@ -117,6 +118,12 @@ func TestFindFiles(t *testing.T) {
assert.True(t, os.IsNotExist(err), fmt.Sprintf("unexpected transcoded file found: %s", nonTranscodedFile))
})

t.Run("Verify that the .DS_Store file was not transcoded", func(t *testing.T) {
nonTranscodedFile := ".DS_Store"
filePath := filepath.Join(tempDir, nonTranscodedFile)
_, err = os.Stat(filePath)
assert.True(t, os.IsNotExist(err), fmt.Sprintf("unexpected transcoded file found: %s", nonTranscodedFile))
})
}

// Destination files should not be re-rendered (check file modified time from first render and compare to second render)
Expand Down

0 comments on commit 73aebab

Please sign in to comment.