32bit compatibility

This commit is contained in:
Ben Sarmiento
2024-01-06 17:30:17 +01:00
parent a3eab1752c
commit d93fd2cdc1
6 changed files with 28 additions and 33 deletions

View File

@@ -9,10 +9,9 @@ import (
"github.com/debridmediamanager/zurg/internal/config"
"github.com/debridmediamanager/zurg/pkg/logutil"
"github.com/debridmediamanager/zurg/pkg/realdebrid"
mapset "github.com/deckarep/golang-set/v2"
cmap "github.com/orcaman/concurrent-map/v2"
"github.com/panjf2000/ants/v2"
"github.com/scylladb/go-set"
"github.com/scylladb/go-set/strset"
)
const (
@@ -25,7 +24,7 @@ type TorrentManager struct {
Api *realdebrid.RealDebrid
DirectoryMap cmap.ConcurrentMap[string, cmap.ConcurrentMap[string, *Torrent]] // directory -> accessKey -> Torrent
DownloadCache cmap.ConcurrentMap[string, *realdebrid.Download]
allAccessKeys *strset.Set
allAccessKeys mapset.Set[string]
latestState *LibraryState
requiredVersion string
workerPool *ants.Pool
@@ -42,7 +41,7 @@ func NewTorrentManager(cfg config.ConfigInterface, api *realdebrid.RealDebrid, p
t := &TorrentManager{
Config: cfg,
Api: api,
allAccessKeys: set.NewStringSet(),
allAccessKeys: mapset.NewSet[string](),
latestState: &initialSate,
requiredVersion: "06.12.2023",
workerPool: p,
@@ -120,7 +119,7 @@ func (t *TorrentManager) TriggerHookOnLibraryUpdate(updatedPaths []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
var filenames []string
var fileSizes []int64
@@ -200,7 +199,7 @@ func (t *TorrentManager) readTorrentFromFile(torrentID string) *Torrent {
if err := json.Unmarshal(jsonData, &torrent); err != 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")
}
if torrent.Version != t.requiredVersion {

View File

@@ -8,9 +8,8 @@ import (
"time"
"github.com/debridmediamanager/zurg/pkg/realdebrid"
mapset "github.com/deckarep/golang-set/v2"
cmap "github.com/orcaman/concurrent-map/v2"
"github.com/scylladb/go-set"
"github.com/scylladb/go-set/strset"
)
func (t *TorrentManager) RefreshTorrents() []string {
@@ -35,7 +34,7 @@ func (t *TorrentManager) RefreshTorrents() []string {
close(infoChan)
t.log.Debugf("Fetched info for %d torrents", len(instances))
freshKeys := set.NewStringSet()
freshKeys := mapset.NewSet[string]()
allTorrents, _ := t.DirectoryMap.Get(INT_ALL)
noInfoCount := 0
for info := range infoChan {
@@ -48,7 +47,7 @@ func (t *TorrentManager) RefreshTorrents() []string {
}
if torrent, exists := allTorrents.Get(info.AccessKey); !exists {
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)
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)
var updatedPaths []string
// 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
tor, ok := allTorrents.Get(accessKey)
if !ok {
@@ -79,8 +78,7 @@ func (t *TorrentManager) RefreshTorrents() []string {
return true
})
// removed torrents
// items which are in in t.allAccessKeys but not in freshKeys
strset.Difference(t.allAccessKeys, freshKeys).Each(func(accessKey string) bool {
t.allAccessKeys.Difference(freshKeys).Each(func(accessKey string) bool {
t.Delete(accessKey, false)
return true
})
@@ -188,8 +186,8 @@ func (t *TorrentManager) getMoreInfo(rdTorrent realdebrid.Torrent) *Torrent {
torrent.SelectedFiles.Set(filepath.Base(file.Path), file)
}
}
torrent.DownloadedIDs = strset.New()
torrent.InProgressIDs = strset.New()
torrent.DownloadedIDs = mapset.NewSet[string]()
torrent.InProgressIDs = mapset.NewSet[string]()
if info.Progress == 100 {
torrent.DownloadedIDs.Add(info.ID)
} else {
@@ -207,11 +205,11 @@ func (t *TorrentManager) mergeToMain(existing, toMerge *Torrent) Torrent {
mainTorrent.AccessKey = existing.AccessKey
mainTorrent.Hash = existing.Hash
mainTorrent.DownloadedIDs = strset.New()
mainTorrent.InProgressIDs = strset.New()
mainTorrent.DownloadedIDs = mapset.NewSet[string]()
mainTorrent.InProgressIDs = mapset.NewSet[string]()
// 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.InProgressIDs.Remove(id)
return true

View File

@@ -117,7 +117,7 @@ func (t *TorrentManager) reinsertTorrent(torrent *Torrent, missingFiles string)
// if missingFiles is not provided
if missingFiles == "" {
// only replace the torrent if we are reinserting all files
oldTorrentIDs = torrent.DownloadedIDs.List()
oldTorrentIDs = torrent.DownloadedIDs.ToSlice()
tmpSelection := ""
torrent.SelectedFiles.IterCb(func(_ string, file *File) {
tmpSelection += fmt.Sprintf("%d,", file.ID) // select all files

View File

@@ -6,9 +6,9 @@ import (
"time"
"github.com/debridmediamanager/zurg/pkg/realdebrid"
mapset "github.com/deckarep/golang-set/v2"
jsoniter "github.com/json-iterator/go"
cmap "github.com/orcaman/concurrent-map/v2"
"github.com/scylladb/go-set/strset"
)
var json = jsoniter.ConfigCompatibleWithStandardLibrary
@@ -20,8 +20,8 @@ type Torrent struct {
LatestAdded string `json:"LatestAdded"`
ForRepair bool `json:"ForRepair"`
Unfixable bool `json:"Unfixable"`
DownloadedIDs *strset.Set `json:"DownloadedIDs"`
InProgressIDs *strset.Set `json:"InProgressIDs"`
DownloadedIDs mapset.Set[string] `json:"DownloadedIDs"`
InProgressIDs mapset.Set[string] `json:"InProgressIDs"`
Version string `json:"Version"` // only used for files
}
@@ -46,14 +46,14 @@ func (t *Torrent) MarshalJSON() ([]byte, error) {
if t.DownloadedIDs.IsEmpty() {
temp.DownloadedIDsJson = []byte(`""`)
} else {
downloadedIDsStr := `"` + strings.Join(t.DownloadedIDs.List(), ",") + `"`
downloadedIDsStr := `"` + strings.Join(t.DownloadedIDs.ToSlice(), ",") + `"`
temp.DownloadedIDsJson = []byte(downloadedIDsStr)
}
if t.InProgressIDs.IsEmpty() {
temp.InProgressIDsJson = []byte(`""`)
} else {
inProgressIDsStr := `"` + strings.Join(t.InProgressIDs.List(), ",") + `"`
inProgressIDsStr := `"` + strings.Join(t.InProgressIDs.ToSlice(), ",") + `"`
temp.InProgressIDsJson = []byte(inProgressIDsStr)
}
@@ -83,16 +83,16 @@ func (t *Torrent) UnmarshalJSON(data []byte) error {
if len(temp.DownloadedIDsJson) > 2 {
downloadedIDs := strings.Split(strings.ReplaceAll(string(temp.DownloadedIDsJson), `"`, ""), ",")
t.DownloadedIDs = strset.New(downloadedIDs...)
t.DownloadedIDs = mapset.NewSet[string](downloadedIDs...)
} else {
t.DownloadedIDs = strset.New()
t.DownloadedIDs = mapset.NewSet[string]()
}
if len(temp.InProgressIDsJson) > 2 {
inProgressIDs := strings.Split(strings.ReplaceAll(string(temp.InProgressIDsJson), `"`, ""), ",")
t.InProgressIDs = strset.New(inProgressIDs...)
t.InProgressIDs = mapset.NewSet[string](inProgressIDs...)
} else {
t.InProgressIDs = strset.New()
t.InProgressIDs = mapset.NewSet[string]()
}
return nil