pcgamedb/utils/magnet.go
nite07 b7aadf7f88 add cf-clearance-scraper
fix greegogcrawler
fix goggamescrawler
2024-11-20 10:40:33 +08:00

30 lines
574 B
Go

package utils
import (
"bytes"
"github.com/anacrolix/torrent/metainfo"
)
func ConvertTorrentToMagnet(torrent []byte) (string, string, error) {
minfo, err := metainfo.Load(bytes.NewReader(torrent))
if err != nil {
return "", "", err
}
info, err := minfo.UnmarshalInfo()
if err != nil {
return "", "", err
}
var size uint64 = uint64(info.Length)
if size == 0 {
for _, file := range info.Files {
size += uint64(file.Length)
}
}
magnet, err := minfo.MagnetV2()
if err != nil {
return "", "", err
}
return magnet.String(), BytesToSize(size), nil
}