<commit_before>package main

import (
	"flag"
	"fmt"
	"os"
	"path"
	"runtime"
	"strconv"
	"time"

	_ "image/gif"
	_ "image/jpeg"
	_ "image/png"

	"github.com/aerogo/ipo"
	"github.com/aerogo/ipo/inputs"
	"github.com/aerogo/ipo/outputs"
	"github.com/animenotifier/arn"
	"github.com/fatih/color"
)

var ticker = time.NewTicker(50 * time.Millisecond)

// Shell parameters
var from int
var to int

// Shell flags
func init() {
	flag.IntVar(&from, "from", 0, "From index")
	flag.IntVar(&to, "to", 0, "To index")
	flag.Parse()
}

func main() {
	color.Yellow("Downloading anime images")
	defer arn.Node.Close()

	if from < 0 {
		from = 0
	}

	allAnime := arn.FilterAnime(func(anime *arn.Anime) bool {
		id, _ := strconv.Atoi(anime.ID)
		return id >= from && id <= to
	})

	for index, anime := range allAnime {
		fmt.Printf("%d / %d\n", index+1, len(allAnime))
		work(anime)
	}

	color.Green("Finished downloading anime images.")

	// Give file buffers some time, just to be safe
	time.Sleep(time.Second)
}

func work(anime *arn.Anime) error {
	<-ticker.C

	originals := path.Join(os.Getenv("GOPATH"), "/src/github.com/animenotifier/notify.moe/images/anime/original/")
	large := path.Join(os.Getenv("GOPATH"), "/src/github.com/animenotifier/notify.moe/images/anime/large/")
	medium := path.Join(os.Getenv("GOPATH"), "/src/github.com/animenotifier/notify.moe/images/anime/medium/")
	small := path.Join(os.Getenv("GOPATH"), "/src/github.com/animenotifier/notify.moe/images/anime/small/")

	largeSize := 250
	mediumSize := 150
	smallSize := 55

	webpQuality := 70
	jpegQuality := 70

	qualityBonusLowDPI := 10
	qualityBonusMedium := 10
	qualityBonusSmall := 10

	kitsuOriginal := fmt.Sprintf("https://media.kitsu.io/anime/poster_images/%s/original", anime.ID)

	system := ipo.System{
		Inputs: []ipo.Input{
			&inputs.FileSystemImage{
				URL: path.Join(originals, anime.ID+".png"),
			},
			&inputs.FileSystemImage{
				URL: path.Join(originals, anime.ID+".jpg"),
			},
			&inputs.FileSystemImage{
				URL: path.Join(originals, anime.ID+".jpeg"),
			},
			&inputs.FileSystemImage{
				URL: path.Join(originals, anime.ID+".gif"),
			},
			&inputs.NetworkImage{
				URL: kitsuOriginal + anime.ImageExtension,
			},
			&inputs.NetworkImage{
				URL: kitsuOriginal + ".png",
			},
			&inputs.NetworkImage{
				URL: kitsuOriginal + ".jpg",
			},
			&inputs.NetworkImage{
				URL: kitsuOriginal + ".jpeg",
			},
		},
		Outputs: []ipo.Output{
			// Original
			&outputs.ImageFile{
				Directory: originals,
				BaseName:  anime.ID,
			},

			// Large
			&outputs.ImageFile{
				Directory: large,
				BaseName:  anime.ID,
				Size:      largeSize,
				Quality:   jpegQuality + qualityBonusLowDPI,
			},
			&outputs.ImageFile{
				Directory: large,
				BaseName:  anime.ID + "@2",
				Size:      largeSize * 2,
				Quality:   jpegQuality,
			},
			&outputs.ImageFile{
				Directory: large,
				BaseName:  anime.ID,
				Size:      largeSize,
				Format:    "webp",
				Quality:   webpQuality + qualityBonusLowDPI,
			},
			&outputs.ImageFile{
				Directory: large,
				BaseName:  anime.ID + "@2",
				Size:      largeSize * 2,
				Format:    "webp",
				Quality:   webpQuality,
			},

			// Medium
			&outputs.ImageFile{
				Directory: medium,
				BaseName:  anime.ID,
				Size:      mediumSize,
				Quality:   jpegQuality + qualityBonusLowDPI + qualityBonusMedium,
			},
			&outputs.ImageFile{
				Directory: medium,
				BaseName:  anime.ID + "@2",
				Size:      mediumSize * 2,
				Quality:   jpegQuality,
			},
			&outputs.ImageFile{
				Directory: medium,
				BaseName:  anime.ID,
				Size:      mediumSize,
				Format:    "webp",
				Quality:   webpQuality + qualityBonusLowDPI + qualityBonusMedium,
			},
			&outputs.ImageFile{
				Directory: medium,
				BaseName:  anime.ID + "@2",
				Size:      mediumSize * 2,
				Format:    "webp",
				Quality:   webpQuality,
			},

			// Small
			&outputs.ImageFile{
				Directory: small,
				BaseName:  anime.ID,
				Size:      smallSize,
				Quality:   jpegQuality + qualityBonusLowDPI + qualityBonusSmall,
			},
			&outputs.ImageFile{
				Directory: small,
				BaseName:  anime.ID + "@2",
				Size:      smallSize * 2,
				Quality:   jpegQuality,
			},
			&outputs.ImageFile{
				Directory: small,
				BaseName:  anime.ID,
				Size:      smallSize,
				Format:    "webp",
				Quality:   webpQuality + qualityBonusLowDPI + qualityBonusSmall,
			},
			&outputs.ImageFile{
				Directory: small,
				BaseName:  anime.ID + "@2",
				Size:      smallSize * 2,
				Format:    "webp",
				Quality:   webpQuality,
			},
		},
		InputProcessor:  ipo.SequentialInputs,
		OutputProcessor: ipo.ParallelOutputs,
	}

	err := system.Run()

	if err != nil {
		fmt.Println(err)
	}

	// Try to free up some memory
	system.Inputs = nil
	system.Outputs = nil
	runtime.GC()

	return nil
}
<commit_msg>Slightly bigger images for 1.0 ratio<commit_after>package main

