示例#1
0
func ProduceTorrents(file string, c chan *core.Torrent, d chan *core.Torrent) {
	log.Println("Reading database dump from:", file)
	f, err := os.Open(file)
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()
	gr, err := gzip.NewReader(f)
	if err != nil {
		log.Fatal(err)
	}
	defer gr.Close()

	cr := csv.NewReader(gr)
	cr.LazyQuotes = true
	cr.Comma = '|'

	for rec, err := cr.Read(); err != io.EOF; rec, err = cr.Read() {
		if err != nil {
			log.Print(err)
			continue
		}

		name := html.UnescapeString(rec[0])

		size, err := strconv.Atoi(rec[1])
		if err != nil {
			log.Print(err)
		}

		created := time.Now()

		infoHash, err := hex.DecodeString(rec[2])
		if err != nil {
			log.Print(err)
			continue
		}

		files, err := strconv.Atoi(rec[3])
		if err != nil {
			log.Print(err)
		}

		category := rec[4]
		seeders, err := strconv.Atoi(rec[5])
		if err != nil {
			log.Print(err)
		}
		leechers, err := strconv.Atoi(rec[6])
		if err != nil {
			log.Print(err)
		}

		t := core.CreateTorrent(infoHash, name, "from db dump", category, created, nil,
			(uint64)(size), (uint)(files), (uint)(seeders), (uint)(leechers))
		if err != nil {
			log.Print(err)
			continue
		}
		c <- t
		d <- t
	}
	close(c)
	close(d)
}
示例#2
0
func createDefaultTorrent(d string) *core.Torrent {
	return core.CreateTorrent([]byte("magnetlink"), "name", d, "category", time.Now(), nil, 0, 0, 0, 0)
}