<commit_before>package main

import (
	"flag"
	"fmt"
	"image"
	"image/jpeg"
	"log"
	"net/http"
	"os"
	"os/user"
	"regexp"
	"sync"

	"github.com/PuerkitoBio/goquery"
)

var (
	dir      string
	threadId = regexp.MustCompile(`thread-(\d*)-`)
	imageId  = regexp.MustCompile(`img/(.*)`)
)

func worker(linkChan chan string, wg *sync.WaitGroup) {
	defer wg.Done()

	for url := range linkChan {
		resp, _ := http.Get(url)
		defer resp.Body.Close()

		m, _, err := image.Decode(resp.Body)
		if err != nil {
			log.Fatal(err)
			continue
		}

		// Ignore small images
		bounds := m.Bounds()
		if bounds.Size().X > 400 && bounds.Size().Y > 400 {
			out, _ := os.Create(dir + "/" + imageId.FindStringSubmatch(url)[1])
			defer out.Close()
			jpeg.Encode(out, m, nil)<commit_msg>Support png.<commit_after>package main

import (
	"flag"
	"fmt"
	"image"
	"image/jpeg"
	"image/png"
	"net/http"
	"os"
	"os/user"
	"regexp"
	"sync"

	"github.com/PuerkitoBio/goquery"
	"github.com/coreos/go-log/log"
)

var (
	dir      string
	threadId = regexp.MustCompile(`thread-(\d*)-`)
	imageId  = regexp.MustCompile(`img/(.*)\.(jpg|png)`)
)

func worker(linkChan chan string, wg *sync.WaitGroup) {
	defer wg.Done()

	for url := range linkChan {
		resp, err := http.Get(url)
		if err != nil {
			log.Println(err)
			continue
		}
		defer resp.Body.Close()

		m, _, err := image.Decode(resp.Body)
		if err != nil {
			log.Println(err)
			continue
		}

		// Ignore small images
		bounds := m.Bounds()
		if bounds.Size().X > 400 && bounds.Size().Y > 400 {
			imgInfo := imageId.FindStringSubmatch(url)
			out, _ := os.Create(dir + "/" + imgInfo[1] + "." + imgInfo[2])
			defer out.Close()
			switch imgInfo[2] {
			case "jpg":
				jpeg.Encode(out, m, nil)
			case "png":
				png.Encode(out, m)
			}
{'fraction_non_alphanumeric': 0.18264322178105502, 'fraction_numerical': 0.009075439591605219, 'mean_word_length': 3.0551724137931036, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1944410', 'n_tokens_mistral': 810, 'n_tokens_neox': 710, 'n_words': 144}