Skip to content

Commit

Permalink
Renames variables to transcode
Browse files Browse the repository at this point in the history
Some variables referred to "rendering" which is not precise. This
application transcodes music.
  • Loading branch information
topfunky committed May 15, 2024
1 parent 2f1793e commit a738afc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
18 changes: 9 additions & 9 deletions find_and_transcode_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/xfrr/goffmpeg/transcoder"
)

type fileToRender struct {
type fileToTranscode struct {
sourcePath string
destinationPath string
}
Expand All @@ -24,12 +24,12 @@ func findAndTranscodeFiles(sourceDir, destinationDir string) error {
return fmt.Errorf("failed to create destination directory: %v", err)
}

filesThatNeedToBeRendered, err := compareDirectories(sourceDir, destinationDir)
filesThatNeedToBeTranscoded, err := compareDirectories(sourceDir, destinationDir)
if err != nil {
return fmt.Errorf("error: %v", err)
}

for _, file := range filesThatNeedToBeRendered {
for _, file := range filesThatNeedToBeTranscoded {
sourcePath := filepath.Join(sourceDir, file.sourcePath)

if isUntranscodedMusicFile(sourcePath) {
Expand Down Expand Up @@ -117,7 +117,7 @@ func transcodeFileAtPath(fileSourcePath, sourcePath, destinationDir string) erro

// compareDirectories compares the files in two directories and returns a list of the files exclusive to directory A.
// The return value is the files that need to be transcoded (or copied to the destination, if already MP3).
func compareDirectories(a string, b string) ([]fileToRender, error) {
func compareDirectories(a string, b string) ([]fileToTranscode, error) {
filesA, err := getFilenames(a)
if err != nil {
return nil, err
Expand Down Expand Up @@ -157,16 +157,16 @@ func getFilenames(directory string) ([]string, error) {
}

// getExclusiveFiles returns the files exclusive to filesA compared to filesB.
func getExclusiveFiles(filesA, filesB []string) []fileToRender {
exclusiveFiles := make([]fileToRender, 0)
func getExclusiveFiles(filesA, filesB []string) []fileToTranscode {
exclusiveFiles := make([]fileToTranscode, 0)

fileMap := make(map[string]bool)
for _, file := range filesB {
fileMap[file] = true
}

// Generate list of filenames that need to be transcoded later
var sourceFileOutputNameList []fileToRender
var sourceFileOutputNameList []fileToTranscode
for _, file := range filesA {
destinationFilename := ""
if strings.HasSuffix(file, ".mp3") {
Expand All @@ -179,12 +179,12 @@ func getExclusiveFiles(filesA, filesB []string) []fileToRender {
// Ignore .DS_Store, .txt and other files
file = ""
}
fileToRender := fileToRender{
fileToTranscode := fileToTranscode{
sourcePath: file,
destinationPath: destinationFilename,
}

sourceFileOutputNameList = append(sourceFileOutputNameList, fileToRender)
sourceFileOutputNameList = append(sourceFileOutputNameList, fileToTranscode)
}

for _, file := range sourceFileOutputNameList {
Expand Down
4 changes: 2 additions & 2 deletions find_and_transcode_files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,10 @@ func TestFindFiles_NoReRender(t *testing.T) {
})
}

// Returns a string array of only the `sourcePath` attribute from an array of `fileToRender` structs.
// Returns a string array of only the `sourcePath` attribute from an array of `fileToTranscode` structs.
//
// This makes test assertions cleaner, based on how the fixture data is written.
func getDestinationPaths(files []fileToRender) []string {
func getDestinationPaths(files []fileToTranscode) []string {
var sources []string
for _, file := range files {
sources = append(sources, file.destinationPath)
Expand Down

0 comments on commit a738afc

Please sign in to comment.