MSE support

This commit is contained in:
liwei committed 2019-05-31 18:29:04 +08:00
1 parent 03fbdcda60
commit dbc58a209d
11 files changed
+309 -343

No files matched your search

+25 -25
View File
@@ -11,24 +11,18 @@ type MetaInfo struct {
// tracker URL
// http://bittorrent.org/beps/bep_0003.html#metainfo-files
Announce string `json:"announce"`
// tracker URL
// http://bittorrent.org/beps/bep_0012.html
AnnounceList [][]string `json:"announce-list"`
Comment string `json:"comment"`
CreatedBy string `json:"created by"`
CreationDate int64 `json:"creation date"`
Encoding string `json:"encoding"`
Comment string `json:"comment"`
CreatedBy string `json:"created by"`
CreationDate int64 `json:"creation date"`
Encoding string `json:"encoding"`
// http://bittorrent.org/beps/bep_0019.html
UrlList []string `json:"url-list"`
Info *Info `json:"info"`
Info *Info `json:"info"`
InfoHash [20]byte `json:"-"`
ExtraInfo `json:"-"`
}
type Info struct {
@@ -44,19 +38,9 @@ type File struct {
Path string `json:"path"`
}
func (metaInfo *MetaInfo) GetTotalSize() uint64 {
if metaInfo.Info != nil {
if len(metaInfo.Info.Files) > 0 {
var length uint64
for _, f := range metaInfo.Info.Files {
length += f.Length
}
return length
} else {
return metaInfo.Info.Length
}
}
return 0
type ExtraInfo struct {
InfoHash [20]byte
FileSize uint64
}
func ParseFromFile(path string) (*MetaInfo, error) {
@@ -91,5 +75,21 @@ func ParseFromFile(path string) (*MetaInfo, error) {
}
}
}
metaInfo.FileSize = getTotalSize(&metaInfo)
return &metaInfo, nil
}
func getTotalSize(metaInfo *MetaInfo) uint64 {
if metaInfo.Info != nil {
if len(metaInfo.Info.Files) > 0 {
var length uint64
for _, f := range metaInfo.Info.Files {
length += f.Length
}
return length
} else {
return metaInfo.Info.Length
}
}
return 0
}