@@ 44,9 44,52 @@ fmt.Printf("Launching video sorter...\n")
for object := range client.ListObjects(Config.S3.Bucket, Config.S3.Prefix, false, doneCh) {
- if strings.HasSuffix(object.Key, ".mp4") || strings.HasSuffix(object.Key, ".gif") {
+ if strings.HasSuffix(object.Key, ".mp4") {
begin:
- exec.Command("vlc", "https://"+Config.S3.Endpoint+"/"+Config.S3.Bucket+"/"+object.Key, "--play-and-exit").Output()
+ cmd := fmt.Sprintf(Config.Sorter.Video, "https://"+Config.S3.Endpoint+"/"+Config.S3.Bucket+"/"+object.Key)
+ cmd_split := strings.Split(cmd, " ")
+ exec.Command(cmd_split[0], cmd_split[1:]...).Output()
+ reader := bufio.NewReader(os.Stdin)
+ fmt.Print("[k]eep, [T]rash, [r]eplay?: ")
+ text, _ := reader.ReadString('\n')
+ if text[0] == '\n' || text[0] == 'T' || text[0] == 't' {
+ client.RemoveObject(Config.S3.Bucket, object.Key)
+ } else if text[0] == 'k' || text[0] == 'K' {
+ id := strings.ReplaceAll(object.Key, Config.S3.Prefix, "")
+ src := minio.NewSourceInfo(Config.S3.Bucket, Config.S3.Prefix+id, nil)
+ dst, err := minio.NewDestinationInfo(Config.S3.Bucket, Config.S3.GoodPrefix+id, nil, nil)
+ err = client.CopyObject(dst, src)
+ if err == nil {
+ _, err = exec.Command(Config.Scripts.Directory+"/set-object-acl-public-read.sh",
+ Config.S3.Bucket, Config.S3.GoodPrefix+id,
+ "https://"+Config.S3.Endpoint, Config.S3.Id,
+ Config.S3.Secret, Config.S3.Region).Output()
+
+ if err != nil {
+ fmt.Printf("Error set-object-acl: %s\n", err.Error())
+ return
+ }
+
+ client.RemoveObject(Config.S3.Bucket, Config.S3.Prefix+id)
+ }
+ } else if text[0] == 'r' || text[0] == 'R' {
+ goto begin
+ }
+ }
+ }
+ }
+
+ func sortGif(client *minio.Client) {
+ doneCh := make(chan struct{})
+ defer close(doneCh)
+
+ fmt.Printf("Launching gif sorter...\n")
+ for object := range client.ListObjects(Config.S3.Bucket, Config.S3.Prefix, false, doneCh) {
+ if strings.HasSuffix(object.Key, ".gif") {
+ begin:
+ cmd := fmt.Sprintf(Config.Sorter.Gif, "https://"+Config.S3.Endpoint+"/"+Config.S3.Bucket+"/"+object.Key)
+ cmd_split := strings.Split(cmd, " ")
+ exec.Command(cmd_split[0], cmd_split[1:]...).Output()
reader := bufio.NewReader(os.Stdin)
fmt.Print("[k]eep, [T]rash, [r]eplay?: ")
text, _ := reader.ReadString('\n')
@@ 97,7 140,8 @@ func main() {
filename := flag.String("config", "/etc/kart-worker.conf", "The yaml configuration file")
check := flag.Bool("check", false, "Check images in the bucket")
- video := flag.Bool("video", false, "Check images in the bucket")
+ video := flag.Bool("video", false, "Launch video sorter")
+ gif := flag.Bool("gif", false, "Launch gif sorter")
keep := flag.String("keep", "id", "The image to keep")
throw := flag.String("throw", "id", "The image to throw")
@@ 120,8 164,14 @@ return
}
+ if *gif {
+ sortGif(client)
+ return
+ }
+
if *keep == "id" && *throw == "id" {
launchSorter(client, *filename)
+ sortGif(client)
sortVideo(client)
}