add option to remove non-image files from archive

This commit is contained in:
Milan Nikolic
2015-11-04 00:28:18 +01:00
parent 85818eec5f
commit 82e8a6cbac
2 changed files with 26 additions and 21 deletions

View File

@@ -41,8 +41,9 @@ Using
-w, --width=0 image width -w, --width=0 image width
-h, --height=0 image height -h, --height=0 image height
-q, --quality=75 JPEG image quality -q, --quality=75 JPEG image quality
-n, --norgb do not convert images with RGB colorspace -f, --filter=2 0=NearestNeighbor, 1=Box, 2=Linear, 3=MitchellNetravali, 4=CatmullRom, 6=Gaussian, 7=Lanczos
-f, --filter=0 0=NearestNeighbor, 1=Box, 2=Linear, 3=MitchellNetravali, 4=CatmullRom, 6=Gaussian, 7=Lanczos -N, --no_rgb do not convert images that have RGB colorspace
-I, --no_nonimage remove non image files from archive
-s, --suffix=SUFFIX add suffix to file basename -s, --suffix=SUFFIX add suffix to file basename
-c, --cover extract cover -c, --cover extract cover
-t, --thumbnail extract cover thumbnail (freedesktop spec.) -t, --thumbnail extract cover thumbnail (freedesktop spec.)

View File

@@ -83,22 +83,23 @@ var (
// Command line options // Command line options
type options struct { type options struct {
ToPNG bool // encode images to PNG instead of JPEG ToPNG bool // encode images to PNG instead of JPEG
ToBMP bool // encode images to 4-Bit BMP (16 colors) instead of JPEG ToBMP bool // encode images to 4-Bit BMP (16 colors) instead of JPEG
ToGIF bool // encode images to GIF instead of JPEG ToGIF bool // encode images to GIF instead of JPEG
Quality int // JPEG image quality Quality int // JPEG image quality
NoRGB bool // do not convert images that have RGB colorspace Width int // image width
Width int // image width Height int // image height
Height int // image height Filter int // 0=NearestNeighbor, 1=Box, 2=Linear, 3=MitchellNetravali, 4=CatmullRom, 6=Gaussian, 7=Lanczos
Filter int // 0=NearestNeighbor, 1=Box, 2=Linear, 3=MitchellNetravali, 4=CatmullRom, 6=Gaussian, 7=Lanczos NoRGB bool // do not convert images that have RGB colorspace
Suffix string // add suffix to file basename NoNonImage bool // remove non image files from archive
Cover bool // extract cover Suffix string // add suffix to file basename
Thumbnail bool // extract cover thumbnail (freedesktop spec.) Cover bool // extract cover
Outdir string // output directory Thumbnail bool // extract cover thumbnail (freedesktop spec.)
Grayscale bool // convert images to grayscale (monochromatic) Outdir string // output directory
Recursive bool // process subdirectories recursively Grayscale bool // convert images to grayscale (monochromatic)
Size int64 // process only files larger then size (in MB) Recursive bool // process subdirectories recursively
Quiet bool // hide console output Size int64 // process only files larger then size (in MB)
Quiet bool // hide console output
} }
// Command line arguments // Command line arguments
@@ -326,7 +327,9 @@ func convertArchive(file string) {
go convertImage(img, 0, pathname) go convertImage(img, 0, pathname)
} }
} else { } else {
copyFile(bytes.NewReader(buf), filepath.Join(workdir, filepath.Base(pathname))) if !opts.NoNonImage {
copyFile(bytes.NewReader(buf), filepath.Join(workdir, filepath.Base(pathname)))
}
} }
} }
wg.Wait() wg.Wait()
@@ -846,8 +849,9 @@ func parseFlags() {
kingpin.Flag("height", "image height").Default(strconv.Itoa(0)).Short('h').IntVar(&opts.Height) kingpin.Flag("height", "image height").Default(strconv.Itoa(0)).Short('h').IntVar(&opts.Height)
kingpin.Flag("quality", "JPEG image quality").Short('q').Default(strconv.Itoa(jpeg.DefaultQuality)).IntVar(&opts.Quality) kingpin.Flag("quality", "JPEG image quality").Short('q').Default(strconv.Itoa(jpeg.DefaultQuality)).IntVar(&opts.Quality)
kingpin.Flag("filter", "0=NearestNeighbor, 1=Box, 2=Linear, 3=MitchellNetravali, 4=CatmullRom, 6=Gaussian, 7=Lanczos").Short('f'). kingpin.Flag("filter", "0=NearestNeighbor, 1=Box, 2=Linear, 3=MitchellNetravali, 4=CatmullRom, 6=Gaussian, 7=Lanczos").Short('f').
Default(strconv.Itoa(NearestNeighbor)).IntVar(&opts.Filter) Default(strconv.Itoa(Linear)).IntVar(&opts.Filter)
kingpin.Flag("norgb", "do not convert images that have RGB colorspace").Short('n').BoolVar(&opts.NoRGB) kingpin.Flag("no_rgb", "do not convert images that have RGB colorspace").Short('N').BoolVar(&opts.NoRGB)
kingpin.Flag("no_nonimage", "remove non image files from archive").Short('I').BoolVar(&opts.NoNonImage)
kingpin.Flag("suffix", "add suffix to file basename").Short('s').StringVar(&opts.Suffix) kingpin.Flag("suffix", "add suffix to file basename").Short('s').StringVar(&opts.Suffix)
kingpin.Flag("cover", "extract cover").Short('c').BoolVar(&opts.Cover) kingpin.Flag("cover", "extract cover").Short('c').BoolVar(&opts.Cover)
kingpin.Flag("thumbnail", "extract cover thumbnail (freedesktop spec.)").Short('t').BoolVar(&opts.Thumbnail) kingpin.Flag("thumbnail", "extract cover thumbnail (freedesktop spec.)").Short('t').BoolVar(&opts.Thumbnail)