Beispiel #1
0
var Source string
var Destination string

// importCmd represents the import command
var importCmd = &cobra.Command{
	Use:   "import",
	Short: "Import photos from SOURCE to DESTINATION",
	Long: `Photos will be moved to a path based on date taken,
	eg: 2015/05/13/GFY_[hash].jpg

	Photos not moved are **potential** duplicates.`,
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Println("Sorting photos in " + Source)
		fmt.Println("Moving photos to " + Destination)

		files := scanner.ScanDir(Source)
		for _, f := range files {
			os.MkdirAll(f.SortedPath(Destination), 0777)
			_, err := os.Stat(f.SortedFullPath(Destination))
			if os.IsNotExist(err) {
				fmt.Printf("Moving %s >> %s\n", f.Path, f.SortedFullPath(Destination))
				os.Rename(f.Path, f.SortedFullPath(Destination))
			} else if err == nil {
				fmt.Printf("Duplicate %s >> %s\n", f.Path, f.SortedFullPath(Destination))
			} else {
				fmt.Printf("Error[%s] %s >> %s\n", err, f.Path, f.SortedFullPath(Destination))
			}
		}
	},
}
Beispiel #2
-1
type SimplePhoto struct {
	Path      string
	ThumbPath string
	Date      time.Time
	Hash      string
}

var Path string

// indexCmd represents the index command
var indexCmd = &cobra.Command{
	Use:   "index",
	Short: "Generate an index of your picture data",
	Long:  `Scans all your pics, saves the date, hash, and file path into an index`,
	Run: func(cmd *cobra.Command, args []string) {
		files := scanner.ScanDir(Path)
		db := scanner.OpenDb(Path)
		photos := []*SimplePhoto{}
		defer db.Close()
		for _, f := range files {
			fmt.Printf("%s\t%s\t%s\n", f.Date, f.Hash(), f.Path)
			f.Thumbnail(Path)
			// db.Add(f.Path, f.Date, f.Hash())
			simple := &SimplePhoto{
				Path:      f.Path,
				ThumbPath: f.Thumbnail(Path),
				Date:      f.Datetime(),
				Hash:      f.Hash(),
			}
			photos = append(photos, simple)
		}