32bit compatibility
This commit is contained in:
2
go.mod
2
go.mod
@@ -10,10 +10,10 @@ require (
|
|||||||
require github.com/orcaman/concurrent-map/v2 v2.0.1
|
require github.com/orcaman/concurrent-map/v2 v2.0.1
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/deckarep/golang-set/v2 v2.6.0
|
||||||
github.com/json-iterator/go v1.1.12
|
github.com/json-iterator/go v1.1.12
|
||||||
github.com/julienschmidt/httprouter v1.3.0
|
github.com/julienschmidt/httprouter v1.3.0
|
||||||
github.com/panjf2000/ants/v2 v2.8.2
|
github.com/panjf2000/ants/v2 v2.8.2
|
||||||
github.com/scylladb/go-set v1.0.2
|
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
|||||||
6
go.sum
6
go.sum
@@ -2,8 +2,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
|
|||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/fatih/set v0.2.1 h1:nn2CaJyknWE/6txyUDGwysr3G5QC6xWB/PtVjPBbeaA=
|
github.com/deckarep/golang-set/v2 v2.6.0 h1:XfcQbWM1LlMB8BsJ8N9vW5ehnnPVIw0je80NsVHagjM=
|
||||||
github.com/fatih/set v0.2.1/go.mod h1:+RKtMCH+favT2+3YecHGxcc0b4KyVWA1QWWJUs4E0CI=
|
github.com/deckarep/golang-set/v2 v2.6.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4=
|
||||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||||
@@ -22,8 +22,6 @@ github.com/panjf2000/ants/v2 v2.8.2/go.mod h1:7ZxyxsqE4vvW0M7LSD8aI3cKwgFhBHbxnl
|
|||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
github.com/scylladb/go-set v1.0.2 h1:SkvlMCKhP0wyyct6j+0IHJkBkSZL+TDzZ4E7f7BCcRE=
|
|
||||||
github.com/scylladb/go-set v1.0.2/go.mod h1:DkpGd78rljTxKAnTDPFqXSGxvETQnJyuSOQwsHycqfs=
|
|
||||||
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
|
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
|
||||||
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
|
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
|
||||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||||
|
|||||||
@@ -9,10 +9,9 @@ import (
|
|||||||
"github.com/debridmediamanager/zurg/internal/config"
|
"github.com/debridmediamanager/zurg/internal/config"
|
||||||
"github.com/debridmediamanager/zurg/pkg/logutil"
|
"github.com/debridmediamanager/zurg/pkg/logutil"
|
||||||
"github.com/debridmediamanager/zurg/pkg/realdebrid"
|
"github.com/debridmediamanager/zurg/pkg/realdebrid"
|
||||||
|
mapset "github.com/deckarep/golang-set/v2"
|
||||||
cmap "github.com/orcaman/concurrent-map/v2"
|
cmap "github.com/orcaman/concurrent-map/v2"
|
||||||
"github.com/panjf2000/ants/v2"
|
"github.com/panjf2000/ants/v2"
|
||||||
"github.com/scylladb/go-set"
|
|
||||||
"github.com/scylladb/go-set/strset"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -25,7 +24,7 @@ type TorrentManager struct {
|
|||||||
Api *realdebrid.RealDebrid
|
Api *realdebrid.RealDebrid
|
||||||
DirectoryMap cmap.ConcurrentMap[string, cmap.ConcurrentMap[string, *Torrent]] // directory -> accessKey -> Torrent
|
DirectoryMap cmap.ConcurrentMap[string, cmap.ConcurrentMap[string, *Torrent]] // directory -> accessKey -> Torrent
|
||||||
DownloadCache cmap.ConcurrentMap[string, *realdebrid.Download]
|
DownloadCache cmap.ConcurrentMap[string, *realdebrid.Download]
|
||||||
allAccessKeys *strset.Set
|
allAccessKeys mapset.Set[string]
|
||||||
latestState *LibraryState
|
latestState *LibraryState
|
||||||
requiredVersion string
|
requiredVersion string
|
||||||
workerPool *ants.Pool
|
workerPool *ants.Pool
|
||||||
@@ -42,7 +41,7 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, p
|
|||||||
t := &TorrentManager{
|
t := &TorrentManager{
|
||||||
Config: cfg,
|
Config: cfg,
|
||||||
Api: api,
|
Api: api,
|
||||||
allAccessKeys: set.NewStringSet(),
|
allAccessKeys: mapset.NewSet[string](),
|
||||||
latestState: &initialSate,
|
latestState: &initialSate,
|
||||||
requiredVersion: "06.12.2023",
|
requiredVersion: "06.12.2023",
|
||||||
workerPool: p,
|
workerPool: p,
|
||||||
@@ -120,7 +119,7 @@ func (t *TorrentManager) TriggerHookOnLibraryUpdate(updatedPaths []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *TorrentManager) assignedDirectoryCb(tor *Torrent, cb func(string)) {
|
func (t *TorrentManager) assignedDirectoryCb(tor *Torrent, cb func(string)) {
|
||||||
torrentIDs := strset.Union(tor.DownloadedIDs, tor.InProgressIDs).List()
|
torrentIDs := tor.DownloadedIDs.Union(tor.InProgressIDs).ToSlice()
|
||||||
// get filenames needed for directory conditions
|
// get filenames needed for directory conditions
|
||||||
var filenames []string
|
var filenames []string
|
||||||
var fileSizes []int64
|
var fileSizes []int64
|
||||||
@@ -200,7 +199,7 @@ func (t *TorrentManager) readTorrentFromFile(torrentID string) *Torrent {
|
|||||||
if err := json.Unmarshal(jsonData, &torrent); err != nil {
|
if err := json.Unmarshal(jsonData, &torrent); err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if strset.Union(torrent.DownloadedIDs, torrent.InProgressIDs).IsEmpty() {
|
if torrent.DownloadedIDs.Union(torrent.InProgressIDs).IsEmpty() {
|
||||||
t.log.Fatal("Torrent has no downloaded or in progress ids")
|
t.log.Fatal("Torrent has no downloaded or in progress ids")
|
||||||
}
|
}
|
||||||
if torrent.Version != t.requiredVersion {
|
if torrent.Version != t.requiredVersion {
|
||||||
|
|||||||
@@ -8,9 +8,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/debridmediamanager/zurg/pkg/realdebrid"
|
"github.com/debridmediamanager/zurg/pkg/realdebrid"
|
||||||
|
mapset "github.com/deckarep/golang-set/v2"
|
||||||
cmap "github.com/orcaman/concurrent-map/v2"
|
cmap "github.com/orcaman/concurrent-map/v2"
|
||||||
"github.com/scylladb/go-set"
|
|
||||||
"github.com/scylladb/go-set/strset"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (t *TorrentManager) RefreshTorrents() []string {
|
func (t *TorrentManager) RefreshTorrents() []string {
|
||||||
@@ -35,7 +34,7 @@ func (t *TorrentManager) RefreshTorrents() []string {
|
|||||||
close(infoChan)
|
close(infoChan)
|
||||||
t.log.Debugf("Fetched info for %d torrents", len(instances))
|
t.log.Debugf("Fetched info for %d torrents", len(instances))
|
||||||
|
|
||||||
freshKeys := set.NewStringSet()
|
freshKeys := mapset.NewSet[string]()
|
||||||
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
|
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
|
||||||
noInfoCount := 0
|
noInfoCount := 0
|
||||||
for info := range infoChan {
|
for info := range infoChan {
|
||||||
@@ -48,7 +47,7 @@ func (t *TorrentManager) RefreshTorrents() []string {
|
|||||||
}
|
}
|
||||||
if torrent, exists := allTorrents.Get(info.AccessKey); !exists {
|
if torrent, exists := allTorrents.Get(info.AccessKey); !exists {
|
||||||
allTorrents.Set(info.AccessKey, info)
|
allTorrents.Set(info.AccessKey, info)
|
||||||
} else if !strset.Difference(info.DownloadedIDs, torrent.DownloadedIDs).IsEmpty() {
|
} else if !info.DownloadedIDs.Difference(torrent.DownloadedIDs).IsEmpty() {
|
||||||
mainTorrent := t.mergeToMain(torrent, info)
|
mainTorrent := t.mergeToMain(torrent, info)
|
||||||
allTorrents.Set(info.AccessKey, &mainTorrent)
|
allTorrents.Set(info.AccessKey, &mainTorrent)
|
||||||
}
|
}
|
||||||
@@ -56,7 +55,7 @@ func (t *TorrentManager) RefreshTorrents() []string {
|
|||||||
t.log.Infof("Compiled into %d torrents, %d were missing info", allTorrents.Count(), noInfoCount)
|
t.log.Infof("Compiled into %d torrents, %d were missing info", allTorrents.Count(), noInfoCount)
|
||||||
var updatedPaths []string
|
var updatedPaths []string
|
||||||
// torrents yet to be assigned in a directory
|
// torrents yet to be assigned in a directory
|
||||||
strset.Difference(freshKeys, t.allAccessKeys).Each(func(accessKey string) bool {
|
freshKeys.Difference(t.allAccessKeys).Each(func(accessKey string) bool {
|
||||||
// assign to directories
|
// assign to directories
|
||||||
tor, ok := allTorrents.Get(accessKey)
|
tor, ok := allTorrents.Get(accessKey)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -79,8 +78,7 @@ func (t *TorrentManager) RefreshTorrents() []string {
|
|||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
// removed torrents
|
// removed torrents
|
||||||
// items which are in in t.allAccessKeys but not in freshKeys
|
t.allAccessKeys.Difference(freshKeys).Each(func(accessKey string) bool {
|
||||||
strset.Difference(t.allAccessKeys, freshKeys).Each(func(accessKey string) bool {
|
|
||||||
t.Delete(accessKey, false)
|
t.Delete(accessKey, false)
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
@@ -188,8 +186,8 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
|
|||||||
torrent.SelectedFiles.Set(filepath.Base(file.Path), file)
|
torrent.SelectedFiles.Set(filepath.Base(file.Path), file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
torrent.DownloadedIDs = strset.New()
|
torrent.DownloadedIDs = mapset.NewSet[string]()
|
||||||
torrent.InProgressIDs = strset.New()
|
torrent.InProgressIDs = mapset.NewSet[string]()
|
||||||
if info.Progress == 100 {
|
if info.Progress == 100 {
|
||||||
torrent.DownloadedIDs.Add(info.ID)
|
torrent.DownloadedIDs.Add(info.ID)
|
||||||
} else {
|
} else {
|
||||||
@@ -207,11 +205,11 @@ func (t *TorrentManager) mergeToMain(existing, toMerge *Torrent) Torrent {
|
|||||||
|
|
||||||
mainTorrent.AccessKey = existing.AccessKey
|
mainTorrent.AccessKey = existing.AccessKey
|
||||||
mainTorrent.Hash = existing.Hash
|
mainTorrent.Hash = existing.Hash
|
||||||
mainTorrent.DownloadedIDs = strset.New()
|
mainTorrent.DownloadedIDs = mapset.NewSet[string]()
|
||||||
mainTorrent.InProgressIDs = strset.New()
|
mainTorrent.InProgressIDs = mapset.NewSet[string]()
|
||||||
|
|
||||||
// this function triggers only when we have a new DownloadedID
|
// this function triggers only when we have a new DownloadedID
|
||||||
strset.Difference(toMerge.DownloadedIDs, existing.DownloadedIDs).Each(func(id string) bool {
|
toMerge.DownloadedIDs.Difference(existing.DownloadedIDs).Each(func(id string) bool {
|
||||||
mainTorrent.DownloadedIDs.Add(id)
|
mainTorrent.DownloadedIDs.Add(id)
|
||||||
mainTorrent.InProgressIDs.Remove(id)
|
mainTorrent.InProgressIDs.Remove(id)
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ func (t *TorrentManager) reinsertTorrent(torrent *Torrent, missingFiles string)
|
|||||||
// if missingFiles is not provided
|
// if missingFiles is not provided
|
||||||
if missingFiles == "" {
|
if missingFiles == "" {
|
||||||
// only replace the torrent if we are reinserting all files
|
// only replace the torrent if we are reinserting all files
|
||||||
oldTorrentIDs = torrent.DownloadedIDs.List()
|
oldTorrentIDs = torrent.DownloadedIDs.ToSlice()
|
||||||
tmpSelection := ""
|
tmpSelection := ""
|
||||||
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
|
||||||
tmpSelection += fmt.Sprintf("%d,", file.ID) // select all files
|
tmpSelection += fmt.Sprintf("%d,", file.ID) // select all files
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/debridmediamanager/zurg/pkg/realdebrid"
|
"github.com/debridmediamanager/zurg/pkg/realdebrid"
|
||||||
|
mapset "github.com/deckarep/golang-set/v2"
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
cmap "github.com/orcaman/concurrent-map/v2"
|
cmap "github.com/orcaman/concurrent-map/v2"
|
||||||
"github.com/scylladb/go-set/strset"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||||
@@ -20,8 +20,8 @@ type Torrent struct {
|
|||||||
LatestAdded string `json:"LatestAdded"`
|
LatestAdded string `json:"LatestAdded"`
|
||||||
ForRepair bool `json:"ForRepair"`
|
ForRepair bool `json:"ForRepair"`
|
||||||
Unfixable bool `json:"Unfixable"`
|
Unfixable bool `json:"Unfixable"`
|
||||||
DownloadedIDs *strset.Set `json:"DownloadedIDs"`
|
DownloadedIDs mapset.Set[string] `json:"DownloadedIDs"`
|
||||||
InProgressIDs *strset.Set `json:"InProgressIDs"`
|
InProgressIDs mapset.Set[string] `json:"InProgressIDs"`
|
||||||
|
|
||||||
Version string `json:"Version"` // only used for files
|
Version string `json:"Version"` // only used for files
|
||||||
}
|
}
|
||||||
@@ -46,14 +46,14 @@ func (t *Torrent) MarshalJSON() ([]byte, error) {
|
|||||||
if t.DownloadedIDs.IsEmpty() {
|
if t.DownloadedIDs.IsEmpty() {
|
||||||
temp.DownloadedIDsJson = []byte(`""`)
|
temp.DownloadedIDsJson = []byte(`""`)
|
||||||
} else {
|
} else {
|
||||||
downloadedIDsStr := `"` + strings.Join(t.DownloadedIDs.List(), ",") + `"`
|
downloadedIDsStr := `"` + strings.Join(t.DownloadedIDs.ToSlice(), ",") + `"`
|
||||||
temp.DownloadedIDsJson = []byte(downloadedIDsStr)
|
temp.DownloadedIDsJson = []byte(downloadedIDsStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if t.InProgressIDs.IsEmpty() {
|
if t.InProgressIDs.IsEmpty() {
|
||||||
temp.InProgressIDsJson = []byte(`""`)
|
temp.InProgressIDsJson = []byte(`""`)
|
||||||
} else {
|
} else {
|
||||||
inProgressIDsStr := `"` + strings.Join(t.InProgressIDs.List(), ",") + `"`
|
inProgressIDsStr := `"` + strings.Join(t.InProgressIDs.ToSlice(), ",") + `"`
|
||||||
temp.InProgressIDsJson = []byte(inProgressIDsStr)
|
temp.InProgressIDsJson = []byte(inProgressIDsStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,16 +83,16 @@ func (t *Torrent) UnmarshalJSON(data []byte) error {
|
|||||||
|
|
||||||
if len(temp.DownloadedIDsJson) > 2 {
|
if len(temp.DownloadedIDsJson) > 2 {
|
||||||
downloadedIDs := strings.Split(strings.ReplaceAll(string(temp.DownloadedIDsJson), `"`, ""), ",")
|
downloadedIDs := strings.Split(strings.ReplaceAll(string(temp.DownloadedIDsJson), `"`, ""), ",")
|
||||||
t.DownloadedIDs = strset.New(downloadedIDs...)
|
t.DownloadedIDs = mapset.NewSet[string](downloadedIDs...)
|
||||||
} else {
|
} else {
|
||||||
t.DownloadedIDs = strset.New()
|
t.DownloadedIDs = mapset.NewSet[string]()
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(temp.InProgressIDsJson) > 2 {
|
if len(temp.InProgressIDsJson) > 2 {
|
||||||
inProgressIDs := strings.Split(strings.ReplaceAll(string(temp.InProgressIDsJson), `"`, ""), ",")
|
inProgressIDs := strings.Split(strings.ReplaceAll(string(temp.InProgressIDsJson), `"`, ""), ",")
|
||||||
t.InProgressIDs = strset.New(inProgressIDs...)
|
t.InProgressIDs = mapset.NewSet[string](inProgressIDs...)
|
||||||
} else {
|
} else {
|
||||||
t.InProgressIDs = strset.New()
|
t.InProgressIDs = mapset.NewSet[string]()
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user