Group all unplayable torrents in a separate directory
This commit is contained in:
@@ -13,7 +13,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ALL_TORRENTS = "__all__"
|
ALL_TORRENTS = "__all__"
|
||||||
|
UNPLAYABLE_TORRENTS = "__unplayable__"
|
||||||
)
|
)
|
||||||
|
|
||||||
func loadV1Config(content []byte, log *logutil.Logger) (*ZurgConfigV1, error) {
|
func loadV1Config(content []byte, log *logutil.Logger) (*ZurgConfigV1, error) {
|
||||||
@@ -30,13 +31,14 @@ func (z *ZurgConfigV1) GetVersion() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (z *ZurgConfigV1) GetDirectories() []string {
|
func (z *ZurgConfigV1) GetDirectories() []string {
|
||||||
rootDirectories := make([]string, len(z.Directories)+1)
|
rootDirectories := make([]string, len(z.Directories)+2)
|
||||||
i := 0
|
i := 0
|
||||||
for directory := range z.Directories {
|
for directory := range z.Directories {
|
||||||
rootDirectories[i] = directory
|
rootDirectories[i] = directory
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
rootDirectories[i] = ALL_TORRENTS
|
rootDirectories[i] = ALL_TORRENTS
|
||||||
|
rootDirectories[i+1] = UNPLAYABLE_TORRENTS
|
||||||
return rootDirectories
|
return rootDirectories
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,6 +76,7 @@ func (z *ZurgConfigV1) GetGroupMap() map[string][]string {
|
|||||||
temp := make([]string, len(v))
|
temp := make([]string, len(v))
|
||||||
copy(temp, v)
|
copy(temp, v)
|
||||||
result[k] = temp
|
result[k] = temp
|
||||||
|
// result[k] = append(result[k], UNPLAYABLE_TORRENTS)
|
||||||
}
|
}
|
||||||
result[ALL_TORRENTS] = []string{ALL_TORRENTS} // Add special group for all torrents
|
result[ALL_TORRENTS] = []string{ALL_TORRENTS} // Add special group for all torrents
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ func (t *TorrentManager) CheckDeletedStatus(torrent *Torrent) bool {
|
|||||||
torrent.DownloadedIDs.Each(func(id string) bool {
|
torrent.DownloadedIDs.Each(func(id string) bool {
|
||||||
infoCache.Set(id, torrent)
|
infoCache.Set(id, torrent)
|
||||||
t.writeTorrentToFile(id, torrent)
|
t.writeTorrentToFile(id, torrent)
|
||||||
return true
|
return false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
@@ -32,7 +32,7 @@ func (t *TorrentManager) Delete(accessKey string, deleteInRD bool) {
|
|||||||
t.Api.DeleteTorrent(id)
|
t.Api.DeleteTorrent(id)
|
||||||
infoCache.Remove(id)
|
infoCache.Remove(id)
|
||||||
t.deleteTorrentFile(id)
|
t.deleteTorrentFile(id)
|
||||||
return true
|
return false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ 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"
|
||||||
|
"github.com/debridmediamanager/zurg/pkg/utils"
|
||||||
mapset "github.com/deckarep/golang-set/v2"
|
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"
|
||||||
@@ -123,9 +124,13 @@ func (t *TorrentManager) assignedDirectoryCb(tor *Torrent, cb func(string)) {
|
|||||||
// get filenames needed for directory conditions
|
// get filenames needed for directory conditions
|
||||||
var filenames []string
|
var filenames []string
|
||||||
var fileSizes []int64
|
var fileSizes []int64
|
||||||
|
unplayable := true
|
||||||
tor.SelectedFiles.IterCb(func(key string, file *File) {
|
tor.SelectedFiles.IterCb(func(key string, file *File) {
|
||||||
filenames = append(filenames, filepath.Base(file.Path))
|
filenames = append(filenames, filepath.Base(file.Path))
|
||||||
fileSizes = append(fileSizes, file.Bytes)
|
fileSizes = append(fileSizes, file.Bytes)
|
||||||
|
if unplayable && utils.IsStreamable(file.Path) {
|
||||||
|
unplayable = false
|
||||||
|
}
|
||||||
})
|
})
|
||||||
// Map torrents to directories
|
// Map torrents to directories
|
||||||
switch t.Config.GetVersion() {
|
switch t.Config.GetVersion() {
|
||||||
@@ -133,7 +138,10 @@ func (t *TorrentManager) assignedDirectoryCb(tor *Torrent, cb func(string)) {
|
|||||||
configV1 := t.Config.(*config.ZurgConfigV1)
|
configV1 := t.Config.(*config.ZurgConfigV1)
|
||||||
for _, directories := range configV1.GetGroupMap() {
|
for _, directories := range configV1.GetGroupMap() {
|
||||||
for _, directory := range directories {
|
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)
|
cb(directory)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/debridmediamanager/zurg/internal/config"
|
||||||
"github.com/debridmediamanager/zurg/pkg/realdebrid"
|
"github.com/debridmediamanager/zurg/pkg/realdebrid"
|
||||||
mapset "github.com/deckarep/golang-set/v2"
|
mapset "github.com/deckarep/golang-set/v2"
|
||||||
cmap "github.com/orcaman/concurrent-map/v2"
|
cmap "github.com/orcaman/concurrent-map/v2"
|
||||||
@@ -59,7 +60,7 @@ func (t *TorrentManager) RefreshTorrents() []string {
|
|||||||
// assign to directories
|
// assign to directories
|
||||||
tor, ok := allTorrents.Get(accessKey)
|
tor, ok := allTorrents.Get(accessKey)
|
||||||
if !ok {
|
if !ok {
|
||||||
return true
|
return false
|
||||||
}
|
}
|
||||||
var directories []string
|
var directories []string
|
||||||
t.assignedDirectoryCb(tor, func(directory string) {
|
t.assignedDirectoryCb(tor, func(directory string) {
|
||||||
@@ -69,18 +70,19 @@ func (t *TorrentManager) RefreshTorrents() []string {
|
|||||||
torrents, _ := t.DirectoryMap.Get(directory)
|
torrents, _ := t.DirectoryMap.Get(directory)
|
||||||
torrents.Set(accessKey, tor)
|
torrents.Set(accessKey, tor)
|
||||||
updatedPaths = append(updatedPaths, fmt.Sprintf("%s/%s", directory, accessKey))
|
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)
|
directories = append(directories, directory)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
t.log.Debugf("Added %s to %v", accessKey, directories)
|
t.log.Debugf("Added %s to %v", accessKey, directories)
|
||||||
t.allAccessKeys.Add(accessKey)
|
t.allAccessKeys.Add(accessKey)
|
||||||
return true
|
return false
|
||||||
})
|
})
|
||||||
// removed torrents
|
// removed torrents
|
||||||
t.allAccessKeys.Difference(freshKeys).Each(func(accessKey string) bool {
|
t.allAccessKeys.Difference(freshKeys).Each(func(accessKey string) bool {
|
||||||
t.Delete(accessKey, false)
|
t.Delete(accessKey, false)
|
||||||
return true
|
return false
|
||||||
})
|
})
|
||||||
|
|
||||||
return updatedPaths
|
return updatedPaths
|
||||||
@@ -212,7 +214,7 @@ func (t *TorrentManager) mergeToMain(existing, toMerge *Torrent) Torrent {
|
|||||||
toMerge.DownloadedIDs.Difference(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 false
|
||||||
})
|
})
|
||||||
|
|
||||||
// the link can have the following values
|
// the link can have the following values
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ func (t *TorrentManager) Repair(torrent *Torrent) {
|
|||||||
torrent.DownloadedIDs.Each(func(id string) bool {
|
torrent.DownloadedIDs.Each(func(id string) bool {
|
||||||
infoCache.Set(id, torrent)
|
infoCache.Set(id, torrent)
|
||||||
t.writeTorrentToFile(id, torrent)
|
t.writeTorrentToFile(id, torrent)
|
||||||
return true
|
return false
|
||||||
})
|
})
|
||||||
_ = t.repairWorker.Submit(func() {
|
_ = t.repairWorker.Submit(func() {
|
||||||
t.log.Infof("Repairing torrent %s", torrent.AccessKey)
|
t.log.Infof("Repairing torrent %s", torrent.AccessKey)
|
||||||
|
|||||||
Reference in New Issue
Block a user