-
Notifications
You must be signed in to change notification settings - Fork 0
/
music_filter.go
52 lines (47 loc) · 1.31 KB
/
music_filter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"io/ioutil"
"music_filter/file"
"music_filter/filter"
"music_filter/unzip"
"path/filepath"
"strings"
)
func main() {
location := "/Users/arun/Downloads/Music"
destinationLocation := "/Users/arun/Documents/Music"
fileNames := ListFileNamesOn(location)
zipFileNames := filter.FilterBy(fileNames, ".zip")
var fileNamesInZip []string
for _, zipFileName := range zipFileNames {
fileNamesInZip = append(fileNamesInZip, unzip.ListFileNamesInZip(zipFileName, unzip.FileNameWithoutExtension(zipFileName))...)
}
flacFileNames := filter.FilterBy(fileNamesInZip, ".flac")
ExtractZipOn(location)
file.Copy(flacFileNames, destinationLocation)
}
func ListFileNamesOn(location string) []string {
files, err := ioutil.ReadDir(location)
fileNames := make([]string, len(files), len(files))
if err == nil {
for index, file := range files {
fileNames[index] = unzip.AbsolutePath(location, file.Name())
}
}
return fileNames
}
func ExtractZipOn(location string) {
files := ListFileNamesOn(location)
for _, file := range files {
_, fileNameAlone := filepath.Split(file)
if !IsHiddenFile(fileNameAlone) {
err := unzip.Unzip(file, unzip.FileNameWithoutExtension(file))
if err != nil {
panic(err)
}
}
}
}
func IsHiddenFile(fileName string) bool {
return strings.HasPrefix(fileName, ".")
}