Group all unplayable torrents in a separate directory
This commit is contained in:
@@ -16,7 +16,7 @@ func (t *TorrentManager) CheckDeletedStatus(torrent *Torrent) bool {
|
||||
torrent.DownloadedIDs.Each(func(id string) bool {
|
||||
infoCache.Set(id, torrent)
|
||||
t.writeTorrentToFile(id, torrent)
|
||||
return true
|
||||
return false
|
||||
})
|
||||
}
|
||||
return false
|
||||
@@ -32,7 +32,7 @@ func (t *TorrentManager) Delete(accessKey string, deleteInRD bool) {
|
||||
t.Api.DeleteTorrent(id)
|
||||
infoCache.Remove(id)
|
||||
t.deleteTorrentFile(id)
|
||||
return true
|
||||
return false
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/debridmediamanager/zurg/internal/config"
|
||||
"github.com/debridmediamanager/zurg/pkg/logutil"
|
||||
"github.com/debridmediamanager/zurg/pkg/realdebrid"
|
||||
"github.com/debridmediamanager/zurg/pkg/utils"
|
||||
mapset "github.com/deckarep/golang-set/v2"
|
||||
cmap "github.com/orcaman/concurrent-map/v2"
|
||||
"github.com/panjf2000/ants/v2"
|
||||
@@ -123,9 +124,13 @@ func (t *TorrentManager) assignedDirectoryCb(tor *Torrent, cb func(string)) {
|
||||
// get filenames needed for directory conditions
|
||||
var filenames []string
|
||||
var fileSizes []int64
|
||||
unplayable := true
|
||||
tor.SelectedFiles.IterCb(func(key string, file *File) {
|
||||
filenames = append(filenames, filepath.Base(file.Path))
|
||||
fileSizes = append(fileSizes, file.Bytes)
|
||||
if unplayable && utils.IsStreamable(file.Path) {
|
||||
unplayable = false
|
||||
}
|
||||
})
|
||||
// Map torrents to directories
|
||||
switch t.Config.GetVersion() {
|
||||
@@ -133,7 +138,10 @@ func (t *TorrentManager) assignedDirectoryCb(tor *Torrent, cb func(string)) {
|
||||
configV1 := t.Config.(*config.ZurgConfigV1)
|
||||
for _, directories := range configV1.GetGroupMap() {
|
||||
for _, directory := range directories {
|
||||
if t.Config.MeetsConditions(directory, tor.AccessKey, tor.ComputeTotalSize(), torrentIDs, filenames, fileSizes) {
|
||||
if unplayable {
|
||||
cb(config.UNPLAYABLE_TORRENTS)
|
||||
break
|
||||
} else if t.Config.MeetsConditions(directory, tor.AccessKey, tor.ComputeTotalSize(), torrentIDs, filenames, fileSizes) {
|
||||
cb(directory)
|
||||
break
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/debridmediamanager/zurg/internal/config"
|
||||
"github.com/debridmediamanager/zurg/pkg/realdebrid"
|
||||
mapset "github.com/deckarep/golang-set/v2"
|
||||
cmap "github.com/orcaman/concurrent-map/v2"
|
||||
@@ -59,7 +60,7 @@ func (t *TorrentManager) RefreshTorrents() []string {
|
||||
// assign to directories
|
||||
tor, ok := allTorrents.Get(accessKey)
|
||||
if !ok {
|
||||
return true
|
||||
return false
|
||||
}
|
||||
var directories []string
|
||||
t.assignedDirectoryCb(tor, func(directory string) {
|
||||
@@ -69,18 +70,19 @@ func (t *TorrentManager) RefreshTorrents() []string {
|
||||
torrents, _ := t.DirectoryMap.Get(directory)
|
||||
torrents.Set(accessKey, tor)
|
||||
updatedPaths = append(updatedPaths, fmt.Sprintf("%s/%s", directory, accessKey))
|
||||
if directory != "__all__" {
|
||||
// this is just for the logs
|
||||
if directory != config.ALL_TORRENTS {
|
||||
directories = append(directories, directory)
|
||||
}
|
||||
})
|
||||
t.log.Debugf("Added %s to %v", accessKey, directories)
|
||||
t.allAccessKeys.Add(accessKey)
|
||||
return true
|
||||
return false
|
||||
})
|
||||
// removed torrents
|
||||
t.allAccessKeys.Difference(freshKeys).Each(func(accessKey string) bool {
|
||||
t.Delete(accessKey, false)
|
||||
return true
|
||||
return false
|
||||
})
|
||||
|
||||
return updatedPaths
|
||||
@@ -212,7 +214,7 @@ func (t *TorrentManager) mergeToMain(existing, toMerge *Torrent) Torrent {
|
||||
toMerge.DownloadedIDs.Difference(existing.DownloadedIDs).Each(func(id string) bool {
|
||||
mainTorrent.DownloadedIDs.Add(id)
|
||||
mainTorrent.InProgressIDs.Remove(id)
|
||||
return true
|
||||
return false
|
||||
})
|
||||
|
||||
// the link can have the following values
|
||||
|
||||
@@ -40,7 +40,7 @@ func (t *TorrentManager) Repair(torrent *Torrent) {
|
||||
torrent.DownloadedIDs.Each(func(id string) bool {
|
||||
infoCache.Set(id, torrent)
|
||||
t.writeTorrentToFile(id, torrent)
|
||||
return true
|
||||
return false
|
||||
})
|
||||
_ = t.repairWorker.Submit(func() {
|
||||
t.log.Infof("Repairing torrent %s", torrent.AccessKey)
|
||||
|
||||
Reference in New Issue
Block a user