|
|
|
@ -10,6 +10,7 @@ import (
|
|
|
|
|
"os"
|
|
|
|
|
"os/exec"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"runtime"
|
|
|
|
|
"strings"
|
|
|
|
|
"sync"
|
|
|
|
|
"text/template"
|
|
|
|
@ -55,6 +56,7 @@ var optIgnoreVideos = false
|
|
|
|
|
var optDryRun = false
|
|
|
|
|
var optVerbose = false
|
|
|
|
|
var optCleanUp = false
|
|
|
|
|
var optMemoryUse = false
|
|
|
|
|
|
|
|
|
|
// this function parses command-line arguments
|
|
|
|
|
func parseArgs() (inputDirectory string, outputDirectory string) {
|
|
|
|
@ -64,6 +66,7 @@ func parseArgs() (inputDirectory string, outputDirectory string) {
|
|
|
|
|
optDryRunPtr := flag.Bool("d", false, "Dry run - don't make changes, only explain what would be done")
|
|
|
|
|
optVerbosePtr := flag.Bool("v", false, "Verbose - print debugging information to stderr")
|
|
|
|
|
optProfile := flag.Bool("p", false, "Run Go pprof profiling service for debugging")
|
|
|
|
|
optMemory := flag.Bool("m", false, "Minimize memory usage")
|
|
|
|
|
|
|
|
|
|
flag.Usage = func() {
|
|
|
|
|
fmt.Fprintf(os.Stderr, "Usage: %s [OPTION]... DIRECTORY\n\n", os.Args[0])
|
|
|
|
@ -97,6 +100,10 @@ func parseArgs() (inputDirectory string, outputDirectory string) {
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if *optMemory {
|
|
|
|
|
optMemoryUse = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if *optProfile {
|
|
|
|
|
go func() {
|
|
|
|
|
log.Println(http.ListenAndServe("localhost:6060", nil))
|
|
|
|
@ -233,6 +240,22 @@ func isMediaFile(filename string) bool {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Checks if given directory entry is symbolic link to a directory
|
|
|
|
|
func isSymlinkDir(directory string, entry os.FileInfo) (is bool) {
|
|
|
|
|
if entry.Mode()&os.ModeSymlink != 0 {
|
|
|
|
|
realPath, err := filepath.EvalSymlinks(filepath.Join(directory, entry.Name()))
|
|
|
|
|
checkError(err)
|
|
|
|
|
|
|
|
|
|
fileinfo, err := os.Lstat(realPath)
|
|
|
|
|
checkError(err)
|
|
|
|
|
|
|
|
|
|
if fileinfo.IsDir() {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func recurseDirectory(thisDirectory string, relativeDirectory string) (root directory) {
|
|
|
|
|
root.name = filepath.Base(thisDirectory)
|
|
|
|
|
asIsStat, _ := os.Stat(thisDirectory)
|
|
|
|
@ -247,7 +270,7 @@ func recurseDirectory(thisDirectory string, relativeDirectory string) (root dire
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, entry := range list {
|
|
|
|
|
if entry.IsDir() {
|
|
|
|
|
if entry.IsDir() || isSymlinkDir(thisDirectory, entry) {
|
|
|
|
|
if !isEmptyDir(filepath.Join(thisDirectory, entry.Name())) {
|
|
|
|
|
root.subdirectories = append(root.subdirectories, recurseDirectory(filepath.Join(thisDirectory, entry.Name()), filepath.Join(relativeDirectory, root.name)))
|
|
|
|
|
}
|
|
|
|
@ -713,6 +736,9 @@ func fullsizeImageWorker(wg *sync.WaitGroup, imageJobs chan job, progressBar *pb
|
|
|
|
|
resizeFullsizeImage(job.source, job.destination)
|
|
|
|
|
if !optDryRun {
|
|
|
|
|
progressBar.Increment()
|
|
|
|
|
if optMemoryUse {
|
|
|
|
|
runtime.GC()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -723,6 +749,9 @@ func fullsizeVideoWorker(wg *sync.WaitGroup, videoJobs chan job, progressBar *pb
|
|
|
|
|
resizeFullsizeVideo(job.source, job.destination)
|
|
|
|
|
if !optDryRun {
|
|
|
|
|
progressBar.Increment()
|
|
|
|
|
if optMemoryUse {
|
|
|
|
|
runtime.GC()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -914,15 +943,13 @@ func main() {
|
|
|
|
|
progressBar = pb.StartNew(changes)
|
|
|
|
|
if optVerbose {
|
|
|
|
|
vips.LoggingSettings(nil, vips.LogLevelDebug)
|
|
|
|
|
} else {
|
|
|
|
|
vips.LoggingSettings(nil, vips.LogLevelMessage)
|
|
|
|
|
}
|
|
|
|
|
if optVerbose {
|
|
|
|
|
vips.Startup(&vips.Config{
|
|
|
|
|
ReportLeaks: true})
|
|
|
|
|
CacheTrace: false,
|
|
|
|
|
CollectStats: false,
|
|
|
|
|
ReportLeaks: true})
|
|
|
|
|
} else {
|
|
|
|
|
vips.Startup(&vips.Config{
|
|
|
|
|
ReportLeaks: false})
|
|
|
|
|
vips.LoggingSettings(nil, vips.LogLevelError)
|
|
|
|
|
vips.Startup(nil)
|
|
|
|
|
}
|
|
|
|
|
defer vips.Shutdown()
|
|
|
|
|
}
|
|
|
|
|