2022-03-20 00:11:19 +03:00
|
|
|
package gorrent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/anacrolix/torrent/metainfo"
|
|
|
|
)
|
|
|
|
|
|
|
|
type FileInfo struct {
|
|
|
|
Length int64
|
|
|
|
Path []string
|
|
|
|
PathUTF8 []string
|
|
|
|
}
|
|
|
|
|
|
|
|
type Info struct {
|
|
|
|
Name string
|
|
|
|
Length int64
|
|
|
|
Source string
|
|
|
|
Files []*FileInfo
|
|
|
|
//
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *Info) LoadFile(path string) error {
|
|
|
|
meta, err := metainfo.LoadFromFile(path)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
i, err := meta.UnmarshalInfo()
|
|
|
|
o.Name = i.Name
|
|
|
|
o.Length = i.Length
|
|
|
|
o.Source = i.Source
|
|
|
|
for _, fi := range i.Files {
|
|
|
|
o.Files = append(o.Files, &FileInfo{
|
|
|
|
Length: fi.Length,
|
|
|
|
Path: fi.Path,
|
2022-05-15 18:00:42 +03:00
|
|
|
PathUTF8: fi.PathUtf8,
|
2022-03-20 00:11:19 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|