Esempio n. 1
0
func main() {
	fmt.Println("Hot!")

	if folder == "" {
		folder = "C:\\Users\\David\\HotFolder"
	}

	ctx := context.Background()

	hf := new(fs.HotFolder)
	hf.Path = folder
	hf.PollInterval = time.Second * 5
	hf.MinAge = time.Second * 1
	hf.MonitorErrors = make(chan error)
	hf.ChangeNotifications = make(chan fs.HotfolderChangeNotification)

	hf.Ctx = ctx

	go hf.Monitor()

	log.Println("Listening to notifications from the HotFolder...")

	for {
		select {
		case walkErr := <-hf.MonitorErrors:
			log.Println(walkErr.Error())
			return
		case changes := <-hf.ChangeNotifications:
			log.Printf("Got notification of %d changes.", len(changes))

			for i, f := range changes {
				log.Printf("\t%d %s del: %v", i, f.Path, f.Removed)
			}
		}
	}

}
Esempio n. 2
0
func main() {
	fmt.Println("Hot!")

	if hotfolder == "" {
		hotfolder = "P:\\Dropbox\\SidesPartyPhotos" //"C:\\Users\\David\\HotFolder"
	}

	if workfolder == "" {
		workfolder = "C:\\Users\\David\\WorkFolder"
	}

	if thumbFolder == "" {
		thumbFolder = "C:\\Users\\David\\go\\src\\github.com\\crown-hill\\goutils\\partyboard\\websrc\\slideshow"
	}

	thumbSize = 1600

	ctx := context.Background()

	hf := new(fs.HotFolder)
	hf.Path = hotfolder
	hf.PollInterval = time.Second * 5
	hf.MinAge = time.Second * 1
	hf.MonitorErrors = make(chan error)
	hf.ChangeNotifications = make(chan fs.HotfolderChangeNotification)

	hf.Ctx = ctx

	thumbnailQueue := make(chan *fs.HotFolderChange, 100)

	go func() {

		for {
			select {
			case change := <-thumbnailQueue:

				workPath := change.Path

				if moveFiles {
					workPath := filepath.Join(workfolder, change.FileInfo.Name())
					err := os.Rename(change.Path, workPath)
					if err != nil {
						log.Println("Error moving %s %s", change.Path, err.Error())
						break
					}
				}

				thumbName := change.FileInfo.Name() + "-thumb.jpg"
				thumbPath := filepath.Join(thumbFolder, thumbName)

				sizeArg := fmt.Sprintf("%d,%d", thumbSize, thumbSize)

				_, _, err := runCrValidate("-jpg", thumbPath, "-maxImagesize", sizeArg, workPath)
				if err != nil {
					log.Println("Error thumbnailing %s %s", change.Path, err.Error())
					break
				}

			}
		}

	}()

	go hf.Monitor()

	log.Println("Listening to notifications from the HotFolder...")

	for {
		select {
		case walkErr := <-hf.MonitorErrors:
			log.Println(walkErr.Error())
			return
		case changes := <-hf.ChangeNotifications:
			log.Printf("Got notification of %d changes.", len(changes))

			for _, f := range changes {
				//log.Printf("\t%d %s del: %v", i, f.Path, f.Removed)
				if f.Removed == false {
					thumbnailQueue <- f
				}
			}
		}
	}

}