From a9505ea07af1710b12eec4f04f9c417e03b93073 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Thu, 9 Nov 2017 13:28:06 +0100 Subject: [PATCH] Simpler image download --- images/anime/.gitignore | 1 + images/anime/large/.gitignore | 2 ++ images/anime/medium/.gitignore | 2 ++ images/anime/original/.gitignore | 2 ++ images/anime/small/.gitignore | 2 ++ jobs/anime-images/anime-images.go | 25 ++++++++++++++----------- 6 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 images/anime/large/.gitignore create mode 100644 images/anime/medium/.gitignore create mode 100644 images/anime/original/.gitignore create mode 100644 images/anime/small/.gitignore diff --git a/images/anime/.gitignore b/images/anime/.gitignore index c96a04f0..b6e069c5 100644 --- a/images/anime/.gitignore +++ b/images/anime/.gitignore @@ -1,2 +1,3 @@ * +!*/ !.gitignore \ No newline at end of file diff --git a/images/anime/large/.gitignore b/images/anime/large/.gitignore new file mode 100644 index 00000000..c96a04f0 --- /dev/null +++ b/images/anime/large/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/images/anime/medium/.gitignore b/images/anime/medium/.gitignore new file mode 100644 index 00000000..c96a04f0 --- /dev/null +++ b/images/anime/medium/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/images/anime/original/.gitignore b/images/anime/original/.gitignore new file mode 100644 index 00000000..c96a04f0 --- /dev/null +++ b/images/anime/original/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/images/anime/small/.gitignore b/images/anime/small/.gitignore new file mode 100644 index 00000000..c96a04f0 --- /dev/null +++ b/images/anime/small/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/jobs/anime-images/anime-images.go b/jobs/anime-images/anime-images.go index 36788632..e53ab939 100644 --- a/jobs/anime-images/anime-images.go +++ b/jobs/anime-images/anime-images.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "path" + "runtime" "strings" "time" @@ -11,7 +12,6 @@ import ( _ "image/jpeg" _ "image/png" - "github.com/aerogo/flow/jobqueue" "github.com/aerogo/ipo" "github.com/aerogo/ipo/inputs" "github.com/aerogo/ipo/outputs" @@ -19,28 +19,26 @@ import ( "github.com/fatih/color" ) -var ticker = time.NewTicker(50 * time.Millisecond) +var ticker = time.NewTicker(100 * time.Millisecond) func main() { color.Yellow("Downloading anime images") defer arn.Node.Close() - jobs := jobqueue.New(work) + allAnime := arn.AllAnime() - for anime := range arn.StreamAnime() { - jobs.Queue(anime) + for index, anime := range allAnime { + fmt.Printf("%d / %d\n", index, len(allAnime)) + work(anime) } - results := jobs.Wait() - color.Green("Finished downloading %d anime images.", len(results)) + color.Green("Finished downloading anime images.") // Give file buffers some time, just to be safe time.Sleep(time.Second) } -func work(job interface{}) interface{} { - anime := job.(*arn.Anime) - +func work(anime *arn.Anime) error { if !strings.HasPrefix(anime.Image.Original, "//media.kitsu.io/anime/") { return nil } @@ -59,7 +57,7 @@ func work(job interface{}) interface{} { webpQuality := 80 jpegQuality := 80 - system := &ipo.System{ + system := ipo.System{ Inputs: []ipo.Input{ &inputs.NetworkImage{ URL: anime.Image.Original, @@ -166,5 +164,10 @@ func work(job interface{}) interface{} { fmt.Println(err) } + // Try to free up some memory + system.Inputs = nil + system.Outputs = nil + runtime.GC() + return nil }