import (
	"flag"
	"fmt"
	"os"
	"path"
	"runtime"
	"strconv"
	"time"

	_ "image/gif"
	_ "image/jpeg"
	_ "image/png"

	"github.com/aerogo/ipo"
	"github.com/aerogo/ipo/inputs"
	"github.com/aerogo/ipo/outputs"
	"github.com/animenotifier/arn"
	"github.com/fatih/color"
)

var ticker = time.NewTicker(50 * time.Millisecond)

// Shell parameters
var from int
var to int

// Shell flags
func init() {
	flag.IntVar(&from, "from", 0, "From index")
	flag.IntVar(&to, "to", 0, "To index")
	flag.Parse()
}

func main() {
	color.Yellow("Downloading anime images")
	defer arn.Node.Close()

	if from < 0 {
		from = 0
	}

	allAnime := arn.FilterAnime(func(anime *arn.Anime) bool {
		id, _ := strconv.Atoi(anime.ID)
		return id >= from && id <= to
	})

	for index, anime := range allAnime {
		fmt.Printf("%d / %d\n", index+1, len(allAnime))
		work(anime)
	}

	color.Green("Finished downloading anime images.")

	// Give file buffers some time, just to be safe
	time.Sleep(time.Second)
}

func work(anime *arn.Anime) error {
	<-ticker.C

	originals := path.Join(os.Getenv("GOPATH"), "/src/github.com/animenotifier/notify.moe/images/anime/original/")
	large := path.Join(os.Getenv("GOPATH"), "/src/github.com/animenotifier/notify.moe/images/anime/large/")
	medium := path.Join(os.Getenv("GOPATH"), "/src/github.com/animenotifier/notify.moe/images/anime/medium/")
	small := path.Join(os.Getenv("GOPATH"), "/src/github.com/animenotifier/notify.moe/images/anime/small/")

	largeSize := 250
	mediumSize := 142
	smallSize := 55

	mediumSizeBonusLowDPI := 8
	smallSizeBonusLowDPI := 5

	webpQuality := 70
	jpegQuality := 70

	qualityBonusLowDPI := 10
	qualityBonusMedium := 10
	qualityBonusSmall := 10

	kitsuOriginal := fmt.Sprintf("https://media.kitsu.io/anime/poster_images/%s/original", anime.ID)

	system := ipo.System{
		Inputs: []ipo.Input{
			&inputs.FileSystemImage{
				URL: path.Join(originals, anime.ID+".png"),
			},
			&inputs.FileSystemImage{
				URL: path.Join(originals, anime.ID+".jpg"),
			},
			&inputs.FileSystemImage{
				URL: path.Join(originals, anime.ID+".jpeg"),
			},
			&inputs.FileSystemImage{
				URL: path.Join(originals, anime.ID+".gif"),
			},
			&inputs.NetworkImage{
				URL: kitsuOriginal + anime.ImageExtension,
			},
			&inputs.NetworkImage{
				URL: kitsuOriginal + ".png",
			},
			&inputs.NetworkImage{
				URL: kitsuOriginal + ".jpg",
			},
			&inputs.NetworkImage{
				URL: kitsuOriginal + ".jpeg",
			},
		},
		Outputs: []ipo.Output{
			// Original
			&outputs.ImageFile{
				Directory: originals,
				BaseName:  anime.ID,
			},

			// Large
			&outputs.ImageFile{
				Directory: large,
				BaseName:  anime.ID,
				Size:      largeSize,
				Quality:   jpegQuality + qualityBonusLowDPI,
			},
			&outputs.ImageFile{
				Directory: large,
				BaseName:  anime.ID + "@2",
				Size:      largeSize * 2,
				Quality:   jpegQuality,
			},
			&outputs.ImageFile{
				Directory: large,
				BaseName:  anime.ID,
				Size:      largeSize,
				Format:    "webp",
				Quality:   webpQuality + qualityBonusLowDPI,
			},
			&outputs.ImageFile{
				Directory: large,
				BaseName:  anime.ID + "@2",
				Size:      largeSize * 2,
				Format:    "webp",
				Quality:   webpQuality,
			},

			// Medium
			&outputs.ImageFile{
				Directory: medium,
				BaseName:  anime.ID,
				Size:      mediumSize + mediumSizeBonusLowDPI,
				Quality:   jpegQuality + qualityBonusLowDPI + qualityBonusMedium,
			},
			&outputs.ImageFile{
				Directory: medium,
				BaseName:  anime.ID + "@2",
				Size:      mediumSize * 2,
				Quality:   jpegQuality,
			},
			&outputs.ImageFile{
				Directory: medium,
				BaseName:  anime.ID,
				Size:      mediumSize + mediumSizeBonusLowDPI,
				Format:    "webp",
				Quality:   webpQuality + qualityBonusLowDPI + qualityBonusMedium,
			},
			&outputs.ImageFile{
				Directory: medium,
				BaseName:  anime.ID + "@2",
				Size:      mediumSize * 2,
				Format:    "webp",
				Quality:   webpQuality,
			},

			// Small
			&outputs.ImageFile{
				Directory: small,
				BaseName:  anime.ID,
				Size:      smallSize + smallSizeBonusLowDPI,
				Quality:   jpegQuality + qualityBonusLowDPI + qualityBonusSmall,
			},
			&outputs.ImageFile{
				Directory: small,
				BaseName:  anime.ID + "@2",
				Size:      smallSize * 2,
				Quality:   jpegQuality,
			},
			&outputs.ImageFile{
				Directory: small,
				BaseName:  anime.ID,
				Size:      smallSize + smallSizeBonusLowDPI,
				Format:    "webp",
				Quality:   webpQuality + qualityBonusLowDPI + qualityBonusSmall,
			},
			&outputs.ImageFile{
				Directory: small,
				BaseName:  anime.ID + "@2",
				Size:      smallSize * 2,
				Format:    "webp",
				Quality:   webpQuality,
			},
		},
		InputProcessor:  ipo.SequentialInputs,
		OutputProcessor: ipo.ParallelOutputs,
	}

	err := system.Run()

	if err != nil {
		fmt.Println(err)
	}

	// Try to free up some memory
	system.Inputs = nil
	system.Outputs = nil
	runtime.GC()

	return nil
}

{'fraction_non_alphanumeric': 0.14539695514457954, 'fraction_numerical': 0.007969755798508225, 'mean_word_length': 2.921474358974359, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3083158', 'n_tokens_mistral': 4354, 'n_tokens_neox': 3594, 'n_words': 693}